下图为某个点的值大于25即标记为白色。
代码:
// 设置曲线的样式
Series series = chart1.Series[1];
// 画样条曲线(Spline) 散点图Point
series.ChartType = SeriesChartType.Spline;
// 线宽2个像素
series.BorderWidth = 2;
// 线的颜色:红色
series.Color = System.Drawing.Color.Red;
// 图示上的文字
series.LegendText = "曲线1";
//标记点颜色
//series.MarkerColor = Color.Red;
//标记点大小
series.MarkerSize = 10;
//标记点样式
series.MarkerStyle = MarkerStyle.Star6;
//随机数
Random ra = new Random();
// 准备数据
float[] values = {ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30), ra.Next(1, 30)
};
// 在chart中显示数据
int x = -2;
foreach (float v in values)
{
//添加数据点
series.Points.AddXY(x, v);
//大于阈值的点进行标记
if (v>25)
series.Points[x+2].MarkerColor = Color.White;//修改该节点的颜色 数据点的集合从0开始
x++;
}
// 设置显示范围
ChartArea chartArea = chart1.ChartAreas[0];
chartArea.AxisX.Minimum = -2;
chartArea.AxisX.Maximum = 6;
chartArea.AxisY.Minimum = -30d;
chartArea.AxisY.Maximum = 35d;
chartArea.AxisY2.Minimum = 0;
chartArea.AxisY2.Maximum = 6000;
PS:
chart1.Series[0].Points[3].MarkerBorderColor = Color.Red; //标记点边框颜色
chart1.Series[0].Points[3].MarkerBorderWidth = 3; //标记点边框大小
chart1.Series[0].Points[3].MarkerColor = Color.Red; //标记点中心颜色
chart1.Series[0].Points[3].MarkerSize = 5; //标记点大小
chart1.Series[0].Points[3].MarkerStyle = MarkerStyle.Circle; //标记点类型