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

Problems with two dataseries in chart.

2 Answers 31 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Kristjan Einarsson
Top achievements
Rank 1
Kristjan Einarsson asked on 11 Mar 2013, 03:18 PM
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 Answers, 1 is accepted

Sort by
0
Missing User
answered on 14 Mar 2013, 01:27 PM
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.

0
Kristjan Einarsson
Top achievements
Rank 1
answered on 18 Mar 2013, 08:53 AM
Thanks, worked as described.
Tags
Chart
Asked by
Kristjan Einarsson
Top achievements
Rank 1
Answers by
Missing User
Kristjan Einarsson
Top achievements
Rank 1
Share this question
or