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

Set color for Pie graphic

8 Answers 251 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jp Maxwell
Top achievements
Rank 1
Jp Maxwell asked on 12 Dec 2007, 08:44 PM
Hello, I'd like to know what property should I used to set the color for every series in a Pie report. Thanks

8 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 13 Dec 2007, 01:41 PM
Hi Jp Maxwell,

In a Pie series the individual colors are set through the Appearance property of the series items. For example:

            ChartSeriesItem seriesItem = new ChartSeriesItem();
seriesItem.Appearance.FillStyle.MainColor = Color.Blue;
seriesItem.Appearance.FillStyle.SecondColor = Color.LightBlue;
seriesItem.Appearance.FillStyle.FillType =             Telerik.Reporting.Charting.Styles.FillType.Gradient
...


Hope this helps.

All the best,
Chavdar
Author nickname the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jp Maxwell
Top achievements
Rank 1
answered on 13 Dec 2007, 06:20 PM
I'm currently using these properties and the graphic is not taking the colors I set, but the default ones. It is strange, since the report is one that I'm generating programmatically and I can assign the colors for it when the chart is a Line or Bar one (indeed, I assign the same properties I use to Pie graphic to set the colors for Bar chart and the it works well), but when I change the type of the series to Pie, the colors are not changing. Here is a piece of code that generate the report:

private

void chtMain_NeedDataSource(object sender, EventArgs e)
{
    chtMain
.PlotArea.XAxis.Items.Clear();
    chtMain
.Series.Clear();
   
    SortValuesByDate();
}

protected

void SortValuesByDate()
{
    if (chtMain.PlotArea.XAxis.Items.Count == 0)
    {
        //Creation of XAxis items
        ...
    }

    if
(DataSource == null)
        return;

    foreach (CustomClass[] reportData in DataSource)
    {
           string name = new Guid().ToString();
        //ChartType is a variable that could be Line, Bar or Pie
         ChartSeries serie = new ChartSeries(name, ChartType);

        //here assign the values for the colors
        serie

.Appearance.LineSeriesAppearance.Color = reportData .Color;
        serie
.Appearance.FillStyle.MainColor = reportData .Color;
        serie.Appearance.FillStyle.FillType = FillType.Solid;
        //creates an item with value 0 for every element in XAxis
        AddDefaultValues(serie);
        foreach (CustomObject serieInfo in reportData)
        {
            serie.Items[GetDateIndex(serieInfo )].YValue += serieInfo.Value;
        }
        chtMain
.Series.Add(serie);
    }
}

Do you see something that can be wrong??

0
Chavdar
Telerik team
answered on 14 Dec 2007, 09:37 AM
Hi Jp Maxwell,

In case of a Pie chart the MainColor and FillType properties of the series items should be set as well:

serie
.Appearance.FillStyle.MainColor = reportData .Color;
serie.Appearance.FillStyle.FillType = FillType.Solid;
//creates an item with value 0 for every element in XAxis
AddDefaultValues(serie);
foreach (CustomObject serieInfo in reportData)
{
serie.Items[GetDateIndex(serieInfo )].YValue += serieInfo.Value;
serie.Items[GetDateIndex(serieInfo )].Appearance.FillStyle.MainColor = reportData.Color;
serie.Items[GetDateIndex(serieInfo )].Appearance.FillStyle.FillType = FillType.Solid;

}

Give it a try and let me know if you have other questions.

Greetings,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Hin
Top achievements
Rank 1
answered on 29 May 2008, 07:42 PM
Hi, 

I have the following code to set the color of the pie chart sections.
I'm setting the datasource of the chart to a collection of objects
containing an int value, string for the label, and a color.
But the pie chart in my report still displays with the default colors.
Am I missing something ?

Thanks in advance,

private void graphePFExterne_NeedDataSource(object sender, System.EventArgs e)
        {
            Section5Source source = (Section5Source)this.DataSource;
            Section5 section5Source = source[0];
            Telerik.Reporting.Processing.Chart graphe = (Telerik.Reporting.Processing.Chart)sender;
            graphe.DataSource = section5Source.SourcePFExterne;

            this.graphePFExterne.Series.Clear();
            this.graphePFExterne.PlotArea.YAxis.Items.Clear();

            ChartSeries serie = new ChartSeries("Pie", ChartSeriesType.Pie);

            serie.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
            serie.Appearance.FillStyle.MainColor = Color.Silver;
            serie.Appearance.LineSeriesAppearance.Color = Color.Silver;

            ChartSeriesItem itemSerie;

            foreach (GrapheTarteItem item in section5Source.SourcePFExterne)
            {
                itemSerie = new ChartSeriesItem();
                itemSerie.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                itemSerie.Appearance.FillStyle.MainColor = item.Couleur;
                itemSerie.Label.TextBlock.Text = item.Libelle;
                itemSerie.YValue = (double)item.Valeur;
                serie.Items.Add(itemSerie);
            }

            this.graphePFExterne.Series.Add(serie);
        }
0
Chavdar
Telerik team
answered on 30 May 2008, 07:38 PM
Hello Hin,

If you are setting explicitly the DataSource property of the processing chart item, all subsequent code will be ignored during databinding.  To solve the problem you have to remove the following line:
graphe.DataSource = section5Source.SourcePFExterne;
Hope this helps.

All the best,
Chavdar
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Hin
Top achievements
Rank 1
answered on 30 May 2008, 07:48 PM
Great, that works. I thought I've tried that before and was getting an empty serie error in my graph. But it works now, thanks a lot !
0
Deva
Top achievements
Rank 1
answered on 11 May 2015, 05:54 PM

I have code to set the pie colors for the individual slices, but my colors do not get updated to Red, any ideas?

 

 

void LoansReport_NeedDataSource(object sender, EventArgs e)
        {
            try
            {
                var sr = sender as Telerik.Reporting.Processing.Report;
                var parameters = sr.Parameters;

                if (parameters["LoansClass"].Value != null)
                {
                    LoansClass lc = null;
                    lc = JsonConvert.DeserializeObject<LoansClass>(ZipStreamHelper.unZip<string>(parameters["LoansClass"].Value as string));
                    this.DataSource = lc;

                    //BAR Chart
                    //                    
                    ChartSeries serie = new ChartSeries();
                    serie.Type = ChartSeriesType.Bar;
                    serie.Clear();
                    serie.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing;

                    int yVal = 0;
                    foreach (DataSlice ds in lc.BarGraph.DataSlices)
                    {
                        ChartSeriesItem item = new ChartSeriesItem();

                        item.Label.TextBlock.Text = ds.Demension;
                        item.Name = ds.Demension;
                        item.YValue = yVal;
                        yVal++;
                        item.XValue = ds.Measure;
                        serie.Items.Add(item);
                    }
                    this.barGraph = (Telerik.Reporting.Chart)this.Items.Find(this.barGraph.Name, true)[0];
                    this.barGraph.ItemDataBound -= barGraph_ItemDataBound;
                    this.barGraph.ItemDataBound += barGraph_ItemDataBound;
                    barGraph.Series.ClearItems();
                    barGraph.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] { serie });

                    barGraph.PlotArea.XAxis.AutoScale = false;
                    if (serie.Items.Count != 0)
                    {
                        barGraph.PlotArea.XAxis.AddRange(0, serie.Items.Count - 1, 1);
                        for (int y = 0; y < serie.Items.Count; y++)
                        {
                            barGraph.PlotArea.XAxis[y].TextBlock.Text = " ";
                        }
                    }
                    barGraph.ChartTitle.TextBlock.Text = lc.BarGraph.Title;

                    this.barGraph.ChartTitle.Appearance.FillStyle.MainColor = System.Drawing.Color.WhiteSmoke;
                    this.barGraph.BitmapResolution = 96F;
                    this.barGraph.ChartTitle.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;

                    barGraph.IntelligentLabelsEnabled = false;
                    barGraph.DataSource = lc.BarGraph.DataSlices;

                    ChartSeries serieBar = new ChartSeries();
                    serieBar.DataYColumn = "Measure";
                    serieBar.DataLabelsColumn = "Demension";
                    serieBar.Name = lc.BarGraph.Title;
                    serieBar.Type = ChartSeriesType.Bar;
                    serieBar.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing;
                    barGraph.Series.ClearItems();
                    barGraph.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] { serieBar });
                    barGraph.ChartTitle.TextBlock.Text = lc.BarGraph.Title;
                    serieBar.PlotArea.EmptySeriesMessage.TextBlock.Text = string.Empty;

                    //PIE Chart
                    //
                    this.pieGraph = (Telerik.Reporting.Chart)this.Items.Find(this.pieGraph.Name, true)[0];
                    //this.pieGraph.ItemDataBound -= barGraph_ItemDataBound;
                    //this.pieGraph.ItemDataBound += pieGraph_ItemDataBound;
                    pieGraph.IntelligentLabelsEnabled = false;
                    //pieGraph.DataSource = null;
                    ChartSeries seriePie = new ChartSeries();
                    seriePie.DataYColumn = "Measure";
                    seriePie.DataLabelsColumn = "Demension";

                    seriePie.Appearance.LabelAppearance.Visible = false;

                    //seriePie.Appearance.LabelAppearance.Distance = 5;
                    //seriePie.Appearance.LabelAppearance.LabelLocation = Telerik.Reporting.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Inside;
                    seriePie.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;                    
                    seriePie.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.Navy;

                    seriePie.Name = lc.PieGraph.Title;
                    seriePie.Type = ChartSeriesType.Pie;
                    seriePie.Appearance.FillStyle.MainColor = Color.Red;
                    seriePie.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                    //seriePie.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing;
                    pieGraph.Series.ClearItems();
                    pieGraph.Appearance.FillStyle.MainColor = Color.Yellow;
                    pieGraph.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;

                    //pieGraph.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] { seriePie });
                    foreach (var y in lc.PieGraph.DataSlices)
                    {
                        ChartSeriesItem item = new ChartSeriesItem();
                        item.YValue = y.Measure;
                        item.Name = y.Demension;
                        item.Appearance.FillStyle.MainColor = Color.Red;
                        item.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                        item.Appearance.Border.Color = Color.Navy;
                        //item.Label.TextBlock.Text
                        seriePie.Items.Add(item);
                    }
                    pieGraph.Series.Add(seriePie);

                    pieGraph.ChartTitle.TextBlock.Text = lc.PieGraph.Title;
                    pieGraph.PlotArea.EmptySeriesMessage.TextBlock.Text = string.Empty;

                    Cavatica35.Shared.Helpers.TraceHelper.TraceError("End of need Data");
                    Cavatica35.Shared.Helpers.TraceHelper.TraceFlush();
                }
            }
            catch (Exception ex)
            {
                Cavatica35.Shared.Helpers.TraceHelper.TraceError(ex.Message + "\n" + ex.InnerException.Message + "\n" );
                Cavatica35.Shared.Helpers.TraceHelper.TraceFlush();
            }
        }


0
Nasko
Telerik team
answered on 13 May 2015, 03:44 PM
Hello Deva,

The Chart item is obsolete and is no longer supported.

You can use the Graph item to build your charts instead. Setting the color of the pies in a Pie Chart can be achieved using Color Palettes, or via Conditional Formatting (DataPointConditionalFormatting).

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Jp Maxwell
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Jp Maxwell
Top achievements
Rank 1
Hin
Top achievements
Rank 1
Deva
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or