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

Manually set X axis labels (ex. only show 5, 9 and 16)

1 Answer 56 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 25 Sep 2013, 08:44 PM
I have a Chart where I would like to set the X axis labels to show just 5, 9 and 16, for example but nothing else.  How would I got about doing this?
Tks.

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 01 Oct 2013, 07:01 AM
Hi Brian,

The RadChart's axes have two modes - categorical and numerical. In numerical mode, the series associated with the axis are positioned  according their XValue (of their data points) which should be a number or DateTime. For example:
SeriesMapping seriesMapping = new SeriesMapping();
seriesMapping.SeriesDefinition = new LineSeriesDefinition();
seriesMapping.ItemMappings.Add(
 new ItemMapping {DataPointMember=DataPointMember.XValue, FieldName = "XVal" });
seriesMapping.ItemMappings.Add(
 new ItemMapping {DataPointMember=DataPointMember.YValue, FieldName = "YVal" });
seriesMapping.ItemsSource = new List<PlotInfo>
{
    new PlotInfo {XVal = 0.3, YVal = 13},
    new PlotInfo {XVal = 2.8, YVal = 8},
    new PlotInfo {XVal = 3.3, YVal = 18},
    new PlotInfo {XVal = 7.3, YVal = 15},
};
  
this.RadChart1.SeriesMappings.Add(seriesMapping);
(Note that all of the series associated with the axis should have only XValue ItemMapping in their SeriesMapping (and not XCategory), because otherwise the chart will be confused if it has to use the XValue to position data points on the axis or XCategory.)

In the categorical mode the chart will position the items on equal distance from one another (as if the x axis is not continuous, but behaving like slot collection - each item sits on its own slot) and will display an axis label per each item. This label is actually the the XCategory DataPointMember. There are no restrictions to the type. If it is different than string, int or DateTime then the default string from
DataItem.[associated_with_XCategory_property].ToString() is displayed. Example:
SeriesMapping seriesMapping = new SeriesMapping();
seriesMapping.SeriesDefinition = new LineSeriesDefinition();
seriesMapping.ItemMappings.Add(
    new ItemMapping { DataPointMember = DataPointMember.XCategory,
        FieldName = "Category" });
seriesMapping.ItemMappings.Add(
    new ItemMapping { DataPointMember = DataPointMember.YValue,
        FieldName = "YVal" });
seriesMapping.ItemsSource = new List<PlotInfo>
{
    new PlotInfo {Cateogry = "Number 5", YVal = 13},
    new PlotInfo {Cateogry = "Number 9", YVal = 8},
    new PlotInfo {Cateogry = "Number 16", YVal = 18},
};
  
this.RadChart1.SeriesMappings.Add(seriesMapping);
Note that if you want the axis to be in categorical mode, all of the series associated with it should have only XCategory item mapping.

That's said, I think that the categorical mode should fulfill your requirements.

I hope this helps.
 
Greetings,
Petar Kirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Chart
Asked by
Brian
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or