簡體   English   中英

如何使x軸忽略x值的順序?

[英]How to make the x-axis to ignore the order of the x values?

首先,如果我的英語不太好,我很抱歉......

我有4個數組(前2個用於#1系列),我想將它們綁定到我的圖表:

double[] yValues1 = { 65.62, 75.54, 60.45, 55.73, 70.42, 200 };
string[] xValues1 = { "France", "Canada", "UK", "USA", "Italy", "India" };
chart.Series["Series1"].Points.DataBindXY(xValues1, yValues1);

double[] yValues2 = { 65.62, 75.54, 60.45, 55.73, 200, 70.42 };
string[] xValues2 = { "France", "Canada", "UK", "USA", "India", "Italy"};
chart.Series["Series2"].Points.DataBindXY(xValues2, yValues2);

結果是(觀察:意大利和印度的價值觀和秩序):

正如你所看到的,印度兩個系列中都有200個,但是第二個系列中的200個指的是意大利(這是第一個系列中的第五個),好像它是按照第一個系列進行的。 簡而言之,我希望無論xValues的順序如何,都要顯示兩個系列,但是根據它們的字符串值。

順便說一句,我怎樣才能限制列的數量,即使我用長度更大的數組將圖表綁定到那個限制?

要完成此操作,請添加對AlignDataPointsByAxisLabel的調用:

Chart.AlignDataPointsByAxisLabel();

這將使所有數據點與相同的軸標簽對齊,無論它們綁定的順序如何。

xValue和yValue可以添加到SortedDictionary中。 這將使值和鍵保持配對。

chart1.Series.Add("Series1");
chart1.Series.Add("Series2");

SortedDictionary<string, double> sd1 = new SortedDictionary<string, double>();
SortedDictionary<string, double> sd2 = new SortedDictionary<string, double>();
sd1.Add("france", 65.52);
sd2.Add("france", 65.52);
sd1.Add("india", 200);
sd2.Add("italy", 40);
sd1.Add("italy", 50);
sd2.Add("india", 200);

chart1.Series["Series1"].Points.DataBindXY(sd1.Keys, sd1.Values);
chart1.Series["Series2"].Points.DataBindXY(sd2.Keys, sd2.Values);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM