怎样在mschart的x轴上设置滚动条

zhouyangmgzx 2011-10-10 04:00:05
用mschart做了一个柱形图,但当数据过多时,柱形图会越来越细。如何在x轴上设置滚动条,这样柱形图就不会因为数据的增多而变形。我在chart属性里找到了chartarea--axis--dataview--scrollbar,但设置后没用。有没有前辈做过类似的东西,请不吝赐教!谢谢!!
...全文
419 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
z417784008 2014-05-29
顺便问下怎么给加上的滚动条换个样式?
回复
z417784008 2014-05-29
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = false; chart1.ChartAreas[0].AxisX.ScrollBar.Size = 20; chart1.ChartAreas[0].AxisX.ScaleView.Size = 10; chart1.ChartAreas[0].AxisX.ScaleView.MinSize = 1;
回复
tigertang123 2011-10-18
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)
' Process keyboard keys
If e.KeyCode = Keys.Right Then
' Set the new cursor position
chart1.ChartAreas("Default").CursorX.Position += chart1.ChartAreas("Default").CursorX.Interval

Else
If e.KeyCode = Keys.Left Then
' 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()

' Set the selection start variable in case shift arrows are selected
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position

' Reset the old selection start and end
chart1.ChartAreas("Default").CursorX.SelectionStart = Double.NaN
chart1.ChartAreas("Default").CursorX.SelectionEnd = Double.NaN
End Sub 'ProcessScroll


Private Sub Chart1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Chart1.KeyUp

If e.KeyCode = Keys.Right Or e.KeyCode = Keys.Left Then
' If the key event is shifted, process as a selection
If e.Shift Then
ProcessSelect(e)
' Process as a scroll
Else
ProcessScroll(e)
End If

' on enter, zoom the selection
Else
If e.KeyCode = Keys.Enter Then
Dim start, [end] As Double

If chart1.ChartAreas("Default").CursorX.SelectionStart > chart1.ChartAreas("Default").CursorX.SelectionEnd Then
start = chart1.ChartAreas("Default").CursorX.SelectionEnd
[end] = chart1.ChartAreas("Default").CursorX.SelectionStart
Else
[end] = chart1.ChartAreas("Default").CursorX.SelectionEnd
start = chart1.ChartAreas("Default").CursorX.SelectionStart
End If

' Return if no selection actually made
If start = [end] Then
Return
End If
' Zoom the selection
chart1.ChartAreas("Default").AxisX.ScaleView.Zoom(start, [end] - start, DateTimeIntervalType.Number, True)

' Reset selection values
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position
chart1.ChartAreas("Default").CursorX.SelectionStart = Double.NaN
chart1.ChartAreas("Default").CursorX.SelectionEnd = Double.NaN


Else
If e.KeyCode = Keys.Back Then
' Reset zoom back to previous view state
chart1.ChartAreas("Default").AxisX.ScaleView.ZoomReset(1)

' Reset selection values
Me.SelectionStart = chart1.ChartAreas("Default").CursorX.Position
chart1.ChartAreas("Default").CursorX.SelectionStart = Double.NaN
chart1.ChartAreas("Default").CursorX.SelectionEnd = Double.NaN
End If
End If
End If
End Sub 'chart1_KeyUp

回复
tigertang123 2011-10-18
设置可视区域 的起始、结束位置
回复
相关推荐
发帖
图表区
创建于2007-09-28

4810

社区成员

.NET技术 图表区
申请成为版主
帖子事件
创建了帖子
2011-10-10 04:00
社区公告
暂无公告