This is a migrated thread and some comments may be shown as answers.
Dynamically grouping - CHART - ASP.NET
4 Answers 49 Views
This is a migrated thread and some comments may be shown as answers.
Rafał
Top achievements
Rank 1
Rafał asked on 11 Jul 2012, 09:56 AM

Hi,

I have report with one chart. I would like to have chart with dynamic series.

My dataset (attachment): 00ds.png

My C# code:

customChart.DataGroupColumn = "Status";
customChart.PlotArea.XAxis.DataLabelsColumn = "Quarter";

I've got some strange chart as a result: 01.png. Some series are assigned incorrect. For example, in the Q1 there is "Deleted" with value 10, but it should be in the Q3.

I would like to get something like this: 02.png (note that Q3 and Q4 are changed in the X axis).

Is it possible?

Thanks,

Rafal

4 Answers, 1 is accepted

Sort by
0
John S.
Top achievements
Rank 1
answered on 12 Jul 2012, 02:04 AM
Rafal,

Try sorting the data by Quarter followed by a sort in Status. I believe that will correct the chart.

John
0
Elian
Telerik team
answered on 12 Jul 2012, 04:38 PM
Hi Rafal,

When using the DataGroupColumn property the items arrangement is consequential and cannot have gaps - meaning that if it should appear like this:
data1, empty, data2,
it will actually render like this:
data1, data2, empty

The only way to avoid this is to programmatically create the series and the items. When you create the items they need to have both Y-Value and X-Value (the X-Value determines exactly where on the X-AXis the column will be placed). 

You will find these articles helpful on the matter: 
Regards,
Elian
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Darryl
Top achievements
Rank 1
answered on 26 Nov 2012, 01:32 AM
Telerik, please, please tell me the chart is smarter than this!!!!!

We shouldn't have to "doctor" the data to make the charts work correctly.

I have to find an embedded reporting solution for many different types of reports but I really don't want to have to do this for every datasource I supply.
0
Elian
Telerik team
answered on 28 Nov 2012, 10:09 AM
Hello Darryl,

You don't need to 'doctor' the data, you just need to build the series programmatically. Please refer to the links in the previous post and to the following sample code snippet creating a chart with grouping by Category:
private void chart1_NeedDataSource(object sender, EventArgs e)
{
    //here you can actually get the data from the database but the differences are minor
    var data = DataClass.GetData();
    chart1.Series.Add(new ChartSeries());
 
 
    foreach (var item in data)
    {
        //this simulates the grouping
        //if the series already exists we take it and use it               
        var series = chart1.Series.GetByName(item.Category.ToString());
        //if it doesn't, we create it
        if (series == null)
        {
            series = new ChartSeries(item.Category.ToString());
            chart1.Series.Add(series);
        }
        //now we work with this series
        //we use the new ChartSeriesItem(double x, double y) overload
        //if the chart will be only for 1 year time span then we can use the month for x-value
        //if it covers more than one year, we will need more complex expression, including the year
        series.Items.Add(new ChartSeriesItem(item.Date.Month, item.Value));
    }
    //and now we change the x-axis labels with the months names           
    chart1.PlotArea.XAxis.AutoScale = false;
    chart1.PlotArea.XAxis.AddRange(1, 12, 1);
    var months = "January February March April May June July August September October November December".Split(' ');
    for (int i = 0; i < 12; i++)
    {
        chart1.PlotArea.XAxis.Items[i].TextBlock.Text = months[i];
    }
    chart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = -30;
}

 
Greetings,
Elian
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Asked by
Rafał
Top achievements
Rank 1
Answers by
John S.
Top achievements
Rank 1
Elian
Telerik team
Darryl
Top achievements
Rank 1
Share this question
or