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

0
0

Hello

I have 2 charts, a 2D Heatmap and a 3D Waterfall chart, and I want to be able to programmatically change their color palettes.

The 2D heatmap is set up like this, with the GradientStops bound to an ObservableCollection:

...
<s:HeatmapColorPalette x:Key="HeatmapColorPalette" Maximum="{Binding MaxValue,Mode=TwoWay}"  GradientStops="{Binding ColorPalette}"/>
...
<s:SciChartSurface.RenderableSeries>
    <s:FastUniformHeatmapRenderableSeries 
        x:Name="heatmapSeries" 
        DataSeries="{Binding Data}"
        ColorMap="{StaticResource HeatmapColorPalette}">
    </s:FastUniformHeatmapRenderableSeries>
 </s:SciChartSurface.RenderableSeries>
...

This works as expected. When the binding changes the palette/heatmap changes.

The 3D waterfall is set up the similarly:

...
<s3D:GradientColorPalette x:Key="GradientColorPalette" IsStepped="False"  GradientStops="{Binding ColorPalette}" />
...
<s3D:SciChart3DSurface.RenderableSeries>
    <s3D:WaterfallRenderableSeries3D
        x:Name="waterfallSeries"
        DataSeries="{Binding Data3D}"
        YColorMapping="{StaticResource GradientColorPalette}"
        SliceThickness="1">
    </s3D:WaterfallRenderableSeries3D>
</s3D:SciChart3DSurface.RenderableSeries>
...

This, when passed the same data, doesn’t render the chart.
This chart otherwise works fine if I define the GradientStops statically in the XAML.

This is the GradientStops definition (in f#):

let BlueRed = 
        new ObservableCollection<GradientStop>([
            new GradientStop(Color.FromRgb(0x00uy,0x00uy,0xFFuy),0.0)
            new GradientStop(Color.FromRgb(0xFFuy,0x00uy,0x00uy),1.0)
        ])

I am not sure what I am missing.

(edit: apologies for formatting issues in the question)

Version
5.4
  • You must to post comments
0
0

Hello Joseph,

I am sorry for the late reply. Thank you for your inquiry.

I’ll copy the answer provided for you in the support ticket:

The issue you’ve faced here is a WPF issue but not SciChart one. The reason for it is that GradientColorPalette defined in resources has no DataContext set because it is not in the tree. Unfortunately, fixing WPF issues is out of support scope.

There are not that many solutions for this WPF case. What we can suggest you is to bind directly to the Palette property of your ViewModel from DataTrigger.Setter and use some custom converter like this:

public class TestConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ObservableCollection<GradientStop> gStops)
            {
                var newPalette = new GradientColorPalette()
                {
                    IsStepped = false,
                    GradientStops = gStops
                };
                return newPalette;
            }
            else
            {
                return new GradientColorPalette()
                {
                    GradientStops =
                    {
                        new GradientStop(Colors.Aqua, 0),
                        new GradientStop(Colors.GreenYellow, 1),
                    }
                };
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Please also find the modified sample app attached in the support ticket answer. Hope this helps.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.