怎样为微软winform中的chart控件添加Annotations注解,我的代码错在哪
一个图形上可以拥有多个注解对象,可以添加十多种图形样式的注解对象,包括常见的箭头、云朵、矩行、图片等等注解符号,通过各个注解对象的属性,可以方便的设置注解对象的放置位置、呈现的颜色、大小、文字内容样式等常见的属性。
我的代码:
chart1.Series.ElementAt(0).LegendText = "日期数量";
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MM-dd HH" + "时";
chart1.Series[0].XValueType = ChartValueType.DateTime;
chart1.Series.ElementAt(0).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
foreach (var item in Data)
{
DataPoint dp = new DataPoint();
dp.SetValueXY(item.Key, item.Value);
chart1.Series.ElementAt(0).Points.Add(dp);
}
LineAnnotation a = new LineAnnotation();
a.Name = "lineAnnotation";
a.ToolTip = "放批注";
a.X = 1;
a.Y = 1;
a.Visible = true;
chart1.Annotations.Add(a);
//放批注
chart1.Annotations[0].AnchorDataPoint = chart1.Series[0].Points[1];