用mschart做了一个柱形图,但当数据过多时,柱形图会越来越细。如何在x轴上设置滚动条,这样柱形图就不会因为数据的增多而变形。我在chart属性里找到了chartarea--axis--dataview--scrollbar,但设置后没用。有没有前辈做过类似的东西,请不吝赐教!谢谢!!
------解决方案--------------------
设置可视区域 的起始、结束位置
------解决方案--------------------
MSChart demo里面有事例,例如:
Imports System.Windows.Forms.DataVisualization.Charting
...
Private SelectionStart As Double = Double.NaN
...
Protected Overrides Function ProcessDialogKey(keyData As Keys) As Boolean
' Avoid dialog processing of arrow keys
If keyData = Keys.Left Or keyData = Keys.Right Then
Return False
End If
Return MyBase.ProcessDialogKey(keyData)
End Function 'ProcessDialogKey
Private Sub Chart1_Click(sender As Object, e As System.EventArgs) Handles Chart1.Click
' Set input focus to the chart control
chart1.Focus()
' Set the selection start variable to that of the current position
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position
End Sub 'chart1_Click
Private Sub ProcessSelect(e As System.Windows.Forms.KeyEventArgs)
' Process keyboard keys
If e.KeyCode = Keys.Right Then
' Make sure the selection start value is assigned
If Me.SelectionStart = Double.NaN Then
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position
End If
' Set the new cursor position
chart1.ChartAreas("Default").CursorX.Position += chart1.ChartAreas("Default").CursorX.Interval
Else
If e.KeyCode = Keys.Left Then
' Make sure the selection start value is assigned
If Me.SelectionStart = Double.NaN Then
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position
End If
' Set the new cursor position
chart1.ChartAreas("Default").CursorX.Position -= chart1.ChartAreas("Default").CursorX.Interval
End If
End If
' If the cursor is outside the view, set the view
' so that the cursor can be seen
SetView()
chart1.ChartAreas("Default").CursorX.SelectionStart = Me.SelectionStart
chart1.ChartAreas("Default").CursorX.SelectionEnd = chart1.ChartAreas("Default").CursorX.Position
End Sub 'ProcessSelect
Private Sub SetView()
' Keep the cursor from leaving the max and min axis points
If chart1.ChartAreas("Default").CursorX.Position < 0 Then
chart1.ChartAreas("Default").CursorX.Position = 0
Else
If chart1.ChartAreas("Default").CursorX.Position > 75 Then
chart1.ChartAreas("Default").CursorX.Position = 75
End If
End If
' Move the view to keep the cursor visible
If chart1.ChartAreas("Default").CursorX.Position < chart1.ChartAreas("Default").AxisX.ScaleView.Position Then
chart1.ChartAreas("Default").AxisX.ScaleView.Position = chart1.ChartAreas("Default").CursorX.Position
Else
If chart1.ChartAreas("Default").CursorX.Position > chart1.ChartAreas("Default").AxisX.ScaleView.Position + chart1.ChartAreas("Default").AxisX.ScaleView.Size Then
chart1.ChartAreas("Default").AxisX.ScaleView.Position = chart1.ChartAreas("Default").CursorX.Position - chart1.ChartAreas("Default").AxisX.ScaleView.Size
End If
End If
End Sub 'SetView
Private Sub ProcessScroll(e As System.Windows.Forms.KeyEventArgs)