The problem is: when we use the pie, the colors from the palette are used for each datapoint (4 different colors) and the legend shows the 4 datapoints in the serie.
But, switching to the bar, the colors are not used (we only get one color) and the datapoints (Nr1, Nr2...) don't show up in the legend.
private BrushCollection _palette;
public BrushCollection Palette
{
get { return _palette;}
set { _palette = value; }
}
private void MakePallette()
{
Palette = new BrushCollection
{
new SolidColorBrush(Color.FromArgb(255, 106, 148, 200)),
new SolidColorBrush(Color.FromArgb(255, 238, 141, 61)),
new SolidColorBrush(Color.FromArgb(255, 145, 178, 80)),
new SolidColorBrush(Color.FromArgb(255, 255, 155, 152))
};
}
private void MakeChart()
{
RadChart radChart = new RadChart();s
DataSeries dataSeries = null;
MakePallette();
foreach (Brush item in Palette)
{
radChart.PaletteBrushes.Add(item);
}
switch (ChartName) // determine what kind of data to display
{
case "A":
{
radChart.DefaultView.ChartTitle.Content = "All A";
switch (ChartNr) // determine what kind of rendering (bar, pie...etc)
{
case 1:
dataSeries = new DataSeries { Definition = new PieSeriesDefinition() };
break;
case 2:
dataSeries = new DataSeries { Definition = new BarSeriesDefinition() };
break;
}
// Create a DataPoint
DataPoint dataPoint = new DataPoint { YValue = 8, Label = "8", LegendLabel = "Nr 1" };
dataSeries.Add(dataPoint);
dataPoint = new DataPoint { YValue = 3, Label = "3", LegendLabel = "Nr 2" };
dataSeries.Add(dataPoint);
dataPoint = new DataPoint { YValue = 10, Label = "10", LegendLabel = "Nr 3" };
dataSeries.Add(dataPoint);
dataPoint = new DataPoint { YValue = 25, Label = "25", LegendLabel = "Nr 4" };
dataSeries.Add(dataPoint);
}
break;
case "B":
{
radChart.DefaultView.ChartTitle.Content = "All B";
switch (ChartNr) // determine what kind of rendering (bar, pie...etc)
{
case 1:
dataSeries = new DataSeries { Definition = new PieSeriesDefinition() };
break;
case 2:
dataSeries = new DataSeries { Definition = new BarSeriesDefinition() };
break;
}
DataPoint dataPoint = new DataPoint { YValue = 36, Label = "36", LegendLabel = "Krediteringer"};
dataSeries.Add(dataPoint);
dataPoint = new DataPoint { YValue = 14, Label = "14", LegendLabel = "Rettelser"};
dataSeries.Add(dataPoint);
dataPoint = new DataPoint { YValue = 369, Label = "369", LegendLabel = "Enkeltgebyr"};
dataSeries.Add(dataPoint);
}
break;
}
radChart.DefaultView.ChartLegend.Header = string.Empty;
radChart.DefaultView.ChartArea.DataSeries.Add(dataSeries);
}