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

subreport chart there is no or empty series?

16 Answers 441 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
phelix
Top achievements
Rank 1
phelix asked on 08 Sep 2008, 06:04 PM
Hi,
 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

Sort by
0
phelix
Top achievements
Rank 1
answered on 09 Sep 2008, 01:04 PM
ANybody?
0
Steve
Telerik team
answered on 09 Sep 2008, 03:53 PM
Hello Phelix,

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.
0
phelix
Top achievements
Rank 1
answered on 09 Sep 2008, 04:07 PM
Thanks.


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


0
phelix
Top achievements
Rank 1
answered on 09 Sep 2008, 05:45 PM
one more question, How can I show the percentage on every slice of the pie chart?

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);

0
Steve
Telerik team
answered on 10 Sep 2008, 02:35 PM
Hi phelix,

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.
0
phelix
Top achievements
Rank 1
answered on 10 Sep 2008, 06:04 PM

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);




0
Steve
Telerik team
answered on 11 Sep 2008, 02:26 PM
Hi phelix,

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.
0
phelix
Top achievements
Rank 1
answered on 11 Sep 2008, 04:57 PM
Hi, Steve:

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;

}

0
Steve
Telerik team
answered on 12 Sep 2008, 09:37 AM
Hi phelix,

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.
0
phelix
Top achievements
Rank 1
answered on 12 Sep 2008, 01:27 PM
Hi, Steve:$0$0$0$0I tried your aspx and report2 and I still got the same error, and I find out the difference is the version of my Telerik Reporting is 2.5.8.414 and yours is 2.5.8.828. $0$0$0$0$0Maybe that's cause the problem. BUT I have my pie chart worked by passing Dataset to its datasource. The only problem is to show the percentage. $0$0$0$0$0Anyway, I will get the latest version of telerik report and let you updated. $0$0$0$0$0Thanks $0$0-phelix$0
0
phelix
Top achievements
Rank 1
answered on 12 Sep 2008, 05:17 PM
I upgrade to Q2 SP1 2008 and get your report2 working. For further testing, I change the report2 to show my pie chart, and I could NOT get the percentage shown.

        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
0
Steve
Telerik team
answered on 15 Sep 2008, 12:30 PM
Hello 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.
0
phelix
Top achievements
Rank 1
answered on 15 Sep 2008, 09:34 PM
Hi, Steve:$0$0$0$0It does NOT work. I commented the $0$0//s.DataLabelsColumn = "color";$0$0and put$0$0s.DefaultLabelValue = "#%"; YES. It shows the percentage. $0$0$0But if I put s.DefaultLabelValue = "#% - #ITEM"; $0$0or s.DefaultLabelValue = "#ITEM - #%"; $0$0It shows the color name only.$0$0$0$0$0See following Code snippet. $0$0$0$0$0chart1_NeedDataSource()$0$0{$0$0$0            chart1.ChartTitle.TextBlock.Text = "My Test for Pie chart";$0$0            chart1.Series.Clear();$0$0            ChartSeries s = new ChartSeries();$0$0            s.Name = "Color Percentage";$0$0            s.Type = ChartSeriesType.Pie;$0$0$0$0$0            DataTable table = new DataTable();$0$0            table.Columns.Add("color", typeof(string));$0$0            table.Columns.Add("cnt", typeof(int));$0$0            table.Rows.Add(new object[] { "Red", 1 });$0$0            table.Rows.Add(new object[] { "Blue", 2 });$0$0            table.Rows.Add(new object[] { "Yellow", 3 });$0$0            table.Rows.Add(new object[] { "Green", 4 });$0$0            table.Rows.Add(new object[] { "Gray", 2 });$0$0$0$0$0            foreach (DataRow row in table.Rows)$0$0            {$0$0                double val = double.Parse(row[1].ToString());$0$0                string cat = row[0].ToString();$0$0                ChartSeriesItem item = new ChartSeriesItem(val, cat);$0$0                s.Items.Add(item);$0$0            }$0$0            s.DefaultLabelValue = "#% - #ITEM";$0$0            $0$0            chart1.Series.Add(s);$0$0}$0$0$0$0$0$0$0$0$0Also I play around the bar chart and try to show the same data on a bar chart. and on X axis I want the color name shows there and on the bar label I want to show the value. But again, I did not get what I wanted. default it shows the item sequence number (which kind understandable) but shows the color name on the bar label. $0$0I set item.Label.TextBlock.Text = val.ToString(); then the bar labe lshows the value, but I still do not know how to get the color name shows on the xAxis. $0$0$0$0$0Code snippet for bar chart testing:$0$0$0chart2_NeedDataSource()$0$0$0$0{$0$0            chart2.ChartTitle.TextBlock.Text = "My Test for Bar chart";$0$0            chart2.Series.Clear();$0$0            ChartSeries s = new ChartSeries();$0$0            s.Name = "Color Values";$0$0            s.Type = ChartSeriesType.Bar;$0$0$0$0$0            DataTable table = new DataTable();$0$0            table.Columns.Add("color", typeof(string));$0$0            table.Columns.Add("cnt", typeof(int));$0$0            table.Rows.Add(new object[] { "Red", 1 });$0$0            table.Rows.Add(new object[] { "Blue", 2 });$0$0            table.Rows.Add(new object[] { "Yellow", 3 });$0$0            table.Rows.Add(new object[] { "Green", 4 });$0$0            table.Rows.Add(new object[] { "Gray", 2 });$0$0$0$0$0            foreach (DataRow row in table.Rows)$0$0            {$0$0                double val = double.Parse(row[1].ToString());$0$0                string cat = row[0].ToString();$0$0                ChartSeriesItem item = new ChartSeriesItem(val, cat);$0$0 //item.Label.TextBlock.Text = val.ToString();$0$0$0                s.Items.Add(item);$0$0            }$0$0$0$0$0$0$0$0            chart2.Series.Add(s);$0$0$0}$0$0$0$0$0I read through the documentation but the documentation is not that useful. (Could not find anything that introduce the class (and its members ) with any examples. The examples that comes with the intallation does not make too much sense. Most developers won't embed the TableAdapter in the presentation layer, we have another layer call data access layer  in an multi-tiers architecture. I have been using graphicserver and microsoft OWC charting and I have to say their products are more intuitive and the documentation are much better for new users. $0$0$0$0$0$0$0$0$0$0Again, thanks for your patients and help. $0
0
Chavdar
Telerik team
answered on 19 Sep 2008, 12:14 PM
Hello phelix,

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.
0
phelix
Top achievements
Rank 1
answered on 23 Sep 2008, 01:00 PM
Thanks. Now the bar chart is working. One more question, I tried to set the x and y axis label text but they never shown up. 

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.  

0
Chavdar
Telerik team
answered on 26 Sep 2008, 09:25 AM
Hello phelix,

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.
Tags
General Discussions
Asked by
phelix
Top achievements
Rank 1
Answers by
phelix
Top achievements
Rank 1
Steve
Telerik team
Chavdar
Telerik team
Share this question
or