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

Inserting series = wrong palette color

1 Answer 34 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 15 Aug 2012, 02:10 AM
I found a bug with the chart where inserting a series makes all colors incorrect, I have create as simple an example as I could to replicate the problem.

The colors on the second chart are incorrect after swapping the series as it should be the same as Chart 3 - see attached image. The z-index is also incorrect.

<StackPanel>
    <TextBlock Text="Chart 1 - Initial" />
    <telerik:RadCartesianChart x:Name="Chart1" Palette="Metro" Height="100">
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis />
        </telerik:RadCartesianChart.HorizontalAxis>
 
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis />
        </telerik:RadCartesianChart.VerticalAxis>
    </telerik:RadCartesianChart>
 
    <TextBlock Text="Chart 2 - Should be swapped (same as Chart 3)" Margin="0,10,0,0" />
    <telerik:RadCartesianChart x:Name="Chart2" Palette="Metro" Height="100">
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis />
        </telerik:RadCartesianChart.HorizontalAxis>
 
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis />
        </telerik:RadCartesianChart.VerticalAxis>
    </telerik:RadCartesianChart>
 
    <TextBlock Text="Chart 3 - Expected" Margin="0,10,0,0" />
    <telerik:RadCartesianChart x:Name="Chart3" Palette="Metro" Height="100">
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis />
        </telerik:RadCartesianChart.HorizontalAxis>
 
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis />
        </telerik:RadCartesianChart.VerticalAxis>
    </telerik:RadCartesianChart>
</StackPanel>

public class Data
{
    public int Item { get; set; }
    public int Value { get; set; }
}
 
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
 
        // Add Line then Bar series to Chart 1
        InsertSeries(Chart1, true, 0);
        InsertSeries(Chart1, false, 1);
 
        // Add Line then Bar series to Chart 2
        InsertSeries(Chart2, true, 0);
        InsertSeries(Chart2, false, 1);
 
        // Remove Bar series, and re-insert to index 0 on Chart 2
        RemoveLastSeries(Chart2);
        InsertSeries(Chart2, false, 0);
 
        // Add Bar then Line series to Chart 3 (should be the same as Chart 2)
        InsertSeries(Chart3, false, 0);
        InsertSeries(Chart3, true, 1);
    }
 
    private void InsertSeries(RadCartesianChart chart, bool isLine, int index)
    {
        CategoricalSeries series = isLine ? (CategoricalSeries) new LineSeries() : new BarSeries();
        series.ItemsSource = GenerateData();
        series.CategoryBinding = new PropertyNameDataPointBinding("Item");
        series.ValueBinding = new PropertyNameDataPointBinding("Value");
 
        chart.Series.Insert(index, series);
    }
 
    private void RemoveLastSeries(RadCartesianChart chart)
    {
        chart.Series.RemoveAt(chart.Series.Count - 1);
    }
 
    private IEnumerable<Data> GenerateData()
    {
        for (int i = 0; i < 5; ++i)
        {
            yield return new Data()
            {
                Item = i,
                Value = i
            };
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 17 Aug 2012, 12:23 PM
Hello Brendan,

 Thanks for the code provided. However I don't think this is a bug, rather the expected behavior of the RadChartView. In RadChart2 you add Line and then Bar series and by default their colors are taken from the Metro pallette as Green and Blue. Then when you remove the Bar series, you still have Green line left. Even though you add the Bar series at the beginning of your series collection, they are assigned the next available color from the Metro palette - blue. And voilĂ  - you repeated your Chart1 , not Chart 3 and this is the expected behaviour of the control.

Greetings,
Evgenia
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ChartView
Asked by
Brendan
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or