XCategory shows number instead of label

5 posts, 1 answers
  1. Michel Hardy
    Michel Hardy avatar
    9 posts
    Member since:
    Jun 2010

    Posted 13 Jul 2010 Link to this post

    Hi, I've setup a line series with the x axis as a category axis like so:

     

    SeriesMapping seriesMapping = new SeriesMapping();
    LineSeriesDefinition redLineSeries = new LineSeriesDefinition();
    LineSeriesDefinition blackLineSeries = new LineSeriesDefinition();
    LineSeriesDefinition orangeLineSeries = new LineSeriesDefinition();
    redLineSeries.ShowPointMarks = false;
    redLineSeries.ShowItemLabels = false;
    redLineSeries.Appearance.StrokeThickness = 1;
    redLineSeries.Appearance.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
    blackLineSeries.ShowPointMarks = false;
    blackLineSeries.ShowItemLabels = false;
    blackLineSeries.Appearance.StrokeThickness = 1;
    blackLineSeries.Appearance.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
    orangeLineSeries.ShowPointMarks = false;
    orangeLineSeries.ShowItemLabels = false;
    orangeLineSeries.Appearance.StrokeThickness = 1;
    orangeLineSeries.Appearance.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Orange);
    seriesMapping = new SeriesMapping();
    seriesMapping.SeriesDefinition = orangeLineSeries;
    seriesMapping.LegendLabel = "ML Historical";
    seriesMapping.ItemMappings.Add(new ItemMapping("RealResultValue", DataPointMember.YValue));
    seriesMapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = "start_time_text" });
    radChart.SeriesMappings.Add(seriesMapping);
    seriesMapping = new SeriesMapping();
    seriesMapping.SeriesDefinition = blackLineSeries;
    seriesMapping.LegendLabel = "ML";
    seriesMapping.ItemMappings.Add(new ItemMapping("ResultValue", DataPointMember.YValue));
    seriesMapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = "start_time_text" });
    radChart.SeriesMappings.Add(seriesMapping);
    seriesMapping = new SeriesMapping();
    seriesMapping.SeriesDefinition = redLineSeries;
    seriesMapping.LegendLabel = "Max Failure";
    seriesMapping.ItemMappings.Add(new ItemMapping("MaxFailure", DataPointMember.YValue));
    seriesMapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = "start_time_text" });
    radChart.SeriesMappings.Add(seriesMapping);
    seriesMapping = new SeriesMapping();
    seriesMapping.SeriesDefinition = redLineSeries;
    seriesMapping.LegendLabel = "Min Failure";
    seriesMapping.ItemMappings.Add(new ItemMapping("MinFailure", DataPointMember.YValue));
    seriesMapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = "start_time_text" });
    radChart.SeriesMappings.Add(seriesMapping);
    radChart.DefaultView.ChartArea.AxisX.AxisStyles.TickLineStyle = (Style)this.Resources["AxisXTickStyle"];
    radChart.DefaultView.ChartArea.AxisX.Title = "Date and time";
    radChart.DefaultView.ChartArea.AxisX.IsDateTime = false;
    radChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = -90;
    radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Normal;

    When I bind the chart with this code, the chart is drawn properly except for the x axis which shows numbers instead for the text it is suppose to bind to: (see the attached file, it is a screen shot of the chart)

    statData = ec.StatDatas.ToList();
    if (statData.Count > 0 && lsbVariable.SelectedItem != null && ((TestVariable)lsbVariable.SelectedItem).load)
    {
        radChart.SeriesMappings[1].LegendLabel = ((TestVariable)lsbVariable.SelectedItem).caption;
        radChart.SeriesMappings[0].LegendLabel = ((TestVariable)lsbVariable.SelectedItem).caption + " Historical";
        radChart.DefaultView.ChartArea.AxisY.Title = ((TestVariable)lsbVariable.SelectedItem).caption;
        radChart.DefaultView.ChartArea.AxisX.LabelStep = (int)(statData.Where(d => d.test_id.Equals(((TestVariable)lsbVariable.SelectedItem).test_id) && d.variable_id.Equals(((TestVariable)lsbVariable.SelectedItem).variable_id)).Count() / (radChart.DefaultView.ChartArea.ActualWidth / 25));
        radChart.ItemsSource = statData.Where(d => d.test_id.Equals(((TestVariable)lsbVariable.SelectedItem).test_id) && d.variable_id.Equals(((TestVariable)lsbVariable.SelectedItem).variable_id));
        SetupStat(statData.Where(d => d.test_id.Equals(((TestVariable)lsbVariable.SelectedItem).test_id) && d.variable_id.Equals(((TestVariable)lsbVariable.SelectedItem).variable_id)).ToList());
        //SetupStatus();
    }

    Please help!

    Michel

  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 16 Jul 2010 Link to this post

    Hello Michel,

    This code seems to work fine for me. I have attached my test page and the resulting chart.  Give it a try and let me know what changes I need to apply in order to reproduce the problem.

    Kind regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Michel Hardy
    Michel Hardy avatar
    9 posts
    Member since:
    Jun 2010

    Posted 19 Jul 2010 Link to this post

    Thanks, for the reply.

    I just noticed that the problem seems to be related to the amount of data.

    For example, I just ran a query that returned 125 rows. The chart is showing the x axis labels as intended. (Screen shot 1)
    Then I run another query that returned 358 rows and now the chart is showing numbers on the x axis instead of the labels. (Screen shot 2)

    You can see the number of rows on the screen shot using the samples field.

    I am still using the same c# code as my first post.

    Thanks for your help again.

    Michel
  5. Answer
    Ves
    Admin
    Ves avatar
    2879 posts

    Posted 21 Jul 2010 Link to this post

    Hi Michel,

    Thanks for the details. The reason seems to be in the Sampling feature in RadChart. When it is enforced, certain information is lost (individual values of YValue, XCategory, etc) as several datapoints are combined into one. And while RadChart allows you to choose how the YValue of the resulting datapoint is calculated, it is not possible to provide the same functionality for XCategory as each category is individual and meaningful.

    In this case I would suggest disabling Sampling by setting the SamplingThreshold property to 0. The default value is 200 i.e. it is disabled when the chart is populated with less than 200 items.

    Best regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Michel Hardy
    Michel Hardy avatar
    9 posts
    Member since:
    Jun 2010

    Posted 21 Jul 2010 Link to this post

    Thank you very much for your support.

    Setting the sampling threshold to 0 fixed my problem.

    Best regards,

    Michel
Back to Top
DevCraft banner