如何根据条件更改绘图的颜色
问题描述:
我使用以下代码绘制消息数量,周期时间和总响应时间之间的图表
Hi,
I am using the following code to plot a graph between number of messages,cycle time and total response time
private void AddPlottingData(List<GatewayMessageDetails> GWmsgDetailsList)
{
foreach (GatewayMessageDetails GWmsgDetails in GWmsgDetailsList)
{
// Updating plot data (ResponseTime,Latency and cycle time for each invocation)
int MsgNo = (GWmsgDetailsList.IndexOf(GWmsgDetails) + 1);
//if (GWmsgDetails.Latency == 0)
//{
pltOutput.Series["SeriesCycleTime"].Points.AddXY(MsgNo, GWmsgDetails.TotalDeadLineTimeOfBuses);
pltOutput.Series["SeriesResponseTime"].Points.AddXY(MsgNo, GWmsgDetails.TotalResponseTime);
pltOutput.Series["SeriesLatency"].Points.AddXY(MsgNo, GWmsgDetails.Latency);
// Set Plot Type for each series
pltOutput.Series[Constants.SERIES_CYCLETIME].ChartType = SeriesChartType.Point;
pltOutput.Series[Constants.SERIES_LATENCY].ChartType = SeriesChartType.Point;
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].ChartType = SeriesChartType.Point;
pltOutput.Series[Constants.SERIES_CYCLETIME].MarkerStyle = MarkerStyle.Diamond;
// Set Plot Style,Colour and Size
pltOutput.Series[Constants.SERIES_CYCLETIME].Color = Color.Magenta;
if (GWmsgDetails.Latency == 0)
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color = Color.LawnGreen;
if (GWmsgDetails.Latency != 0)
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color = Color.Red;
pltOutput.Series[Constants.SERIES_LATENCY].MarkerStyle = MarkerStyle.Cross;
pltOutput.Series[Constants.SERIES_LATENCY].Color = Color.Black;
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].MarkerStyle = MarkerStyle.Star6;
pltOutput.Series[Constants.SERIES_CYCLETIME].MarkerSize = 4;
pltOutput.Series[Constants.SERIES_LATENCY].MarkerSize = 8;
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].MarkerSize = 7;
}
}
在上面的代码中,我使用条件根据数据更改绘图的颜色
In the above code I am using a condition to change the color of the plot based on the data
if (GWmsgDetails.Latency == 0)
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color = Color.LawnGreen;
if (GWmsgDetails.Latency != 0)
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color = Color.Red;
但它不起作用。任何人都可以帮我解决这个问题???
谢谢
John
But it is not working. Can anyone please help me in solving this???
Thanks
John
答
如果语句,写一个这是一种奇怪的方式。 这是一个更简洁明了的表格:
That's an odd way to write anif
statement. Here's a more concise and clear form:
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color =
GWmsgDetails.Latency == 0 ? Color.LawnGreen : Color.Red;
/ ravi