I have a master report with 3 subreports and there is a bar chart on one of the subreports. In the bar chart report class, I have a databind fiunction, for testing, I am manually populate the data, but later on I need to pass a dataset into this function.
public void DataBind(DataSet aDS)
{
ChartSeries chartSeries = new ChartSeries();
chartSeries.Name = "Sales";
chartSeries.Type = ChartSeriesType.Bar;
// add new items to the series,
// passing a value and a label string
chartSeries.AddItem(120, "Internet");
chartSeries.AddItem(140, "Retail");
chartSeries.AddItem(35, "Wholesale");
chart1.Series.Add(chartSeries);
//bind DAtaSet
chart1.ChartTitle.TextBlock.Text =
"My Test Chart";
chart1.Report.DataSource = aDs;
chart1.Series.Clear();
ChartSeries s = new ChartSeries();
s.Type =
ChartSeriesType.Pie;
s.DataYColumn =
"Value";
s.DataLabelsColumn =
"Desc";
chart1.Series.Add(s);
}
On the master report class I have a function that call the databind function,
public void SubReportChartDataBind(DataSet aDS)
{
MyChartReport rpt = new MyChartreport();
rpt.DataBind(aDS);
subReport3.ReportSource = rpt;
}
and this SubReportChartDataBind function called by the report viewer aspx page.
DataSet oDS = GetDataSetForChart();
MyReportMaster rptMaster = new MyReportMaster();
rptMaster.SubReportChartDataBind(oDs);
this.ReportViewer1.Report =rptMaster;
But on the chart, ther is no data shown, the error is "there is no or empty series". Anybody can give me a hand?
Thanks in advance
16 Answers, 1 is accepted

The problem is that you set the DataSource of your subreport (chart1.Report.DataSource = aDs;) which when rendered generates one DetailSection for each row of the data source. For more information please see Understanding Report Sections. Instead you should leave it unbound and set the data source just for the chart item. You would need to do that in the NeedDataSource event by adding the series to the definition chart item, or implementing a public property in your chart subreport to handle this easily:
public object ChartDataSource
{
get { return this.chartDataSource; }
set { this.chartDataSource = value; }
}
private void chart1_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender;
ChartSeries series = new ChartSeries(....);
DataTable dt = ((DataSet)this.ChartDataSource).Tables["..."];
...
}
What's more you actually do not need to create a subreport to host the chart item (generally speaking the chart is report where the data is drawn as lines and bars instead of typed as text).
private void chart1_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender;
ChartSeries series = new ChartSeries(....);
DataTable dt = ((DataSet)this.DataSource).Tables["..."];
}
Hope this helps.
Best wishes,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

I need to put the chart into a subreport since my master report contains other subreports, the chart is just one of them.

chart1.Series.Clear();
ChartSeries s = new ChartSeries();
s.Name =
"Percentage";
s.Type =
ChartSeriesType.Pie;
s.DataYColumn =
"value";
s.DataLabelsColumn =
"desc";
s.Appearance.LegendDisplayMode =
ChartSeriesLegendDisplayMode.ItemLabels;
chart1.Series.Add(s);
I believe this blog post by my colleague Vesselin should point you in the right direction: Formatting RadChart Labels. i.e. DefaultLabelValue = "#%".
Kind regards,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

I have added
s.DefaultLabelValue = "#Y";
or
s.DefaultLabelValue = "#%";
But it does not work. Please help....
Code Snippet:
chart1.Series.Clear();
ChartSeries s = new ChartSeries();
s.Name ="Percentage";
s.Type =ChartSeriesType.Pie;
s.DataYColumn ="value";
s.DataLabelsColumn ="desc";
s.Appearance.LegendDisplayMode =ChartSeriesLegendDisplayMode.ItemLabels;
s.DefaultLabelValue = "#Y";
or
s.DefaultLabelValue = "#%";
chart1.Series.Add(s);
I've just tried this both on a static series and on dynamically added one like in your case and it seems to work properly for both. I've attached the sample report for your convenience.
All the best,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thanks for the extra effort.
I took your Report2 class and put into my reportviewer aspx, what I got is "There is no or empty series"
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadReport();
}
}
private void LoadReport()
{
Report2 rpt = new Report2();
this.ReportViewer1.Report = rpt;
}
I've attached a fully working solution with my report that is used in a website with your code.
All the best,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.


private void chart1_NeedDataSource(object sender, System.EventArgs e)
{
chart1.ChartTitle.TextBlock.Text = "My Test for Pie chart";
chart1.Series.Clear();
ChartSeries s = new ChartSeries();
s.Name = "Color Percentage";
s.Type = ChartSeriesType.Pie;
s.DataYColumn = "cnt";
s.DataLabelsColumn = "color";
//s.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
s.DefaultLabelValue = "#%";
chart1.Series.Add(s);
DataTable table = new DataTable();
table.Columns.Add("color", typeof(string));
table.Columns.Add("cnt", typeof(int));
table.Rows.Add(new object[] { "Red", 1 });
table.Rows.Add(new object[] { "Blue", 2 });
table.Rows.Add(new object[] { "Yellow", 3 });
table.Rows.Add(new object[] { "Green", 4 });
table.Rows.Add(new object[] { "Gray", 2 });
//DataTable dt = ((DataSet)this.ChartDataSource).Tables[0];
Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender;
chart.DataSource = table;
}
You can try the above code and will see the color name shows on the chart but not the percentage.
Basically, I want to show the color name and its percentage, is that possible.
Thanks for your help
-phelix
I now see where the problem comes from - it is the DataLabelsColumn property that also "overrides" the DefaultLabelValue property. You can either comment it out and you would have the data formatted in percentage as you would like, or if you want to show the color as well, you would have to create manually the chart series and items in the definition and use a formatting like this:
s.DefaultLabelValue = "#% - #ITEM"; where #ITEM is the name of the item, you have specified declaratively. That is the reason this would not work when the chart item is databound - you cannot access the items and change their names. They would show as Item 1, Item 2 etc by default.
Greetings,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

For the first problem try to set the Name and YValue properties of the series items in the following way:
ChartSeriesItem item = new ChartSeriesItem();
item.YValue = (int)row["cnt"];
item.Name = (string)row["color"];
s.Items.Add(item);
To achieve the second result you have to populate the XAxis manually. Consider the following snippet:
private void chart1_NeedDataSource(object sender, System.EventArgs e) |
{ |
chart1.ChartTitle.TextBlock.Text = "My Test for Bar chart"; |
chart1.Series.Clear(); |
ChartSeries s = new ChartSeries(); |
s.Name = "Color Values"; |
s.Type = ChartSeriesType.Bar; |
DataTable table = new DataTable(); |
table.Columns.Add("color", typeof(string)); |
table.Columns.Add("cnt", typeof(int)); |
table.Rows.Add(new object[] { "Red", 1 }); |
table.Rows.Add(new object[] { "Blue", 2 }); |
table.Rows.Add(new object[] { "Yellow", 3 }); |
table.Rows.Add(new object[] { "Green", 4 }); |
table.Rows.Add(new object[] { "Gray", 2 }); |
chart1.PlotArea.XAxis.AutoScale = false; |
chart1.PlotArea.XAxis.AutoShrink = false; |
chart1.PlotArea.XAxis.Items.Clear(); |
foreach (DataRow row in table.Rows) |
{ |
double val = double.Parse(row[1].ToString()); |
string cat = row[0].ToString(); |
ChartSeriesItem item = new ChartSeriesItem(); |
item.YValue = val; |
item.Name = cat; |
s.Items.Add(item); |
chart1.PlotArea.XAxis.Items.Add(new ChartAxisItem(cat)); |
} |
chart1.Series.Add(s); |
} |
Hope this helps.
Regards,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

this.chart1.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Value";
this.chart1.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Month";
this.chart1.PlotArea.XAxis.AxisLabel.Appearance.Position.X=0;
this.chart1.PlotArea.XAxis.AxisLabel.Appearance.Position.Y=0;
Then I changed the plotarea margin bottom to 40%, now I can see the "Month" shows up, but it is too far from the XAxis, how can I move it near the XAxis? like just underneath the axis, I also changed the margin left to 40% but the axis label never shown up. What properties I should set to move the text to the end of the axis? Like:
Value
|
|
|
|
|
-----------------------------
Month
Thanks again.
Currently the axis labels are rendered in the spare space between the corresponding axis and the chart's border. In order to specify more precisely the position of the label you can use the AlignedPosition property as follows:
chart1.PlotArea.YAxis.AxisLabel.Appearance.Position.AlignedPosition = AlignedPositions.TopRight;
The YAxis label cannot be put over the axis as there is not way for now to specify such disposition of the elements.
All the best,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.