简体   繁体   English

LiveChart 未在 x 轴 WPF 上显示所有标签

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

i am using LiveChart and loading some data.我正在使用LiveChart并加载一些数据。

<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 .但我没有在x-axis看到所有 30 个Labels I have referred to these solutions but still same problem.我已经提到了这些解决方案,但仍然是同样的问题。
Livecharts not displaying Label on x axis in WPF Livecharts 未在 WPF 中的 x 轴上显示标签
https://github.com/Live-Charts/Live-Charts/issues/481 https://github.com/Live-Charts/Live-Charts/issues/481

在此处输入图片说明

I think the SeriesCollection is not bound to your Chart.我认为 SeriesCollection 不受您的图表约束。 I hope you are binding it in your code-behind inside LoadLineChart() method.我希望您将它绑定到 LoadLineChart() 方法中的代码隐藏中。

Since there is no code provided for LoadLineChart() method, I just tried randomly giving some values to seriesCollection object as below,由于没有为 LoadLineChart() 方法提供代码,我只是尝试随机给 seriesCollection 对象提供一些值,如下所示,

          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.我猜您可能没有将 seriesCollection 绑定到您的 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 :)希望这对你有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM