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

Chartseries datasource

1 Answer 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bryan Strader
Top achievements
Rank 2
Bryan Strader asked on 15 Sep 2009, 06:41 PM
I am trying to get a line chart to display two different series of data that come from the same datasource(table). Here is my code. It seems the chart is correctly adding the second series when looping through the string values that come back from the one parameter, but only one line is drawn on the chart for the data. How can I filter data down to only certain records per chart series...I've gone through a lot of foums and can't seem to find an answer for this. Any help would be appreciated, thanks.
basically I need the series name to match the value in the ID column for this datatable....


        private void chart1_NeedDataSource(object sender, EventArgs e)

        {

           chart1.DefaultType = ChartSeriesType.Line;

          

           ArrayList al = new ArrayList();

           al = (ArrayList)this.ReportParameters[0].Value;

 

           (sender as Telerik.Reporting.Processing.Chart).DataSource=                                   this.serverAvgCPUDS.ServerAvgCPUDSTable; 

          

           foreach (string s in al)

           {

               ChartSeries series = new ChartSeries(s.ToString());

               series.Type = ChartSeriesType.Line;

 

               series.DataYColumn = "Percent";

               series.DataLabelsColumn = "Time";

 

               chart1.Series.Add(series);

               series = null;

           }

 

        }

1 Answer, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 17 Sep 2009, 02:25 PM
Hello Bryan Strader,

You can achieve this functionality only programmatically as filtering criteria cannot be set for the chart series. Here is an example of how you can do this with code:

private void chart1_NeedDataSource(object sender, EventArgs e) 
        { 
            DataTable dataTable = new DataTable(); 
            dataTable.Columns.Add("ID"typeof(int)); 
            dataTable.Columns.Add("Value"typeof(int)); 
            dataTable.Rows.Add(1, 1); 
            dataTable.Rows.Add(1, 2); 
            dataTable.Rows.Add(2, 3); 
            dataTable.Rows.Add(2, 4); 
            dataTable.Rows.Add(3, 5); 
            dataTable.Rows.Add(3, 6); 
 
            ArrayList parameters = new ArrayList(); 
            parameters.Add("1"); 
            parameters.Add("3"); 
 
            Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart) sender; 
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition; 
 
            chartDef.Series.Clear(); 
            foreach (string s in parameters) 
            { 
                dataTable.DefaultView.RowFilter = "ID = " + s; 
                ChartSeries series = new ChartSeries(s); 
                foreach (DataRowView rowVIew in dataTable.DefaultView) 
                { 
                    series.AddItem((int)rowVIew["Value"]); 
                } 
                chartDef.Series.Add(series); 
            } 
        } 


Sincerely yours,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Bryan Strader
Top achievements
Rank 2
Answers by
Chavdar
Telerik team
Share this question
or