Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSChart custom xaxis labeling

Tags:

label

mschart

I have a MSChart that looks like the following.

http://11.a.hostable.me/images/june2007.JPG

What I would like to do is adjust the x axis labels:

  • I want to label every column, not every 5
  • I want to specify what each label is.

What I don't understand, is when I have it on the "all years" view (as seen below), the number I assign as the XValue using

oDataPoint_PV.SetValueXY(Year, Views)

makes it so the year I specify shows as the label, but for some reason when on the Months view, it starts at 1 instead of the first value I set, which happens to be 13 for this example.

oDataPoint_PV.SetValueXY(Day, Views)

In the chart for June 2007, it should start at 13, and go to july 12th.

http://11.a.hostable.me/images/years.JPG

like image 212
Jason Stauffer Avatar asked Dec 02 '22 01:12

Jason Stauffer


1 Answers

To answer your first question: "I want to label every column, not every 5" You can specify how frequently the label is displayed using the interval property.

chart1.ChartAreas[0].AxisX.Interval = [desired interval];

or to set the interval just for the labels use:

chart1.ChartAreas[0].AxisX.LabelStyle.Interval = [desired interval];

If I follow the end of your question correctly where you don't want your chart to start at zero, you can use a label offset.

chart1.ChartAreas[0].AxisX.LabelStyle.Offset = 1;

This will skip the first label which you mention is zero.

The second objective "I want to specify what each label is" can be solved in several ways

One method is to display the (x or y) value on the (x or y) axis, which I believe is the method you are using based on information you provide in your question

Another way is to set the axis label manually for each data point

chart1.Series[0].Points[0].AxisLabel = "your label"

You can also add the label info when you are adding data points

chart1.Series[0].Points.Add(new DataPoint(4, 4) { AxisLabel = "your label" });

Lastly, you can micromanage your labels using custom labels, but that can be more complicated, and based on what you have typed you probably don't need to use those so I won't go into them.

Also, are you setting your xvalue using a string or a DateTime object?
Something like this:

Chart1.Series[0].XValueType = ChartValueType.DateTime;
System.DateTime x = new System.DateTime(2008, 11, 21);
Chart1.Series[0].Points.AddXY(x.ToOADate(), 34);

If so, when working with date time labels, Microsoft chart objects have additional features you can set to manipulate how it displays. Here is some additional information you might find helpful.

http://msdn.microsoft.com/en-us/library/dd456614.aspx

You can then utilize properties such as these (and I am sure more, but I don't often work with dates)

chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Days;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;

If I have not properly answered your questions due to a misunderstanding, please let me know and revise your question to guide me in the right direction

(Code examples with actual data you use to generate the plots, with resulting images + what you want it to do instead of what is displayed in the image is helpful - you have part of this but it is incomplete)

Good luck!

like image 93
JHubbard80 Avatar answered Dec 18 '22 18:12

JHubbard80