|
How to change XYChart Y Axis Minimum Value and Maximum Value |
Posted by Raghu on Jan-03-2014 11:22 |
|
Hello Peter,
I want to make the Y Axis Scale configurable by user. How can I change Y Axis Minimum Value and Maximum Value?
Take "multiaxes.vb" for example, I add a MouseClick function to change YAxis scale by "setLinearScale". But there is no any change on YAxis Scale. Could you help? Thanks.
Private Sub WinChartViewer1_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles WinChartViewer1.Click
Dim viewer As WinChartViewer = sender
Dim c As XYChart = viewer.Chart
Dim layer As LineLayer
Dim result As DialogResult
Dim fAixs As DialogAxis = New DialogAxis()
If c.yAxis.getX - 75 < e.X And c.yAxis.getX - 45 > e.X Then
MessageBox.Show("Left Axis!")
End If
If c.yAxis.getX - 35 < e.X And c.yAxis.getX > e.X Then
fAixs.tbPyMin.Text = c.yAxis.getMinValue
fAixs.tbPyMax.Text = c.yAxis.getMaxValue
result = fAixs.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
c.yAxis().setLinearScale(fAixs.PyMin, fAixs.PyMax)
viewer.updateDisplay()
End If
End If
If c.yAxis2.getX < e.X And c.yAxis2.getX + 30 > e.X Then
MessageBox.Show("Axis 2!")
End If
If c.yAxis2.getX + 40 < e.X And c.yAxis2.getX + 75 > e.X Then
MessageBox.Show("Right Axis!")
End If
End Sub |
Re: How to change XYChart Y Axis Minimum Value and Maximum Value |
Posted by Peter Kwan on Jan-04-2014 03:43 |
|
Hi Raghu,
To change the chart, you need to redraw it. Assuming the subroutine that draws you chart is called "drawChart", the code should be like:
Dim useManualScale As Boolean
Private Sub WinChartViewer1_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles WinChartViewer1.Click
Dim viewer As WinChartViewer = sender
Dim c As XYChart = viewer.Chart
If c.yAxis.getX - 35 < e.X And c.yAxis.getX > e.X Then
useManualScale = True
drawChart()
End If
End Sub
In your drawChart subdrouinte, the code should be like:
Sub drawChart()
Dim c As XYChart = New XYChart(....)
.... create chart as usual ....
If useManualScale Then
c.yAxis().setLinearScale(fAixs.PyMin, fAixs.PyMax)
useManualScale = False
End If
WinChartViewer1.Chart = Chart
End Sub
Hope this can help.
Regards
Peter Kwan |
|