【问题标题】:C# Chart change colour when a series point goes over a certain value当系列点超过某个值时,C#图表改变颜色
【发布时间】:2014-12-23 10:31:44
【问题描述】:

我目前正在使用 VS C#,并且我的表单上有一个图表。

图表工作正常,但如果系列中的任何值达到 255(图表顶部),我想更改图表的颜色(颜色)

目前我尝试了这个:

 GRAPH_READY = false;
 c.ChartAreas[0].AxisY.Maximum = 255;
 c.ChartAreas[0].AxisX.Maximum = 256;
 c.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
 c.Series[s].Points.DataBindY(vals.ToArray());
 c.Series[s].ChartType = SeriesChartType.Line;
 c.Series[s].BorderWidth = 3;
 c.Series[s].BorderColor = Color.Red;

 for (int i = 0; i < c.Series[s].Points.Count; i++)
 {
      //here I'm wanting to check if any of the Y values of the points are over 255 
      if (c.Series[s].YValuesPerPoint == 255) c.Series[s].Color = Color.Red;
      else if (c.Series[s].YValuesPerPoint < 254) c.Series[s].Color = Color.Blue;
 }
 GRAPH_READY = true;

我尝试了上述方法,但它似乎不起作用 :( 图表在 255 值以下开始时变为蓝色,但当我让它变为 255 时,它保持蓝色。

提前致谢,

J.

【问题讨论】:

    标签: c# colors charts linechart series


    【解决方案1】:

    由于我不确定您要绑定哪些值,因此最好捕获以上所有值(包括您的最大值)。

    我建议将您的第一个 IF 语句更改为:

    if (c.Series[s].YValuesPerPoint >= 255) c.Series[s].Color = Color.Red;
    

    【讨论】:

    • 啊啊啊好喊@setherith,我还注意到我在任何时候都没有使用我的计数...重启日按钮在哪里。
    • 不用担心 - 很高兴我能帮上忙 :)
    猜你喜欢
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多