4

i am using LiveChart and loading some data.

<wpf:CartesianChart Name="LineChart" LegendLocation="top" >
<wpf:CartesianChart.AxisY>
    <wpf:Axis Title="Sales" ></wpf:Axis>
</wpf:CartesianChart.AxisY>
<wpf:CartesianChart.AxisX>
    <wpf:AxesCollection>
        <wpf:Axis Labels="{Binding Labels}">
            <wpf:Axis.Separator>
                <wpf:Separator Step="1" />
            </wpf:Axis.Separator>
        </wpf:Axis>
    </wpf:AxesCollection>
</wpf:CartesianChart.AxisX>


while on backend i have defined Labels.

public DailySalesProgressLineChart()
{
    InitializeComponent();
    Labels = new[]
                 {
                     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
                     26, 27, 28, 29, 30
                 };
    DataContext = this;
    LoadLineChart();
}  
SeriesCollection seriesCollection = new SeriesCollection();
public int[] Labels { get; set; }  

but i am not seeing all 30 Labels on x-axis. I have referred to these solutions but still same problem.
Livecharts not displaying Label on x axis in WPF
https://github.com/Live-Charts/Live-Charts/issues/481

enter image description here

Hammas_Stack1
  • 184
  • 1
  • 13
  • Can you paste code for "LoadLineChart();" method. I cannot see the chart, may be because I am missing this method definition. – G K Oct 21 '18 at 14:54

1 Answers1

1

I think the SeriesCollection is not bound to your Chart. I hope you are binding it in your code-behind inside LoadLineChart() method.

Since there is no code provided for LoadLineChart() method, I just tried randomly giving some values to seriesCollection object as below,

          private void LoadLineChart()
          {
              seriesCollection = new SeriesCollection
              {
                  new ColumnSeries
                  {
                      Title = "1988",
                      Values = new ChartValues<double> { 10, 50, 39, 50, 5, 10, 15, 20, 25, 30, 35, 40, 9, 18, 27, 36, 2, 4, 6, 8, 10, 12, 14,
  16, 3, 6, 9, 12, 14, 17, 21 }
                  }
              };

              //adding series will update and animate the chart automatically
              seriesCollection.Add(new ColumnSeries
              {
                  Title = "1989",
                  Values = new ChartValues<double> { 12, 71, 41, 21, 9, 6, 3, 61, 41, 21, 01, 8, 6, 4, 2, 63, 72, 81, 9, 04, 53, 03, 52, 02,
  51, 01, 5, 05, 93, 05, 01 }
              });

              **LineChart.Series = seriesCollection;**
          }

I guess you might be missing to bind the seriesCollection to your LineChart. But if you are doing so and still you have some other issue, then update your comments.

Note:- I tried with some bar-charts, you can try with your chart code.

Hope this helps you :)

G K
  • 2,481
  • 4
  • 29
  • 45
  • i accepted it as answer as you helped me ! but problem was that the labels must start from 0 to match my data input from database. and secondly input data was not reaching last label limit . like labels are 0,1,2....30. but data was only for 12 labels. when there is data that should be shown at 30th label. then then all the labels will be shown ! – Hammas_Stack1 Oct 23 '18 at 11:51
  • To understand your statement, let me break it like this - "labels must start from 0 to match my data input from database " - So its not starting from 0 in your actual code? " input data was not reaching last label limit" - What was your last label limit? Is it 30 in your case? Am I right? "when there is data that should be shown at 30th label. then then all the labels will be shown !" - My understanding is even though if you have less data, still you want to see all 30 labels? Are we on the same page? – G K Oct 23 '18 at 16:33
  • Was this statement in your xaml "" does n't work for you? I could see one thread on Github for LiveCharts project mentioned the same https://github.com/Live-Charts/Live-Charts/issues/481 – G K Oct 23 '18 at 16:35
  • If my understanding is that you want to see all labels all times, then this might helps you https://stackoverflow.com/questions/7566996/force-all-axis-labels-to-show – G K Oct 23 '18 at 16:37