margin - 无法调整图表边距

标签 margin mschart

我创建了一个图表,但它在 Y 轴和图表边框之间有一个左边距。

如何让它变成0?

是否可以在图表和边框之间定义一个 5px 的统一边距(左、上、右、下)?

我的图表代码如下:

Chart chart = new Chart {
  AntiAliasing = AntiAliasingStyles.All,
  TextAntiAliasingQuality = TextAntiAliasingQuality.High,
  BackColor = Color.FromArgb(250, 250, 250),
  Height = size.Height,
  Width = size.Width
};

chart.Legends.Clear();

ChartArea area = new ChartArea {
  BackColor = Color.Transparent,
  BorderColor = Color.FromArgb(240, 240, 240),
  BorderWidth = 1,
  BorderDashStyle = ChartDashStyle.Solid,
  AxisX = new Axis {
    Enabled = AxisEnabled.True,
    IntervalAutoMode = IntervalAutoMode.VariableCount,
    IsLabelAutoFit = true,
    IsMarginVisible = true,
    LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(100, 100, 100), Font = new Font("Arial", 10, FontStyle.Regular) },
    LineColor = Color.FromArgb(220, 220, 220),
    MajorGrid = new Grid { LineColor = Color.FromArgb(240, 240, 240), LineDashStyle = ChartDashStyle.Solid },
    MajorTickMark = new TickMark { LineColor = Color.FromArgb(220, 220, 220), Size = 4.0f },
  },
  AxisY = new Axis {
    Enabled = AxisEnabled.True,
    IntervalAutoMode = IntervalAutoMode.VariableCount,
    IsLabelAutoFit = true,
    IsMarginVisible = true,
    LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(100, 100, 100), Font = new Font("Arial", 10, FontStyle.Regular) },
    LineColor = Color.Transparent,
    MajorGrid = new Grid { LineColor = Color.FromArgb(240, 240, 240), LineDashStyle = ChartDashStyle.Solid },
    MajorTickMark = new TickMark { LineColor = Color.FromArgb(240, 240, 240), Size = 2.0f }
  },
  Position = new ElementPosition { Height = 100, Width = 100, X = 0, Y = 0 }
};

chart.ChartAreas.Add(area);

area.AxisX.LabelStyle.Format = "H:mm";
area.AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Hours;

Series series = new Series {
  CustomProperties = "PointWidth = 1",
  IsXValueIndexed = true,
  XValueType = (ChartValueType)Enum.Parse(typeof(ChartValueType), x.Data.GetType().GetGenericArguments()[0].Name)
};

series.BorderWidth = 2;
series.BorderColor = Color.FromArgb(84, 164, 232);
series.ChartType = SeriesChartType.Area;
series.Color = Color.FromArgb(222, 234, 244);

series.Points.DataBindXY(x.Data, s.Data);

chart.Series.Add(series);

谢谢你,

米格尔

最佳答案

您可以使用 Axis.IsMarginVisible = false 移除轴边距。
您可以使用 ChartArea.Position 定位图表区域或使用 ChartArea.InnerPlotPosition

定位绘图区域

关于margin - 无法调整图表边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12837247/

相关文章:

html - 负边距导致内容在缩放期间移动

c# - 如何在 .net 4 Chart 中更改字体颜色

c# - 散点图 'best-fit' 线的算法

Android包含标签不覆盖布局属性

html - 距中心的CSS边距

c# - 如何在饼图中的图例中设置不同的标签

c# - 如何让 WinForms 图表控制主 Y 轴绘制在图表的两边?

c# - 如何有条件地将数据点添加到使用 MSChart 呈现的图表中

objective-c - NSTextField 奇怪的左边距

html - 使用 margin 属性时出现奇怪的间距