
8 Answers, 1 is accepted
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

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??
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

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


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