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

Binding color to Fill/Stroke property of AreaSeries

3 Answers 209 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lion Pham
Top achievements
Rank 1
Lion Pham asked on 23 Mar 2014, 03:53 PM
Hello,

I want to binding color to the Fill and Stroke property of the AreaSeries but when I try to do that, the color of these properties were not changed to the color I set and they were set to the default color (blue).

Here is the code:

01.<telerikChart:AreaSeries
02.                                    Fill="{Binding SomeData, Converter={StaticResource SomeDataToSolidColorBrushConverter}}"
03.                                    Stroke="{Binding SomeData, Converter={StaticResource SomeDataToSolidColorBrushConverter}}"
04.                                    telerikChart:ChartTrackBallBehavior.TrackInfoTemplate="{StaticResource TrackInfoTemplate}">
05.                                    <telerikChart:AreaSeries.ValueBinding>
06.                                        <telerikChart:PropertyNameDataPointBinding
07.                                            PropertyName="Amount" />
08.                                    </telerikChart:AreaSeries.ValueBinding>
09. 
10.                                    <telerikChart:AreaSeries.CategoryBinding>
11.                                        <telerikChart:PropertyNameDataPointBinding
12.                                            PropertyName="Date" />
13.                                    </telerikChart:AreaSeries.CategoryBinding>
14.                                </telerikChart:AreaSeries>

The SomeDataToSolidColorBrushConverter is a simple converter is used to convert SomeData to expected SolidColorBrush.

Best

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivaylo Gergov
Telerik team
answered on 24 Mar 2014, 12:46 PM
Hi,

I tried to reproduce the issue but with no avail. I have attached a runnable sample project that shows such scenario. Could you please check it and see if this is what you want to achieve?

I am looking forward to your reply.

Regards,
Ivaylo Gergov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Lion Pham
Top achievements
Rank 1
answered on 24 Mar 2014, 03:30 PM
Thanks for your quick reply.

I found the cause of this problem was due to the PaletteName property. I set PaletteName property to "DefaultLight" so the color of the Fill and Stroke property of AreaSeries was not changed. But it is very interesting, if I set value for the Fill or Stroke property directly to a specified color (ex. Red) or a color from StaticResource, the color of the Fill and Stroke property is changed to the color I set successfully, but not working with binding.

Another question, how can I binding color to the Stroke property of the ChartTrackBallBehavior.LineStyle?

Thank you
0
Accepted
Ivaylo Gergov
Telerik team
answered on 24 Mar 2014, 05:56 PM
Hello,

The chart does not support this feature out of the box but I can suggest a possible solution for this scenario:
  1. Whenever the ChartTrackBallBehavior.TrackInfoUpdated event fires, you can apply a different style to the ChartTrackBallBehavior.LineStyle.
  2. To get the current fill/stroke of the series that the ChartTrackBallBehavior targets you can use the TrackBallInfoEventArgs.Context.ClosestDataPoint.Series property and get its Fill or Stroke.

For example if you have AreaSeries or any series that implements the IFilledSeries interface: 

private void ChartTrackBallBehavior_TrackInfoUpdated(object sender, Telerik.UI.Xaml.Controls.Chart.TrackBallInfoEventArgs e)
{
    var stroke = (e.Context.ClosestDataPoint.Series as IFilledSeries).Fill;
    Style style = new Style(typeof(Polyline));
    style.Setters.Add(new Setter { Property = Polyline.StrokeProperty, Value = stroke });
    (sender as ChartTrackBallBehavior).LineStyle = style;
}


If you have any other questions do not hesitate to contact us again.

Regards,
Ivaylo Gergov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Chart for XAML
Asked by
Lion Pham
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Lion Pham
Top achievements
Rank 1
Share this question
or