Hello ,
Scenario:
We need to show the bar graph using custom colors, but when we run code, we get only color that comes first in color Palette [refer to below code].
Below example showing the one of the possible scenario, that we have 3 values bound to listbox and we need to show those values to bar graph.
XAML :
<telerik:RadChart x:Name="testChart" Width="350" Height="490" PaletteBrushesUseSolidColors="True"> </telerik:RadChart>
Code Behind :
public partial class TestParentClass
{
System.Windows.Controls.ListBox ChartListData = new System.Windows.Controls.ListBox();
string TechID
{
get;
set;
}
private BrushCollection _palette;
public BrushCollection Palette
{
get
{
return this._palette;
}
set
{
this._palette = value;
}
}
public TestParentClass()
{
this.Palette = new BrushCollection()
{
new SolidColorBrush(Colors.Green),
new SolidColorBrush(Colors.Yellow),
new SolidColorBrush(Colors.Red)
};
}
public void LoadChartData()
{
try
{
System.Windows.Controls.ListBox ChartListData = new System.Windows.Controls.ListBox();
ChartListData.Items.Add(new TestClass(3,"first"));
ChartListData.Items.Add(new TestClass(6, "Second"));
ChartListData.Items.Add(new TestClass(8, "Third"));
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(25, GridUnitType.Auto) });
grid.RowDefinitions.Add(new RowDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100, GridUnitType.Auto) });
testChart.Content = grid;
////Chart Title
ChartTitle customTitle = new ChartTitle();
customTitle.Content = "Title";
grid.Children.Add(customTitle);
grid.Background = new SolidColorBrush(Colors.Black);
////Chart Legend
ChartLegend legend = new ChartLegend();
legend.UseAutoGeneratedItems = false;
legend.Header = string.Empty;
legend.Name = "Legends";
Grid.SetColumn(legend, 2);
Grid.SetRow(legend, 1);
grid.Children.Add(legend);
//Chart Area
ChartArea viewChart = new ChartArea();
foreach (Brush item in this.Palette)
{
testChart.PaletteBrushes.Add(item);
}
testChart.PaletteBrushesUseSolidColors = true;
testChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
Grid.SetRow(viewChart, 1);
Grid.SetColumn(viewChart, 0);
grid.Children.Add(viewChart);
DataSeries Chartseries = new DataSeries();
Chartseries.Definition = new BarSeriesDefinition();
foreach (TestClass Item in ChartListData.Items)
{
Chartseries.Add(new DataPoint() { YValue = Convert.ToInt32(Item.count), XCategory = Item.Legend });
}
viewChart.DataSeries.Add(Chartseries);
}
catch (Exception ex)
{
}
}
}
public class TestClass
{
public int count;
public string Legend;
public TestClass(int c,string s)
{
count = c;
Legend = s;
}
}
The issue being faced is that whenever we enable to show custom colrs on bars
PaletteBrushesUseSolidColors = true;
testchart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
Then we do not get the custom legeds e.g here we have first,second third etc instead we gte the either [item0,item1...] or [series1,series2..].
Could you please help us to resolve these issue.
Thanks,