Problems with two dataseries in chart.

3 posts, 0 answers
  1. Kristjan Einarsson
    Kristjan Einarsson avatar
    95 posts
    Member since:
    Jan 2010

    Posted 11 Mar 2013 Link to this post

    Hi,
    Im having troubles when having two dataseries in chart.
    The series have different start and end dates that do not intersect.

    The problem is that mars displays twice and the months seem to fall in wrong month (see attachment)
    In the picture the blue (history) series should start in November and end in March.
    The green (2013) series should start in April and end in December.

    Here is the code that creates the series.
    private DataSeries createDataSeries(List<ChartData> data, string legendLabel = "")
            {
                DataSeries series              = new DataSeries();
                BarSeriesDefinition definition = new BarSeriesDefinition();
                definition.ShowItemToolTips    = true;
                definition.ShowItemLabels      = false;
                series.Definition              = definition;
                series.LegendLabel             = legendLabel;
                foreach (ChartData item in data)
                {
                    DataPoint dataPoint   = new DataPoint();
                    dataPoint.YValue      = item.Value;
                    dataPoint.XValue = item.Caption.ToOADate();
                    dataPoint.IsDateTime = true;
                    dataPoint.LabelFormat = "MMM";
                    series.Add(dataPoint);
                    count++;
                }
                return series;
            }

    Can you help me you  ?
    -k
  2. Missing user
    Missing user avatar

    Posted 14 Mar 2013 Link to this post

    Hi Kristjan,

    The reason for this behavior is that you're using the XValue property of the DataPoint and RadChart is trying to set a uniform tick step for the X-Axis' labels. If you set that axis' label format to something like "MMM-dd" you'll see it's actually setting labels for different days, rather than setting identical labels for the same month.

    As far as I can tell, you want to display a single bar for each month. To do this, and, of course, avoid having months appear twice, you should modify the foreach loop like this:
    foreach (ChartData item in data)
    {
        DataPoint dataPoint = new DataPoint();
        dataPoint.YValue = item.Value;
        dataPoint.XCategory = item.Caption.ToString("MMM.");
        series.Add(dataPoint);
        count++;
    }

    Note that if you'll have to display data for more than one year, you should use a format that includes the year component of the DateTime object, such as "`yy MMM.". This is to avoid placing two items having the same month, but a different year, in the same category.

    Kind regards,
    Ivan N.
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristjan Einarsson
    Kristjan Einarsson avatar
    95 posts
    Member since:
    Jan 2010

    Posted 18 Mar 2013 Link to this post

    Thanks, worked as described.
Back to Top