无法调整图表保证金 [英] Can't Adjust Chart Margin

查看:80
本文介绍了无法调整图表保证金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个图表,但是它在Y.Axis和图表的边界之间有一个左边界.

I created a Chart but it has a left margin between the Y.Axis and the Chart's border.

如何将其设置为0?

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

And is it possible to define a 5px uniform margin (left, top, right, bottom) between the chart and the border?

我的图表代码如下:

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

You can remove the axis margin with Axis.IsMarginVisible = false.
You can position your charting areas using ChartArea.Position or position the plotting area using ChartArea.InnerPlotPosition

这篇关于无法调整图表保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆