Pre loader

Axis grid line color when binding to AxisCollection


There are multiple Y axes in my chart. I am displaying grid lines only for the primary axis and I would like to change its color. Please let me know how it might be possible.
I have tried style and it works for X axis (single axes) but doesn’t for Y axes (multiple)

    <Style x:Key="MajorGridLineStyle" TargetType="Line">
        <Setter Property="Stroke" Value="Red"/>

            <s:NumericAxis AxisTitle="{Binding XAxisTitle}" DrawMajorBands="False" DrawMinorGridLines="False" DrawMinorTicks="False"
                           MajorGridLineStyle="{StaticResource MajorGridLineStyle}"/>

I have also tried majorgridlinebrush in my viewmodel but it doesn’t work. Some default color is show for the gridlines

        YAxes.Add(new NumericAxisViewModel
            DrawMajorBands = false,
            DrawMinorGridLines = false,
            DrawMinorTicks = false,
            MajorGridLinesBrush = new SolidColorBrush(Colors.Red)
  • You must to post comments

Hi Kapil

I modified this sample I shared with you last week about Axis MVVM styling,

Added this one line to MainViewModel

    public MainViewModel()
        YAxisViewModels.Add(new NumericAxisViewModel()
            // Apply a style key here to apply a named style to this axis
            StyleKey = "YAxisStyle",
            AxisTitle = "Y Axis",
            MajorGridLinesBrush = Brushes.Purple // this line

I was able to reproduce the problem you saw, where MajorGridLinesBrush wasn’t applied.

I suggest as a workaround now, using the AxisMVVM styling technique I previously described here.

I have also reported a bug, SC-6704 AxisViewModel.MajorGridlinesBrush seems to be ignored

Best regards

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies