Free_think Free_think - 3 months ago 15
C# Question

How to change text of legend in chart column c#?

i have a problem with chart column in c# , when i want to change text legend to take the x value , it show me this (#VALX) in the place of legend.

and this is my code in

formLoad()


{
chart1.DataSource = Remplir("SELECT count(*) AS Expr1, Candidat.Sourcing FROM Sourcing INNER JOIN Candidat ON Sourcing.Sourcing=Candidat.Sourcing GROUP BY Candidat.Sourcing");
chart1.Series[0].XValueMember = "Sourcing";
chart1.Series[0].YValueMembers = "Expr1";
chart1.Series[0].IsVisibleInLegend = true;
}

TaW TaW
Answer

You have not given your series a Name and your query doesn't supply one either. So you simply should insert this:

chart1.Series[0].Name = "Your Series Title"; 

Obviously you can only display one piece of text in a Legend, not all X-Values!

If you want to keep the name and set the Legend text independently, use the ``Series.LegendText` property:

chart1.Series[0].LegendText = "Your Series Legend Text"; 
Comments