visual studio – Inserting TextAnnotation in graph c#


IMAGE

I creating simple graph with line as average (sample only), I have a code in HorizontalLineAnnotation (color red line) and TextAnnotation but the problem is that, the TextAnnotation not working properly.

Here my code in HorizontalLineAnnotation and TextAnnotation .

private void annptaion()
{
//insert line
HorizontalLineAnnotation hl = new HorizontalLineAnnotation();
                    hl.AllowMoving = false;
                    hl.IsInfinitive = true;
                    //hl.LineColor = System.Drawing.Color.Red;
                    hl.AnchorY = Convert.ToDouble(2);//row line
                    hl.AxisX = chart1.ChartAreas[0].AxisX;
                    hl.AxisY = chart1.ChartAreas[0].AxisY;
                    hl.ClipToChartArea = chart1.ChartAreas[0].Name; hl.LineColor = Color.Red; hl.LineWidth = 1;//make line
                    hl.IsSizeAlwaysRelative = false;
                    chart1.Annotations.Add(hl);

//insert text
TextAnnotation ta = new TextAnnotation();
                    
                    ta.AxisX = chart1.ChartAreas[0].AxisX;
                    ta.AxisY = chart1.ChartAreas[0].AxisY;
                    ta.IsSizeAlwaysRelative = false;
                    ta.AnchorAlignment = ContentAlignment.BottomLeft;
                    ta.Text = "average (sample)";
                    ta.ClipToChartArea = chart1.ChartAreas[0].Name; ta.ForeColor = Color.Red;
                    chart1.Annotations.Add(ta);
}

I use the code above for displaying text in the line, but it’s not working properly. I want to display the text either inside of the graph or outside of the graph.

Leave a Reply

Your email address will not be published. Required fields are marked *