C# 图表对齐轴标签

C# Chart alignment axis label

我在柱形图中有一些自定义标签(我的一些代码):

        chart.ChartAreas[0].AxisX.IsMarginVisible = true;
        chart.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = true;
        chart.ChartAreas[0].AxisX.LineColor = Color.LightGray;
        chart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
        chart.ChartAreas[0].AxisX.LabelStyle.Angle = 0;
        chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Trebuchet MS", 10);
        chart.ChartAreas[0].AxisX.MajorTickMark.LineColor = Color.LightGray;

        chart.ChartAreas[0].AxisX.Interval = 1;
        chart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Weeks;
        chart.ChartAreas[0].AxisX.IsLabelAutoFit = true;
        chart.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false;


        DateTime minDate = DateTime.Parse(dt.Rows[0]["Date"].ToString());
        DateTime maxDate = DateTime.Parse(dt.Rows[dt.Rows.Count - 1]["Date"].ToString());

        for (int i = 0; i < dt.Rows.Count - 1; i++)
        {
            chart.ChartAreas[0].AxisX.CustomLabels.Add(new CustomLabel(minDate.ToOADate(),
                                                                       minDate.AddDays(6).ToOADate(),
                                                                       minDate.ToShortDateString() + "-" + minDate.AddDays(6).ToShortDateString(),
                                                                       0,
                                                                       LabelMarkStyle.None));
            minDate = minDate.AddDays(7);
        }

因为我的自定义标签文本太长了 minDate.ToShortDateString() + "-" + minDate.AddDays(6).ToShortDateString() 它看起来像

我怎样才能移动到左轴标签?

除了缩短内容以避免任何冗余之外,您还可以尝试通过在右侧添加几个空格、然后是 non-breaking space 和 \n.

来欺骗标签格式化程序

前后结果如下:

我用过这个代码:

  A.AxisX.LabelStyle.Format = "MM.dd.yy";
  A.AxisX.LabelStyle.Format = "MM.dd.yy        " + ((char)160) + "\n";