我试图以50的间隔设置标记.MainGrid工作正常,但我找不到任何方法让yAxis的标记与主网格的网格线对齐。目前我正在使用它:
chart.ChartAreas.Add(new ChartArea("statistic")
{
AxisX = ...
AxisY = new Axis
{
MajorGrid =
new Grid
{
Enabled = true,
LineColor = Color.Black,
LineDashStyle = ChartDashStyle.Solid,
Interval = 50,
IntervalOffset = 0
},
Title = yAxisDesc,
Minimum = yAxisRange.Item1,
Maximum = yAxisRange.Item2
}
}
得到这个:
我尝试修改MajorTickMark无济于事。
我需要改变什么?
答案 0 :(得分:1)
试试这个:
private void Form1_Load(object sender, EventArgs e)
{
int xmax = 100;
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 50;
chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 50;
chart1.ChartAreas[0].AxisY.LabelStyle.Interval = 50;
for (int x = 1; x < xmax; x++)
chart1.Series[0].Points.AddXY(x, 5 * x);
}
答案 1 :(得分:0)
感谢jstreet, 我找到了以下解决方案:
AxisY =
new Axis
{
MajorGrid =
new Grid
{
Enabled = true,
LineColor = Color.Black,
LineDashStyle = ChartDashStyle.Solid,
Interval = 50,
IntervalOffset = 0
},
Title = yAxisDesc,
Minimum = yAxisRange.Item1,
Maximum = yAxisRange.Item2,
LabelStyle = new LabelStyle{Interval = 50, Enabled=true,IntervalOffset = 0,IsEndLabelVisible = true},
MajorTickMark =
new TickMark
{
Enabled = true,
Interval = 50,
IntervalOffset = 0,
},
}
但是,仅使用MajorTickMark或LabelStyle不会产生所需的图表。现在就是这样: