2015-04-24 60 views
0

我是新來Asp.net圖表和正在開發一種線形圖,它看起來像:asp.net圖表:添加額外的點(Tick標識)X軸

enter image description here

X-的部分軸碼是:(評論已在代碼加)

Chart1.ChartAreas(0).AxisX.Title = "Age" 
    Chart1.ChartAreas(0).AxisX.LineWidth = 2 
    Chart1.ChartAreas(0).AxisX.Interval = 1 
    'Turn off X-axis lines 
    Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = False 
    ' Enable X axis margin 
    Chart1.ChartAreas(0).AxisX.IsMarginVisible = True 
    Chart1.ChartAreas(0).AxisX.IsStartedFromZero = True 
    Chart1.ChartAreas(0).AxisX.IsStartedFromZero = False 


    Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -60 
    Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Drawing.Font("Arial", 8, Drawing.FontStyle.Bold) 
    Chart1.ChartAreas(0).AxisX.MajorTickMark.Enabled = False 
    Chart1.ChartAreas(0).AxisX.IsStartedFromZero = True 


    'age() is array of Ages 
    'Estimated is array of estimated values in Dollars 
    'Real is array of real values in Dollars 
    s.ChartType = SeriesChartType.Line 
    g.ChartType = SeriesChartType.Line 
    s.BorderWidth = 2 
    g.BorderWidth = 2 

    Dim count As Integer = 0 
    'Finding the interval for X Axis 
    'Value of maxAge is 95 and myAge 55 
    Dim interval = (maxAge - myAge)/10 ' 
    Chart1.ChartAreas(0).AxisX.Minimum = myAge 
    'interval value is 4 
    Chart1.ChartAreas(0).AxisX.Interval = interval 

    'To start the graph from origin 

    g.Points.AddXY(Convert.ToInt32(myAge), 0) 
    s.Points.AddXY(Convert.ToInt32(myAge), 0) 
    'Adding the label for origin 
    Chart1.ChartAreas(0).AxisX.CustomLabels.Add(myAge - 1, myAge + 1, "Age " & myAge & " ") 
    count = 0 
    'This loop runs from 55 to 95 of age() Array 
    For i = 1 To 10 
     count += interval 
     s.Points.AddXY(age(count), Estimated(count)) 
     g.Points.AddXY(age(count), Real(count)) 
     Chart1.ChartAreas(0).AxisX.CustomLabels.Add(age(count) - 0.3, age(count), "Age " & age(count) & " ") 
    Next i 
    Chart1.Series.Add(s) 
    Chart1.Series.Add(g) 

和輸出到這個代碼是

enter image description here

問題是,儘管我的循環正好運行了10次,但在X軸上添加了一個額外的刻度標記。

所以我的問題是

有沒有辦法圖形限制,而不是採取額外的飛躍,到最後的刻度標記,?

在此先感謝

回答

0

我是新手到ASP.NET因此圖表,是使這個愚蠢的錯誤。

我不得不這樣設置

Chart1.ChartAreas(0).AxisX.Maximum = maxAge 

和賓果它的工作!該圖僅限於年齡95刻度標記。

相關問題