Search code examples
wpflivecharts

WPF LiveChart: How to Change Color of Gridlines of CartesianChart


I'm new to WPF LiveCharts library. Just wanted to know how can I change the color and style of Gridlines of a chart object. The default is set to Gray I believe. Please see attached.

enter image description here

Here is the code snippet for chart object:

 <lvc:CartesianChart   Series="{Binding SeriesCollection}" Name="chartObj"  >

            <lvc:CartesianChart.AxisX>
                <lvc:Axis MinValue="0"  MaxValue="{Binding MaxXAxisValue}" ></lvc:Axis>
            </lvc:CartesianChart.AxisX>

            <lvc:CartesianChart.AxisY >
            <lvc:Axis MinValue="0"   MaxValue="10" ></lvc:Axis>
            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>

Any idea or solution will be highly appreciated.


Solution

  • The demo you are running, has a theme:

    https://lvcharts.net/App/examples/v1/wpf/Themes

    Documentation is being updated based on the most frequent question in this first year and a half, hopefully this will be more clear.

    The theme sets the default separator style:

    <Style TargetType="lvc:Separator">
                    <Setter Property="Stroke" Value="#1A303030"></Setter>
                    <Style.Triggers>
                        <Trigger Property="AxisOrientation" Value="X">
                            <Setter Property="IsEnabled" Value="False"></Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
    

    You can customize this theme, or override it for your chart:

     <lvc:CartesianChart   Series="{Binding SeriesCollection}" Name="chartObj"  >
    
            <lvc:CartesianChart.AxisX>
                <lvc:Axis MinValue="0"  MaxValue="{Binding MaxXAxisValue}" >
                    <lvc:Axis.Separator>
                       <lvc:Separator Stroke="Red"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX>
        </lvc:CartesianChart>