如何根据条件更改绘图的颜色 [英] How can I change color of plots based on condition

查看:83
本文介绍了如何根据条件更改绘图的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用以下代码绘制消息数量,周期时间和总响应时间之间的图表



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 an if statement.  Here's a more concise and clear form:
pltOutput.Series[Constants.SERIES_RESPONSE_TIME].Color =
  GWmsgDetails.Latency == 0 ? Color.LawnGreen : Color.Red;

/ ravi


这篇关于如何根据条件更改绘图的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆