LiveChart doesn't show all Labels on x-axis WPF

不打扰是莪最后的温柔 提交于 2020-01-04 02:53:28

问题


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


回答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 :)



来源:https://stackoverflow.com/questions/52909476/livechart-doesnt-show-all-labels-on-x-axis-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!