Hi! I have a problem, i would like to databind a PIE in a report, my code for binding a pie chart manually is like SAMPLE A, but i would like to assign YValue from a database, like the SAMPLE B, where i databind a bar chart from a database...
SAMPLE A
SAMPLE B
I would like to fill a pie chart from a database, instead of a bucle...I mean...Something similar to SAMPLE B, where you can assign a DataYColumn, a field from the datasource...
Thanks for your time and i hope to find some help here...
SAMPLE A
private void chart1_NeedDataSource(object sender, EventArgs e) |
{ |
chart1.Width = Unit.Pixel(300); |
chart1.Height = Unit.Pixel(300); |
ChartSeries s = new ChartSeries(); |
s.Name = "NameOfSerie"; |
s.Type = ChartSeriesType.Pie; |
for (int i = 1; i < 6; i++) |
{ |
ChartSeriesItem item = new ChartSeriesItem(); |
item.YValue =i* 3.5; |
item.Label.TextBlock.Text = "A" + i.ToString(); |
s.Items.Add(item); |
} |
s.Appearance.LegendDisplayMode =ChartSeriesLegendDisplayMode.Nothing; |
chart1.Series.Add(s); |
} |
SAMPLE B
private void chart1_NeedDataSource(object sender, EventArgs e) |
{ |
string sql = @"SELECT TOP 10 Production.Product.ListPrice, Production.Product.Name, Production.Product.ProductID FROM Production.Product"; |
string connectionString ="Data Source=localhost;Initial Catalog=AdventureWorks;Integrated Security=True"; |
SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString); |
DataSet dataSet = new DataSet(); |
adapter.Fill(dataSet); |
ChartSeries series = new ChartSeries(); |
series.DataYColumn = "ProductID"; |
series.DataLabelsColumn = "Name"; |
chart1.SeriesOrientation=ChartSeriesOrientation.Horizontal; |
chart1.Width =Unit.Pixel(300); |
chart1.Height = Unit.Pixel(300); |
chart1.Series.Add(series); |
(sender as Telerik.Reporting.Processing.Chart).DataSource = dataSet.Tables[0].DefaultView; |
} |
I would like to fill a pie chart from a database, instead of a bucle...I mean...Something similar to SAMPLE B, where you can assign a DataYColumn, a field from the datasource...
Thanks for your time and i hope to find some help here...