Search code examples
c#wpflivecharts

How to change DataLabels color by using LiveCharts


I am using Live Charts for Line chart and column chart. I have enable data labels function. But I use dark color as background. It make the data label look very obscure. I can't find where I can change the data labels color. Anyone know how to change it? enter image description here

in C#

        ProductionAndTargetCollection = new SeriesCollection
        {
            new LineSeries
            {
                Title = "Target",
                Values = DailyTargetValue,
                DataLabels = true,
                LineSmoothness = 0
            },
             new ColumnSeries
            {
                Title = "Production",
                DataLabels = true,
                Values = DailyProductionValue
            }
        };

in WPF

              <lvc:CartesianChart Name="MidRightChart" Series="{Binding ProductionAndTargetCollection}" DisableAnimations="True">
                <lvc:CartesianChart.AxisX>
                    <lvc:Axis LabelsRotation="0" Labels="{Binding ProductionAndTargetLabels}" Foreground="White" Position="LeftBottom">
                        <lvc:Axis.Separator >
                            <lvc:Separator Step="1"></lvc:Separator>
                        </lvc:Axis.Separator>
                    </lvc:Axis>
                </lvc:CartesianChart.AxisX>
                <lvc:CartesianChart.AxisY>
                    <lvc:Axis Foreground="White" MinValue="0"/>
                </lvc:CartesianChart.AxisY>
             </lvc:CartesianChart>

Solution

  • You should set the Foreground property of the Series to change the colour of the data labels:

    new ColumnSeries
    {
        Title = "Production",
        DataLabels = true,
        Values = DailyProductionValue,
        Foreground = Brushes.Red // <--
    }