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

Color converter no being called on update

2 Answers 129 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
svs
Top achievements
Rank 1
svs asked on 20 May 2013, 03:53 PM
I have a Cartesian chart as follows:

<telerik:RadCartesianChart x:Name="chart" Grid.Column="0">
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries ItemsSource="{Binding DataItems}" ValueBinding="Value" CategoryBinding="DayPeriod" >
            <telerik:BarSeries.PointTemplate>
                <DataTemplate>
                    <Rectangle Fill="{Binding Converter={StaticResource BrushConverter}, ConverterParameter={StaticResource brushes}}"/>
                </DataTemplate>
            </telerik:BarSeries.PointTemplate>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis Minimum="{Binding MinValue}" Maximum="{Binding MaxValue}" MajorStep="{Binding StepSize}" LabelStyle="{StaticResource axisLabelStyle}" />
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis LabelFitMode="Rotate" LabelInterval="2"/>
    </telerik:RadCartesianChart.HorizontalAxis>
</telerik:RadCartesianChart>

I'm setting the colour of each individual Bar in the BarSeries via an IValueConverter (blue for positive, red for negative) using a BrushCollection defined in the UserControl's resources passed into the Value Converted.
It works very nicely!
The Chart is bount to an ObservableCollection<t> of items implemention INotofyPropertyChanged. When the values change, the graph does indeed update - but it never calls the Color Converter and it the value goes from - to + or the other way around it ends up with the wrong colour.

I can't see how to force this update. Is there a way?

Thanks -



2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 23 May 2013, 03:30 PM
Hi Simon,

I think that the only problem is that the binding does not have a Path. The binding does not recall the converter because only a property of the DataPoint has changed and not the whole DataPoint (the DataContext of the Rectangle). I guess that in the Converter you get the Value of the DataPoint, so what you need to do is simply set a Path to the binding and update the converter as needed:
<telerik:BarSeries.PointTemplate>
 <DataTemplate>
  <Rectangle Fill="{Binding Value, Converter=... />

Regards,
Petar Marchev
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
svs
Top achievements
Rank 1
answered on 23 May 2013, 04:20 PM
Petar -

Thanks very much! You were quite right about what I was doing, and putting the Path in the rectangle did indeed fix it.

Thank you -

Simon
Tags
ChartView
Asked by
svs
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
svs
Top achievements
Rank 1
Share this question
or