GridLines
去DataPoints
和Labels
去GridLines
,但..
您可以設置Interval
和Minimum
爲X-Axis
分開來調整它們:
但有一些額外的需要注意的..
// get a reference
ChartArea chartArea1 = chart1.ChartAreas[0];
// don't start at 0
chartArea1.AxisX.IsStartedFromZero = false;
// pick your interval
double interval = 1D;
chartArea1.AxisX.MajorTickMark.Interval = interval;
// set minimum at the middle
chartArea1.AxisX.Minimum = interval/2d;
// pick a column width (optional)
chart1.Series[0].SetCustomProperty("PixelPointWidth", "30");
// we want the labels to sit with the points, not the grid lines..
// so we add custom labels for each point ranging between the grid lines..
for (int i = 0; i < chart1.Series[0].Points.Count; i++)
{
DataPoint dp = chart1.Series[0].Points[i];
chartArea1.AxisX.CustomLabels.Add((0.5d + i) * interval,
(1.5d + i) * interval, dp.XValue.ToString());
}
更新:
隨着更新的問題表明,你正在使用的數據綁定使用字符串作爲X值。這非常方便,但違背了Chart控件的核心本質。它的所有符號,無論是X-Value
還是任何Y-Values
都在內部存儲爲雙打。
隨機字符串不轉換爲加倍而你可以方便地與字符串添加DataPoints
爲X-Values
,醜陋的問題各種各樣拿出一個結果。
首先看看X-Values
自己:正如我所說的,他們是雙重的;當你檢查它們的值時,你會看到它們全都是0.字符串值在哪裏?它們被放置在標籤中。
有一個問題經常發現,您現在無法訪問X-Values
和value expressions。
另一個問題是,我們現在不能給範圍的x-Values
自定義標籤。
解決方案:如果我們需要自定義標籤,我們必須更改數據!
數據綁定是好的,只要確保爲您的數據源添加一個數字列包含一個月份號碼並將其設置爲該系列的XValueMember
!
您可以使該列在您的DataGridView
中不可見。
最後,您會希望像以前一樣創建自定義標籤;只需將其內容更改爲從包含月份名稱的字符串列中拉出即可。
下面是它看起來像在這裏:
來源
2015-09-06 17:26:25
TaW
更具體 – Arash
投入一些精力,如果面對任何問題,然後張貼在這裏。 –
您應該向我們展示如何添加'DataPoints'!他們的「X值」和「X值類型」是什麼? – TaW