|
Zoom in X-Axis got wrong scale |
Posted by wade on Apr-14-2011 19:18 |
|
Dear Peter,
I try to zoom in chart. the Y-Axis displays correctly. But X-Axis display incorrectly. What should I do to fix this problem?
|
Re: Zoom in X-Axis got wrong scale |
Posted by Peter Kwan on Apr-15-2011 01:55 |
|
Hi wade,
Would you mind to inform me the charting part of your code? I would need to know the code that you use to set up the x-axis.
Regards
Peter Kwan |
Re: Zoom in X-Axis got wrong scale |
Posted by wade on Apr-15-2011 08:26 |
|
Here is my code of charting part:
Private Sub Print_IV_Chart(ByVal labels() As Double, ByVal data1() As Double, ByVal data2() As Double, ByVal data3() As Double, ByVal data4() As Double, ByVal data5() As Double)
WinChartViewer1.Visible = True
' Create an XYChart object of size 600 x 300 pixels, with a light blue
' (EEEEFF) background, black border, 1 pxiel 3D border effect and rounded
' corners
Dim c As XYChart = New XYChart(560, 330, &HEEEEFF, &H0, 0)
c.setRoundedFrame()
' Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white
' background. Turn on both horizontal and vertical grid lines with light grey
' color (0xcccccc)
c.setPlotArea(55, 20, 480, 260, &HFFFFFF, -1, -1, &HCCCCCC, &HCCCCCC)
c.setClipping()
c.setRoundedFrame(&HC0C0FF)
' Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use
' 9 pts Arial Bold font. Set the background and border color to Transparent.
'c.addLegend(50, 30, False, "Arial Bold", 9).setBackground(Chart.Transparent)
' Add a title box to the chart using 15 pts Times Bold Italic font, on a
' light blue (CCCCFF) background with glass effect. white (0xffffff) on a
' dark red (0x800000) background, with a 1 pixel 3D border.
'c.addTitle("Application Server Throughput", "Times New Roman Bold Italic", 15).setBackground(&HCCCCFF, &H0, Chart.glassEffect())
' Add a title to the y axis
c.yAxis().setTitle("I", "Arial Bold", 12, &HFF).setFontAngle(0)
c.yAxis.setAutoScale(0.05, 0.05, 1)
' Set the labels on the x axis.
c.xAxis().setLabels(labels).setFontAngle(90)
' Display 1 out of 3 labels on the x-axis.
c.xAxis().setLabelStep(IV_Sample_Point / 20)
' Add a title to the x axis
c.xAxis().setTitle("V", "Arial Bold", 12, &HFF)
'c.swapXY(True)
' Add a line layer to the chart
Dim layer As LineLayer = c.addLineLayer2()
' Set the default line width to 2 pixels
layer.setLineWidth(2)
' Add the three data sets to the line layer. For demo purpose, we use a dash
' line color for the last line
If CH1_ENABLE.Checked = True Then
layer.addDataSet(data1, &HFF0000, "CH1")
End If
If CH2_ENABLE.Checked = True Then
layer.addDataSet(data2, &HFFFF00, "CH2")
End If
If CH3_ENABLE.Checked = True Then
layer.addDataSet(data3, &HFF, "CH3")
End If
If CH4_ENABLE.Checked = True Then
layer.addDataSet(data4, &H0, "CH4")
End If
If CH5_ENABLE.Checked = True Then
layer.addDataSet(data5, &HFF00, "CH5")
End If
' Explicitly auto-scale axes so we can get the axis scales
If data1(IV_Sample_Point - 1) = Chart.NoValue Then
Dim asda As Integer = 123
ElseIf maxX = minX Then
' The axis scale has not yet been set up. So this is the first time the chart is
' drawn and it is drawn with no zooming. We can use auto-scaling to determine the
' axis-scales, then remember them for future use.
' Explicitly auto-scale axes so we can get the axis scales
c.layout()
' Save the axis scales for future use
minX = c.xAxis().getMinValue()
maxX = c.xAxis().getMaxValue()
minY = c.yAxis().getMinValue()
maxY = c.yAxis().getMaxValue()
Else
' Compute the zoomed-in axis scales using the overall axis scales and ViewPort size
Dim xScaleMin As Double = minX + (maxX - minX) * WinChartViewer1.ViewPortLeft
Dim xScaleMax As Double = minX + (maxX - minX) * (WinChartViewer1.ViewPortLeft + _
WinChartViewer1.ViewPortWidth)
Dim yScaleMin As Double = maxY - (maxY - minY) * (WinChartViewer1.ViewPortTop + _
WinChartViewer1.ViewPortHeight)
Dim yScaleMax As Double = maxY - (maxY - minY) * WinChartViewer1.ViewPortTop
' *** use the following formula if you are using a log scale axis ***
' Dim xScaleMin As Double = minX * Math.Pow(maxX / minX, viewer.ViewPortLeft)
' Dim xScaleMax As Double = minX * Math.Pow(maxX / minX, viewer.ViewPortLeft + _
' viewer.ViewPortWidth)
' Dim yScaleMin As Double = maxY * Math.Pow(minY / maxY, viewer.ViewPortTop + _
' viewer.ViewPortHeight)
' Dim yScaleMax As Double = maxY * Math.Pow(minY / maxY, viewer.ViewPortTop)
' Set the axis scales
c.xAxis().setLinearScale(xScaleMin, xScaleMax)
c.xAxis().setRounding(False, False)
c.yAxis().setLinearScale(yScaleMin, yScaleMax)
c.yAxis().setRounding(False, False)
End If
WinChartViewer1.Chart = c
'WinChartViewer1.MouseUsage = WinChartMouseUsage.ZoomIn
' output the chart
'WinChartViewer1.Image = c.makeImage()
'include tool tip for the chart
'WinChartViewer1.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] I:{xLabel} V:{value} '")
End Sub |
Re: Zoom in X-Axis got wrong scale |
Posted by Peter Kwan on Apr-15-2011 16:59 |
|
Hi wade,
In your case, your code sets the labels on the x-axis (using Axis.setLabels). Then the zooming code also sets the x-axis labels. This causes the issue you see.
To solve the problem, instead of setting the x-axis labels, you may inform ChartDirector they are the x-coordinates of your data, and let the zooming code to automatically set the x-axis labels based on the actual visible axis range. To do this, please remove the following lines:
' Set the labels on the x axis.
c.xAxis().setLabels(labels).setFontAngle(90)
' Display 1 out of 3 labels on the x-axis.
c.xAxis().setLabelStep(IV_Sample_Point / 20)
then add the following lines:
c.xAxis().setLabelStyle("Arial", 8, &H000000, 90)
layer.setXData(labels)
'I assume the followings is how you would like the x-axis to auto-scale. If this
'is not the case, you may remove these two lines
c.xAxis().setRounding(false, false)
c.xAxis().setAutoScale(0, 0, 0)
Hope this can help.
Regards
Peter Kwan |
Re: Zoom in X-Axis got wrong scale |
Posted by wade on Apr-15-2011 18:14 |
|
Hi Peter,
It's Work! Thanks for your help. |
|