1 /// <summary>
2 /// 计算数据点并添加
3 /// </summary>
4 /// <param name="list"></param>
5 private void DrawPoint(List<double> list)
6 {
7 double[] left = { 85, 130, 175, 220, 265, 310, 355, 400, 445, 490, 535, 580 };
8 List<double> leftlist = new List<double>();
9 leftlist.AddRange(left);
10
11 for (int i = 1; i < 13; i++)
12 {
13 Ellipse Ellipse = new Ellipse();
14 Ellipse .Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0xff));
15 Ellipse .Width = 8;
16 Ellipse .Height = 8;
17 Canvas.SetLeft(Ellipse,leftlist[i-1]- 4);
18 double y_Max = Math.Ceiling(list.Max() / 100) * 100;
19 Canvas.SetTop(Ellipse, 320 - 250 * (list[i-1] / y_Max) - 4);
20 coordinatePoints.Add(new Point(leftlist[i-1], 320 - 250 * (list[i-1] / y_Max)));
21 this.chartCanvas.Children.Add(Ellipse);
22 //值显示
23 TextBlock EP_Label = new TextBlock();
24 EP_Label.Foreground = System.Windows.Media.Brushes.Red;
25 EP_Label.Text = list[i-1].ToString();
26 Canvas.SetLeft(EP_Label, leftlist[i-1] - 10);
27 Canvas.SetTop(EP_Label, 320 - 250 * (list[i-1] / y_Max) - 20);
28 this.chartCanvas.Children.Add(EP_Label);
29 }
30 }
在绘制数据点的时候,每一次的位置都保存了: coordinatePoints.Add(new Point(leftlist[i-1], 320 - 250 * (list[i-1] / y_Max)));
/// <summary>
/// 折线图坐标点
/// </summary>
private PointCollection coordinatePoints = new PointCollection();
1 /// <summary>
2 /// 绘制连接折线