How do I change a chart caption?

Asked

Viewed 727 times

9

I’m developing a c# application using the Windows Form chart. I would like to know how to put the values of the x-axis as the legend of it.

inserir a descrição da imagem aqui

string[] nomes = { "eduardo", "jorge", "chris", "matheus" };
int[] idades = { 23, 10, 70, 80 };

List<int> numeros = new List<int>();
numeros.Add(23);
numeros.Add(10);
numeros.Add(70);
numeros.Add(100);
int maior = numeros.Max();
int menor = numeros.Min();
chart1.Titles.Add("Idades");

for (int i = 0; i < nomes.Length; i++)
{

    //chart1.Series["Idades"]["PointWidth"] = "0.6";

    //chart1.Series.Add(nomes[i]);

    chart1.Legends.Add(new Legend(nomes[i]));

    chart1.Series["Idades"].Points.AddXY(nomes[i], idades[i]);

    if(numeros.ElementAt(i)==maior){

       chart1.Series["Idades"].Points[i].Color = Color.Red;

    }else if (numeros.ElementAt(i) == menor) {

       chart1.Series["Idades"].Points[i].Color = Color.Yellow;
    }
    else
    {
       chart1.Series["Idades"].Points[i].Color = Color.Blue;
     }
}
  • 3

    Put your code in too, so it’s better for the community to help you.

  • Yes, probably what you have to do is use Legends.add for each X-axis vector value.

  • I tried this: chart1.Series["Ages"]. Legendtext = "#VALX", but it didn’t work

1 answer

0

This way you can rename the Chart legend.

this.ChartLinhas.Series[0].Name = tiposLinhas.ToString();
            this.ChartLinhas.Legends[0].Name = tiposLinhas.ToString();
            this.ChartLinhas.Series[0].Legend = tiposLinhas.ToString();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.