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

Chart DataSource and code data - Why doesn't this work

1 Answer 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 03 Aug 2012, 04:33 PM
Hi..
I'm trying to bind 1 datasource and add another series programmatically.
But my code to add  new series does not show up. If I remove the datasource it does. 
What's wrong with this?   thx!

   SQL = "SELECT  *  TEMP_HUMID_ANALYSIS ";
            


            this.chartTEMP_HUMID.DataSource = new SqlDataSource(DC.Connection.ConnectionString, SQL);
            
// THIS WORKS


// THIS DOES NOT nothing.. if I remvoe the above it works
            // Red Series
            ChartSeries serie1 = new ChartSeries();
            serie1.Name = "Red";
            serie1.Type = ChartSeriesType.Area;
            serie1.YAxisType = ChartYAxisType.Secondary;


            serie1.Appearance.Border.Visible = false;
            serie1.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Hatch;
            serie1.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
            serie1.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.SeriesName;


            Telerik.Reporting.Charting.ChartSeriesItem item = new Telerik.Reporting.Charting.ChartSeriesItem();
            
            item.XValue = 70;
            item.YValue = 0;


            serie1.AddItem(item);




            item = new Telerik.Reporting.Charting.ChartSeriesItem();


            item.XValue = 68.7;
            item.YValue = 82;


            serie1.AddItem(item);




            item = new Telerik.Reporting.Charting.ChartSeriesItem();


            item.XValue = 80;
            item.YValue = 55;


            serie1.AddItem(item);




            item = new Telerik.Reporting.Charting.ChartSeriesItem();


            item.XValue = 83.3;
            item.YValue = 0;


            serie1.AddItem(item);




            this.chartTEMP_HUMID.Series.Add(serie1);

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 08 Aug 2012, 12:54 PM
Hi Jon,

You cannot add manual series when the chart is databound, in fact the NeedDataSource event which would be the correct place to do such a thing, would not even fire when you have the DataSource property of the chart set. You can either create all needed series in the designer and bind them, or create the chart series and items entirely programmatically, without using the DataSource property of the chart.

All the best,
Steve
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 >

Tags
General Discussions
Asked by
Jon
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or