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

Chart with multiple series from diferent datasources

2 Answers 341 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gonçalo
Top achievements
Rank 1
Gonçalo asked on 16 Nov 2011, 04:20 PM
Hi,

I'm a bit lost with this problem..
I need to represent in the same chart, values from different datasources. (i.e. each serie of chart should map one column of each datasource)

I need this because I'm receiving my data trough webservices and I can't manage or change the source(sql)..

Regards,

2 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 17 Nov 2011, 04:58 PM
Hi Gonçalo, 

You have two options here:
  1. You can collect all the data in the code-behind in one class and bind the Chart to ObjectDataSource which uses that class.(the easier one)
  2. Or you can collect the data in the code behind and dynamically create the chart series and add them to the chart. (Which is basically the same but will give you some additional control over the data)
    Telerik.Reporting.Charting.ChartSeries newSeries = new Telerik.Reporting.Charting.ChartSeries();
                newSeries.AddItem();
                newSeries.AddItem();
                ...
                chart1.Series.Add(newSeries);
Kind regards,
Elian
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Gonçalo
Top achievements
Rank 1
answered on 22 Nov 2011, 01:38 PM
Thank you Elian,

I solve my problem like you said.. I let a bit of my code for one of the series (in my case I have multiple charts with more than 2 series):

private ChartSeries doSerie1()
        {
            serie1 = new ChartSeries();
            serie1.Name = Constants.cht_GSM_OVERVIEW_Cdr_Serie3;
            serie1.Type = ChartSeriesType.Bar;
            serie1.YAxisType = ChartYAxisType.Secondary;

            serie1.Appearance.Border.Visible = false;
            serie1.Appearance.FillStyle.FillType = style.FillType.Solid;
            serie1.Appearance.FillStyle.MainColor = System.Drawing.Color.Yellow;
            serie1.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.SeriesName;

            items1 = result.CallDropRateChartDataInfo.NumberOfTchDropsChartDataList;
            for (int i = 0; i < resultMax; i++)
            {
                serie1.AddItem(Convert.ToDouble(items1[i].ChartDataPointValue));
                serie1.Appearance.ShowLabels = false;

                if (i % 2 == 0)
                {
                    chart1.PlotArea.XAxis[i].TextBlock.Text = items1[i].Date.ToShortDateString();
                }
                else
                {
                    chart1.PlotArea.XAxis[i].TextBlock.Text = " ";
                }
            }

            return serie1;
        }
Tags
General Discussions
Asked by
Gonçalo
Top achievements
Rank 1
Answers by
Elian
Telerik team
Gonçalo
Top achievements
Rank 1
Share this question
or