[英]LiveChart doesn't show all Labels on x-axis WPF
我正在使用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>
在后端我定義了標簽。
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
。 我已經提到了這些解決方案,但仍然是同樣的問題。
Livecharts 未在 WPF 中的 x 軸上顯示標簽
https://github.com/Live-Charts/Live-Charts/issues/481
我認為 SeriesCollection 不受您的圖表約束。 我希望您將它綁定到 LoadLineChart() 方法中的代碼隱藏中。
由於沒有為 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;**
}
我猜您可能沒有將 seriesCollection 綁定到您的 LineChart。 但是,如果您這樣做了,但仍有其他問題,請更新您的評論。
注意:- 我嘗試了一些條形圖,您可以嘗試使用您的圖表代碼。
希望這對你有幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.