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

Pie Chart duplicated in table

2 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Forest
Top achievements
Rank 1
Forest asked on 16 Jul 2012, 09:47 AM
Hello Telerik team,

I created a pie chart dynamically in the pie NeedDataSource function.
void chart1_NeedDataSource(object sender, EventArgs e)
{
    List<Product> products = new List<Product>();
    products.Add(new Product("Parka L", 120));
    products.Add(new Product("Parka M", 100));
    products.Add(new Product("Parka S", 132));
 
    Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
    Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
    defChart.IntelligentLabelsEnabled = false;
    ChartSeries serie = new ChartSeries();
    serie.Type = ChartSeriesType.Pie;
    serie.Clear();
    serie.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
    foreach (Product lst in products)
    {
        ChartSeriesItem item = new ChartSeriesItem();
        item.YValue = (double)lst.QuantityInStock;
        item.Name = (string)lst.Name;
        item.Appearance.Exploded = true;
        item.Label.TextBlock.Text = (string)lst.Name + " - #%";
        serie.Items.Add(item);
    }
    defChart.Series.Add(serie);
}

Unfortunatly the chart is duplicated at each row as you can see with the attached file.
Have you got an idea please ?

Thanks



2 Answers, 1 is accepted

Sort by
0
Accepted
Petio Petkov
Telerik team
answered on 18 Jul 2012, 04:30 PM
Hi Forest,

Changing the chart definition without removing the existing series is the cause for your troubles.

Here it is the modified code that should fix the problem:

private void chart1_NeedDataSource(object sender, EventArgs e)
      {
          List<Product> products = new List<Product>();
          Random rnd1 = new Random();
          products.Add(new Product("Parka L", 120));
          products.Add(new Product("Parka M", 100));
          products.Add(new Product("Parka S", 132));
 
          Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
          Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
          defChart.IntelligentLabelsEnabled = false;
           
          ChartSeries serie = new ChartSeries();
          serie.Type = ChartSeriesType.Pie;
          serie.Clear();
          serie.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
          foreach (Product lst in products)
          {
              ChartSeriesItem item = new ChartSeriesItem();
              item.YValue = (double)lst.QuantityInStock;
              item.Name = (string)lst.Name;
              item.Appearance.Exploded = true;
              item.Label.TextBlock.Text = (string)lst.Name + " - #%";
              serie.Items.Add(item);
          }
          //Added by TELERIK
          defChart.Series.Clear();
          //END: Added by TELERIK
          defChart.Series.Add(serie);
      }

Greetings,
Petio Petkov
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 >

0
Forest
Top achievements
Rank 1
answered on 19 Jul 2012, 08:39 AM
Thanks a lot
It works !
Tags
General Discussions
Asked by
Forest
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Forest
Top achievements
Rank 1
Share this question
or