1
我正在嘗試創建一個帶有軸標籤的條形圖,這些軸標籤左對齊並與繪圖有特定的距離。 軸標籤似乎既沒有對齊功能,也沒有可能插入填充。填充被忽略。有什麼能爲它的解決方案:條形圖軸標籤的左對齊
private void button1_Click(object sender, EventArgs e)
{
Chart chart1 = new Chart();
chart1.Size = new Size(600, 200);
Title mainTitle = new Title("BarChartX");
mainTitle.Alignment = ContentAlignment.TopLeft;
mainTitle.Font = new System.Drawing.Font("Arial", 11, FontStyle.Bold);
chart1.Titles.Add(mainTitle);
chart1.ChartAreas.Add(new ChartArea());
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Regular);
chart1.Series.Add("MySeries1").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
chart1.Series["MySeries1"].IsVisibleInLegend = false;
chart1.Series["MySeries1"].Color = Color.Red;
chart1.Series["MySeries1"].Points.AddXY(1, 1);
chart1.Series["MySeries1"]["PixelPointWidth"] = "30";
chart1.Series.Add("MySeries2").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
chart1.Series["MySeries2"].IsVisibleInLegend = false;
chart1.Series["MySeries2"].Color = Color.Red;
chart1.Series["MySeries2"].Points.AddXY(2, 2);
chart1.Series["MySeries2"]["PixelPointWidth"] = "30";
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisY.Interval = 2;
chart1.ChartAreas[0].AxisX.Maximum = 3;
chart1.ChartAreas[0].AxisY.Maximum = 6;
Font stringFont = new System.Drawing.Font("Arial", 10, FontStyle.Regular); /// !!!!!!!!!!!!
string Label1 = "AxisLabel1".PadRight(12);
chart1.ChartAreas[0].AxisX.CustomLabels.Add(0.5, 1.5, Label1);
string Label2 = "AxisLabel2";
chart1.ChartAreas[0].AxisX.CustomLabels.Add(1.5, 2.5, Label2);
flowLayoutPanel1.Controls.Add(chart1);
}[enter image description here][1]
感謝您的建議!我實際上無法使其工作: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> char space =(char)0xa0; chart1.ChartAreas [0] .AxisX.LabelStyle.Font = stringFont; string title1 =「AxisLabel1」; chart1.ChartAreas [0] .AxisX.CustomLabels.Add(0.25,0.75,title1.PadRight(12,space)); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>> 它仍然無視空間。除了字體之外,是否有任何設置需要更改? –
我相信沒有其他的設置.. - 你使用什麼字體?你應該在windows字符表工具中測試,看看你的字體是否真的包含這個特殊的空格字符!c Consolas的工作原理你可以看到。 – TaW
它與0x7F一起工作,這是非常好的方向,非常感謝! –