0

I'm using ASP.NET Chart Controls for displaying some data. I'm not pulling any data from the database through a dataset. I'm adding them manually. I don't know how to add AxisLabels to X-axis or Y-axis. I've tried using Axis.title, customlabels.Add() etc.. but I couldn't display anything.

And I've this stacked column chart which has columns added through a for loop. How to add different AxisLabels to it?

for (int i= 0; i< 10; i++)

{

     Chart1.Series["1"].Points.AddY(5);

     Chart1.Series["2"].Points.AddY(8);

}

How do I add AxisLabels to these 10 columns ?

Thanks, Manish

antyrat
  • 27,479
  • 9
  • 75
  • 76
Manish
  • 31
  • 2
  • 3
  • 7

2 Answers2

1
Chart1.Series(1).Points(i).AxisLabel = val;

This itself is the answer for the question. I was writing AxisX.Enabled = false; that's why I wasn't able to display axis labels for AxisX.

Manish
  • 31
  • 2
  • 3
  • 7
0

I'd have to know the schema for the chart to know exactly how to iterate through it and assign values. But an example syntax could be doing something like:

for (int i = 0; i < Chart1.Series(1).Points.Count; i++)
{
    string val = "5";

    Chart1.Series(1).Points(i).AxisLabel = val;
}

then you could do the same thing for the other:

for (int i = 0; i < Chart1.Series(1).Points.Count; i++)
{
    string val = "8";

    Chart1.Series(2).Points(i).AxisLabel = val;
}
Precious Roy
  • 1,086
  • 1
  • 9
  • 19
  • can you post the markup for the control? and any relevant code for loading it? that would probably increase your chances of getting an answer from me, or someone else on here. – Precious Roy Jul 07 '11 at 17:14
  • Ok. I'm using a stacked column chart. Since I don't have any dataset to bind, I'm manually inserting values for the chart. Now, in the PageLoad, here is my code... Chart1.ChartAreas["ChartArea1"].AxisX.Enabled = AxisEnabled.False; for (int pointIndex = 0; pointIndex < 13; pointIndex++) { x = Math.Round((double)random.Next(25, 95), 0); y = Math.Round((double)random.Next(5, 75), 0); Chart1.Series["Planned CAB"].Points.AddY(x); Chart1.Series["Planned CAB"].Points[pointIndex].Label = Convert.ToString(x); //Similarly for y } Whr 2 add labels? } – Manish Jul 07 '11 at 17:46
  • Hey I got how to do it.. thanks !! I was doing AxisX.Enabled = false; That's the problem ! – Manish Jul 08 '11 at 17:49
  • Awesome, you should post an answer up in case anybody else runs into this problem, or at least explain what the deal was. Could be helpful, and they might give you credit for the answer. – Precious Roy Jul 11 '11 at 17:03