This is a migrated thread and some comments may be shown as answers.

XAxis Item Label spacing

3 Answers 74 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michelle
Top achievements
Rank 1
Michelle asked on 19 Oct 2012, 09:11 PM
Hello,

I am trying to set custom item labels at various points underneath a line chart. I am setting the "Value" property of each ChartAxisItem to the x location I want, but instead the chart is simply finding the maximum value and drawing each label equidistant from each other, regardless of the setting of "Value". Do you know how I can get the effect I want? Isn't "Value" supposed to place the ChartAxisItem at that X location?

Here is some code for example:

radChart1.PlotArea.XAxis.AutoScale = false;
 
var csTest = new ChartSeries();
for (int i = 1; i <= 10; i++)
{
	csTest.Items.Add(new ChartSeriesItem(i, i));
}
radChart1.AddChartSeries(csTest);
radChart1.PlotArea.XAxis.AddItem(new ChartAxisItem("Item 1") { Value = 1 });
radChart1.PlotArea.XAxis.AddItem(new ChartAxisItem("Item 2") { Value = 2 });
radChart1.PlotArea.XAxis.AddItem(new ChartAxisItem("Item 10") { Value = 10 });
// ^^ these are all spaced equidistantally, not according to their "Value"

3 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 23 Oct 2012, 08:15 AM
Hi Michelle,

As you have figured it out - the Value property does not work in the way that you expect. What the chart internally does is that it looks at the first AxisItem's value and the last AxisItem's value and from these Min and Max it creates a range and a step.

I would suggest you don't create the items manually to avoid unnecessary work and to use the AddRange method of the axis. After that you can iterate through the labels and set whatever text you need. Below I have pasted some code to get you started:

radChart1.PlotArea.XAxis.AutoScale = false;
var csTest = new ChartSeries();
for (int i = 1; i <= 5; i++)
{
 csTest.Items.Add(new ChartSeriesItem(i, i));
}
radChart1.AddChartSeries(csTest);
 
radChart1.PlotArea.XAxis.AddRange(1, 5, 1);
 
radChart1.PlotArea.XAxis.Items[0].TextBlock.Text = "Item 1";
radChart1.PlotArea.XAxis.Items[1].TextBlock.Text = "Item 2";
radChart1.PlotArea.XAxis.Items[2].TextBlock.Text = " ";
radChart1.PlotArea.XAxis.Items[3].TextBlock.Text = " ";
radChart1.PlotArea.XAxis.Items[4].TextBlock.Text = "Item 5";

Let us know if we can assist you further.

Kind regards,
Petar Marchev
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Michelle
Top achievements
Rank 1
answered on 24 Oct 2012, 10:51 PM
Thank you for the clarification. Although I do not feel that this is how the code should function, at least now I know that I am not overlooking something.

I could use your example and create a label for each of the hundreds of data points and set them all to " " except for the ones I want to display. However, this will cause the MajorGridLines to not function correctly, since I only want them to display on labels with actual text. Is there any way around this that you know of? 

My project is graphing a large number of data points over time, and I only want the labels to appear at intervals on the hour (i.e. 10:00am), not some fractional part of the hour (i.e. 10:17am). And for these data points I want to have a major grid line drawn vertically upward in the chart.

Michelle
0
Petar Marchev
Telerik team
answered on 25 Oct 2012, 07:22 AM
Hi Michelle,

I am unsure if I have understood your requirements fully. I will ask that you provide us with a couple of snapshots (drawings of some sort) that depict the results that you are after.

Just in short - the MajorGridLines are drawn where the MajorTicks are drawn. Labels are also drawn where the MajorTicks are drawn (unless you set a LabelStep or apply some code as in the previous post). If you don't need a MajorGridLine on every MajorTick you  may need to use MarkedZones instead of the grid lines. You see that there are too many ifs. So please share what your scenario is and what are the final results that you need.

Greetings,
Petar Marchev
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
Tags
Chart (obsolete as of Q1 2013)
Asked by
Michelle
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Michelle
Top achievements
Rank 1
Share this question
or