ColorBar in WPF Surface Chart (SfSurfaceChart)

18 Aug 20212 minutes to read

ColorBar is used to represent the value range in surface via colors. You can define ColorBar for surface chart as shown in the following code example.

Color bar position can be customized using the DockPosition property.
Color bar can either show or hide the labels and this can be done using the ShowLabel property.

<chart:SfSurfaceChart ItemsSource="{Binding DataValues}"  XBindingPath="X"  
                              YBindingPath="Y" ZBindingPath="Z" RowSize="{Binding RowSize}"
                              ColumnSize="{Binding ColumnSize}">
            
            <chart:SfSurfaceChart.ColorBar>
                <chart:ChartColorBar ShowLabel="True" DockPosition="Right"></chart:ChartColorBar>
            </chart:SfSurfaceChart.ColorBar>

        </chart:SfSurfaceChart>
SfSurfaceChart chart = new SfSurfaceChart();
            chart.SetBinding(SfSurfaceChart.ItemsSourceProperty, "DataValues");
            chart.SetBinding(SfSurfaceChart.RowSizeProperty, "RowSize");
            chart.SetBinding(SfSurfaceChart.ColumnSizeProperty, "ColumnSize");
            chart.XBindingPath = "X";
            chart.YBindingPath = "Y";
            chart.ZBindingPath = "Z";
            ChartColorBar colorBar = new ChartColorBar();
            colorBar.DockPosition = ChartDock.Right;
            colorBar.ShowLabel = true;
            chart.ColorBar = colorBar;
            grid.Children.Add(chart);

The following image represents the color bar at the right side of the surface chart.

Color bar position