LiveChart不在X轴WPF上显示所有标签 [英] LiveChart doesn't show all Labels on x-axis WPF

查看:1638
本文介绍了LiveChart不在X轴WPF上显示所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LiveChart并加载一些数据.

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; }  

,但我没有在x-axis上看到全部30个Labels.我已经提到了这些解决方案,但仍然存在相同的问题.
动态图表未在WPF中的x轴上显示标签
https://github.com/Live-Charts/Live-Charts/issues/481

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

推荐答案

我认为SeriesCollection未绑定到您的Chart.希望您将其绑定到LoadLineChart()方法内部的代码中.

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

由于没有为LoadLineChart()方法提供代码,因此我只是尝试如下向seriesCollection对象随机提供一些值,

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;**
          }

我想您可能缺少将seriesCollection绑定到LineChart的想法.但是,如果这样做仍然有其他问题,请更新您的评论.

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

这篇关于LiveChart不在X轴WPF上显示所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆