3

Trying to plot some data on line chart. I am fetching data from Datbase and getting x-axis and y-axis values. Adding values in label of X-axis like below.

<wpf:CartesianChart Name="MonthlySalesLineChart" LegendLocation="Bottom" Margin="10" FontWeight="ExtraLight" Foreground="WhiteSmoke">
    <wpf:CartesianChart.DataTooltip>
        <wpf:DefaultTooltip BulletSize="20" Background="Black" Opacity="0.8" Foreground="White"/>
    </wpf:CartesianChart.DataTooltip>
</wpf:CartesianChart>  

Code Behind :

 private string[] _labelXAxis;
_labelXAxis = new string[_saleInvoiceList.Count];

for (int i = 0; i < _saleInvoiceList.Count; i++)
{
    _labelXAxis[i] = _saleInvoiceList[i].Date.ToString("M");
}  

and then assigning to chart like this.

MonthlySalesLineChart.AxisX.Add(new Axis
{
   Labels = _labelXAxis,
   // ShowLabels = true,
    Foreground = Brushes.White,
    Separator = new LiveCharts.Wpf.Separator
    {
        Step = 1,
    },
    Title = "Date"
   // LabelFormatter = value => value.ToString("M")
   // MinValue = 1,
});  

Now problem is if i turn on Separator then on x-axis both values are shown 0, 1,2,3,4,5... which i am not adding with my _labelXAxis values which are string type date.
But if i don't use separator then i don't see all my string dates on x-Axis instead only few. why ?

When separator is not implemented
enter image description here

When Separator is implemented
enter image description here

Hammas_Stack
  • 99
  • 1
  • 9

0 Answers0