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一起工作,这是非常好的方向,非常感谢! –