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

Chart: how to show X-axis labels in a selective way

2 Answers 240 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gerald
Top achievements
Rank 1
Gerald asked on 23 Jul 2009, 01:09 PM
Hello,

in my line line chart I have a few hundreds data points. The label values shown for the X-axis are dates. I show only labels for the first data point of every quarter (beginning of January, April, July, ...).

Here's the code for that which is embedded in a data point loop:

ChartAxisItem chartAxisItem;  
 
if (entry.QuotesDate.Month % 3 == 1 && entry.QuotesDate.Month != oldMonth)  
{  
    chartAxisItem = new ChartAxisItem(entry.QuotesDate.Date.ToString("yyyy-MM"));  
    oldMonth = entry.QuotesDate.Month;  
}  
else  
{  
    chartAxisItem = new ChartAxisItem();  
}  
 
_gideonChart.PlotArea.XAxis.AddItem(chartAxisItem);  
 
_gideonChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 270;   
 

Unfortunately "something" is shown even for the empty ChartAxisItem entries. That results in a horizontal white bar which runs right through my labels.

If you know what might cause this behavior or how to implement the above in a better way please let me know.

And how can I show major grid lines in the same selective way?

Thanks and kind regards,

Gerald

2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 28 Jul 2009, 12:51 PM
Hello Gerald,

It is not very clear what this ugly white bar is, but reading your inquiry a few times we can make a guess that these are the axis ticks. Should we assume that since you're using AddItem, you have AutoScale=false? Even through you're adding the items yourself, there is no control over the ticks i.e. they would all be displayed. What you can do is increase the LabelStep to a larger number or hide the ticks (MajorTick.Visible=false) and show only the labels.
The same goes for XAxis.MajorGridLines - they would be either all displayed or all invisible.
If the problem is not related to this, please elaborate or better prepare and send us a sample project that shows the problem at hand. Once we review it, we would be able to provide you with more info.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Gerald
Top achievements
Rank 1
answered on 28 Jul 2009, 02:08 PM
Hi,

I increased the LabelStep size to see what Telerik paints when an empty ChartAxisItem occurres: It's zeros ('0').

No matter if I leave the chart axis items without an initial value like
chartAxisItem = new ChartAxisItem(); 
or if I initialize them with an empty string like
chartAxisItem = new ChartAxisItem(""); 

you paint zeros 0000000000... - if the datapoints are tight enough together like in my case these zeros are melted together to a horizontal bar.

I don't know why Telerik assumes that I want to see zeros when passing an empty string or no value at all.

However the work around to that strange behaviour is to pass spaces.

Kind regards, Gerald
Tags
General Discussions
Asked by
Gerald
Top achievements
Rank 1
Answers by
Steve
Telerik team
Gerald
Top achievements
Rank 1
Share this question
or