SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

0
0

Hello,

I have a requirement to make the gradient colors changable by a user for a Heatmap. Basically, I am displaying bearing data for acoustic information captured from sensors as a colorized pixel. The Gradients for each of the 4 directions (N, S, E, W) are defined as a color. I can’t seem to get the colors on the Gradient stops to Bind to the values in my ViewModel. So this isn’t working:

 <s:FastHeatMapRenderableSeries DataSeries="{Binding BearingData}" Maximum="360" IsEnabled="{Binding Colorize}">
                <s:FastHeatMapRenderableSeries.ColorMap>
                    <LinearGradientBrush x:Name="BearingBrush">
                        <GradientStop Offset="0" Color="{Binding NorthColor, Mode=TwoWay}"/>
                        <GradientStop Offset=".25" Color="{Binding EastColor, Mode=TwoWay}"/>
                        <GradientStop Offset="0.5" Color="{Binding SouthColor, Mode=TwoWay}"/>
                        <GradientStop Offset=".75" Color="{Binding WestColor, Mode=TwoWay}"/>
                        <GradientStop Offset="1" Color="{Binding NorthColor, Mode=TwoWay}"/>
                    </LinearGradientBrush>
                </s:FastHeatMapRenderableSeries.ColorMap>
            </s:FastHeatMapRenderableSeries>

What I am having to do is:

 <s:FastHeatMapRenderableSeries DataSeries="{Binding BearingData}" Maximum="360"  ColorMap="{Binding BearingBrush}" IsEnabled="{Binding Colorize}">

And then when a color changes, I need to replace the Brush in its entirety:

  private LinearGradientBrush MakeBearingBrushForColorizing()
    {
        var stops = new GradientStopCollection();
        stops.Add(new GradientStop(NorthColor, 0));
        stops.Add(new GradientStop(EastColor, 0.25));
        stops.Add(new GradientStop(SouthColor, 0.5));
        stops.Add(new GradientStop(WestColor, 0.75));
        stops.Add(new GradientStop(NorthColor, 1));

        return new LinearGradientBrush(stops);
    }

Even this didn’t work before a recent fix: https://www.scichart.com/questions/question/2d-heatmap-change-colormap

But it works now.

Is it possible for your control to respond to changes in the GradientStop’s values? Am I missing something, or is this an adjustment you will need to make?

I am also going to have a scenario where I need to bind the Offset value on one brush, and adjust it with a slider, just so you know the full requirement.

Thank you for your time and consideration,
Mike.

Version
4.0.6.8540
  • You must to post comments
0
0

Hi Michael,

If you get our latest 4.0.7 build from NuGet, you will find that changes to GradientStops are now supported.

Also in v4.1.

Thanks!

Andrew

  • Michael Dusoe
    sorry, the other post should have been a comment to this one ;(
  • You must to post comments
0
0

Thanks Andrew. I have tried this in both 4.1.0.8615 and 4.0.7.8594, and I am struggling getting it to work.

I have tried the Binding technique I attempted above, and it won’t bind because the Gradient Stops are not in the Visual Tree (at least I think that is the reason). Before I went down the path of hacking a solution for that, I tried to just update the Colors in my View Model directly with something like BearingBrush.GradientStops[0].Color = NorthColor; I can’t seem to get it to react to my change.

Could you please provide an example where you made this work, so I can see the approach you designed for and make it work in my scenario?

Thanks.

  • Andrew
    Right I misunderstood you. We added the ability to update the chart when the entire Gradient Brush changes, but we cannot (and will not be able to respond to) changes in Gradient Stop. The reason why is that we would have to subscribe to DependencyPropertyChanged events for every single stop, as well as respond to changes in GradientStopCollection, and the performance would be horrible. It’s better to replace the entire brush in one go!
  • Michael Dusoe
    Thanks, I had a sneaking suspicion this was the case. Creating a new Brush isn’t that bad on a Color change, but I am seeing really poor lag when a slider changes an Offset and I need to make a new brush on every little change in the slider’s value. I may have to implement a delayed application technique, and only make a new brush every so often.Anyway, have a nice weekend!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.