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

Removing a Series from a Databound Chart

1 Answer 76 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Dan Schmecker
Top achievements
Rank 1
Dan Schmecker asked on 02 Dec 2009, 02:41 PM

Hello,
i'm trying to programmatically create a chart in VB. (this is my first time working with RadCharts)
My issue is:
When i assign a data source to the chart, it seems that its assumed that all data columns need to be made into their own Series.
I'm using a SQL stored procedure that produces 16 different columns & I only need to use 5 of them...the other 11 can be left alone.
How do I best go about doing that?
When i tried defining just the Series's that i needed, it just added them to the other 16 Series that were created automaticly.

I've included the relevant code below. Thanks.

 

 

 

 

Protected Sub Loader(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        Dim sqlDataSource As New SqlDataSource()  
        sqlDataSource.ID = "myDataSource" 
        sqlDataSource.ConnectionString = "xxxxxxxxxxxxxxxxxxxxxxx" 
 
        sqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure  
        sqlDataSource.SelectCommand = "Analyze_SLA" 
        Me.Page.Controls.Add(sqlDataSource)  
        RadChart1.DataSourceID = "myDataSource" 
 
        RadChart1.Skin = "Colorful" 
        RadChart1.ChartTitle.TextBlock.Text = "Test Chart" 
        RadChart1.DefaultType = Telerik.Charting.ChartSeriesType.Area  
        RadChart1.AutoLayout = True 
 
        Dim chartSeries1 As New ChartSeries()  
        chartSeries1.Name = "Total Count" 
        chartSeries1.Type = ChartSeriesType.Area  
        chartSeries1.DataYColumn = "The_Count" 
        RadChart1.Series.Add(chartSeries1)  
 
        Dim chartSeries2 As New ChartSeries()  
        chartSeries2.Name = "Two" 
        chartSeries2.Type = ChartSeriesType.Area  
        chartSeries1.DataYColumn = "Issue2" 
        RadChart1.Series.Add(chartSeries2)  
 
 
        Dim chartSeries3 As New ChartSeries()  
        chartSeries3.Name = "Three" 
        chartSeries3.Type = ChartSeriesType.Area  
        RadChart1.Series.Add(chartSeries3)  
 
 
        RadChart1.DataBind()  
        Me.Page.Controls.Add(RadChart1)  
    End Sub 

 

 

1 Answer, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 02 Dec 2009, 05:10 PM
It seems like you are mixing two approaches. One is to databind the grid by setting it equal to whatever is returned from the SQL query, and the other is manually adding the series.

For your particular case what I would do is have the SQL query fill a DataTable object, and then using this object manually add SeriesItems to a ChartSeries and then add these series items to the Series collection of the RadChart. What you are doing now is binding the 16 columns to series by setting the DataSourceID of the RadChart, and that's why you are still seeing all 16. If you go through the steps manually and at the end call DataBind() you should only see your 5 series.
Tags
Chart (Obsolete)
Asked by
Dan Schmecker
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Share this question
or