2016-05-17 111 views
3

我試圖在間隔爲50的tickmarks。MajorGrid工作正常,但我找不到任何方法來獲取yAxis的tickmarks對齊到majorgrid的網格線。目前我使用此:如何設置tickmarks的時間間隔?

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 
    } 
} 

得到這個:

Current result lacking alignment of ticks to grid.

我試圖修改MajorTickMark無濟於事。

我必須改變什麼?

+0

您發佈的代碼並不顯示爲'MajorTickMark'任何更改。應該有類似'chartArea.AxisY.MajorTickMark.Interval = 50;' – jsanalytics

+0

此外,您可能還需要'chartArea.AxisY.LabelStyle.Interval = 50'。 – jsanalytics

+0

Thx @jstreet,這已經成功了 – Sebastian

回答

0

試試這個:

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); 
    } 

enter image description here

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不會導致所期望的圖表英寸這是現在:

desired alignment of ticks and grid