特定像素点处的c#mschart注释

时间:2015-03-17 10:08:12

标签: c# annotations mschart

我正在创建一个简单的图表,在右上角,我想添加一些文字。但是,看一下注释,似乎我可以使用图表的x和y值,而不是我想要的png上的像素点的x和y值。

这是图表的代码:

System.Windows.Forms.DataVisualization.Charting.Chart tempChart = new Chart();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();

chartArea1.Name = "ChartArea1";
tempChart.ChartAreas.Add(chartArea1);

series1.ChartArea = "ChartArea1";
series1.Name = "Series1";

tempChart.Series.Add(series1);
tempChart.Size = new System.Drawing.Size(450, 300);
tempChart.Visible = false;
tempChart.FormatNumber += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.FormatNumberEventArgs>(this.ChartFormatAxis);
var nlvSource = NLVBaseHist.OrderByDescending(orderBy => orderBy.ReportDate).Take(90);
tempChart.DataSource = nlvSource.OrderBy(order => order.ReportDate);
tempChart.BackColor = System.Drawing.ColorTranslator.FromHtml("#efeff2");
tempChart.ChartAreas[0].BackColor = System.Drawing.ColorTranslator.FromHtml("#efeff2");
tempChart.ChartAreas[0].AxisY.LabelStyle.Format = "MyAxisYCustomFormat";
tempChart.ChartAreas[0].AxisX.LabelStyle.Format = "MM-yyyy";
tempChart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
tempChart.ChartAreas[0].AxisX.Interval = 1;
tempChart.ChartAreas[0].AxisY.Tag = "nlvy";
tempChart.Series[0].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.UInt32;
tempChart.Series[0].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
tempChart.Series[0].IsXValueIndexed = true;
tempChart.Series[0].YValueMembers = "TotalInBaseCur";
tempChart.Series[0].BorderWidth = 2;
tempChart.Series[0].Color = System.Drawing.ColorTranslator.FromHtml("#abd7a8");
tempChart.Series[0].BorderColor = System.Drawing.ColorTranslator.FromHtml("#14ba06");
tempChart.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
tempChart.DataBind();

然后我用它来添加文本注释:

TextAnnotation text = new TextAnnotation();
text.Text = "65.88%";
text.X = 90;
text.Y = 20;
text.BringToFront();
tempChart.Annotations.Add(text);

如何添加文本注释并将其放置在图表上的位置,如点(x,y)? 亲切的问候,

Matthijs

0 个答案:

没有答案