Author |
Topic |
|
guyguy2003
10 Posts |
Posted - 10 Mar 2008 : 21:48:55
|
Dear Sir/Madam
I have used your code example for MultiAxes for an XY plot I was requrested to make. It works fine with the dummy data created in the example. however when i used my own data (loading it from a file into arrays of x and y's) the axes stay at the same place, even when using yAxisList(yname).SetAxisIntercept((graphNum - 1) * -18). I am not sure why is this happening! anyone has an idea? I know its not the order of the drawing of the graph, etc - I have used the example and changed only the arrays it is getting and the result was the same.
Anyone knows why is it happening? is it some sort of a bug?
Cheers
Guy Rotenberg Department of Natural Resources and Water, QLD Australia
|
|
quinncurtis
1586 Posts |
Posted - 10 Mar 2008 : 22:29:22
|
Sorry, but based on the information provided we do not have any suggestions, other than there is a 100% probability that it is a programming error and not a bug.
What is the range of the x-values in your data ? What is the scaled range that the x-axis shows in the graph ?
Exactly how does the calculation yAxisList(yname).SetAxisIntercept((graphNum - 1) * -18) relate to the range of the x-values?
|
|
|
guyguy2003
10 Posts |
Posted - 10 Mar 2008 : 23:52:57
|
I'll pass some code.
This is the InitilizeChart which is exactly the same as in the example but for thos things : 1. only for two y axes instead of 5, and 2. reads the datasets from a seperate class (which i'll put in after this piece of code)
Private Sub InitializeChart() myDatasetList.LoadDatasetsFromFile("") If Not deleter Then Dim chartVu As ChartView = Me pTransform1 = New CartesianCoordinates(ChartObj.LINEAR_SCALE, ChartObj.LINEAR_SCALE) pTransform2 = New CartesianCoordinates(ChartObj.LINEAR_SCALE, ChartObj.LINEAR_SCALE)
Dim theFont As Font Dim numPoints As Integer = 100 Dim x1(numPoints - 1) As Double Dim y1(numPoints - 1) As Double Dim y2(numPoints - 1) As Double
Dim i As Integer
x1(0) = 1 y1(0) = 1000 y2(0) = 1000.0
For i = 1 To numPoints - 1 x1(i) = CDbl(i * i) y1(i) = y1((i - 1)) + 400.0 * (0.55 - ChartSupport.GetRandomDouble()) y2(i) = y2((i - 1)) + 190.0 * (0.45 - ChartSupport.GetRandomDouble())
Next i
theFont = New Font("Microsoft Sans Serif", 10, FontStyle.Bold) Dataset1 = New SimpleDataset("Second", x1, y2, 0.5, 0.0) Dataset2 = myDatasetList.AllQCDatasets(0)
pTransform1.AutoScale(Dataset1, ChartObj.AUTOAXES_FAR, ChartObj.AUTOAXES_FAR) pTransform2.AutoScale(Dataset2, ChartObj.AUTOAXES_FAR, ChartObj.AUTOAXES_FAR)
pTransform1.SetGraphBorderDiagonal(0.35, 0.15, 0.9, 0.65) pTransform2.SetGraphBorderDiagonal(0.35, 0.15, 0.9, 0.65)
Dim background As New Background(pTransform1, ChartObj.GRAPH_BACKGROUND, Color.White) chartVu.AddChartObject(background)
Dim plotbackground As New Background(pTransform1, ChartObj.PLOT_BACKGROUND, Color.White) chartVu.AddChartObject(plotbackground)
Dim attrib1 As New ChartAttribute(Color.Blue, 2, DashStyle.Solid) Dim attrib2 As New ChartAttribute(Color.Red, 2, DashStyle.Solid)
xAxis = New LinearAxis(pTransform1, ChartObj.X_AXIS) xAxis.SetLineWidth(2) chartVu.AddChartObject(xAxis)
yAxis1 = New LinearAxis(pTransform1, ChartObj.Y_AXIS) yAxis1.SetAxisIntercept(0.0) yAxis1.SetChartObjAttributes(attrib1) ' axis color matches line color chartVu.AddChartObject(yAxis1)
yAxis2 = New LinearAxis(pTransform2, ChartObj.Y_AXIS) yAxis2.SetAxisIntercept(-18) yAxis2.SetChartObjAttributes(attrib2) ' axis color matches line color chartVu.AddChartObject(yAxis2)
Dim xAxisLab As New NumericAxisLabels(xAxis) xAxisLab.SetTextFont(theFont) chartVu.AddChartObject(xAxisLab)
Dim yAxisLab1 As New NumericAxisLabels(yAxis1) yAxisLab1.SetTextFont(theFont) yAxisLab1.SetAxisLabelsFormat(ChartObj.BUSINESSFORMAT) chartVu.AddChartObject(yAxisLab1)
Dim yAxisLab2 As New NumericAxisLabels(yAxis2) yAxisLab2.SetTextFont(theFont) chartVu.AddChartObject(yAxisLab2)
Dim axisTitleFont As New Font("Microsoft Sans Serif", 10, FontStyle.Bold) Dim xaxistitle As New AxisTitle(xAxis, axisTitleFont, "Event Partition") chartVu.AddChartObject(xaxistitle)
Dim xgrid As New Grid(xAxis, yAxis1, ChartObj.X_AXIS, ChartObj.GRID_MAJOR) chartVu.AddChartObject(xgrid)
Dim thePlot1 As New SimpleLinePlot(pTransform1, Dataset1, attrib1) chartVu.AddChartObject(thePlot1)
Dim thePlot2 As New SimpleLinePlot(pTransform2, Dataset2, attrib2) chartVu.AddChartObject(thePlot2)
Dim theTitleFont As New Font("Microsoft Sans Serif", 14, FontStyle.Bold) Dim mainTitle As New ChartTitle(theTitleFont, "Widget Tolerances by Worker") mainTitle.SetTitleType(ChartObj.CHART_HEADER) mainTitle.SetTitlePosition(ChartObj.CENTER_GRAPH)
chartVu.AddChartObject(mainTitle)
Dim theSubheadFont As New Font("Microsoft Sans Serif", 10, FontStyle.Bold) Dim localTitle As New ChartTitle(pTransform1, theSubheadFont, "Click on one of the buttons below to change the x-axis range.") localTitle.SetTitleType(ChartObj.CHART_SUBHEAD) localTitle.SetTitlePosition(ChartObj.CENTER_PLOT) localTitle.ImplicitZValue = 1.0 localTitle.SetColor(Color.Black) chartVu.AddChartObject(localTitle)
Dim theFooterFont As New Font("Microsoft Sans Serif", 10, FontStyle.Bold) Dim footer As New ChartTitle(theFooterFont, "Graphs can have an UNLIMITED number of x- and y-axes.") footer.SetTitleType(ChartObj.CHART_FOOTER) footer.SetTitlePosition(ChartObj.CENTER_GRAPH) footer.SetTitleOffset(8) chartVu.AddChartObject(footer)
' Uses sll defaults for data tooltip Dim datatooltip As New DataToolTip(chartVu) datatooltip.SetEnable(True) chartVu.SetCurrentMouseListener(datatooltip)
Dim protate As New Point3D(10, 20, 0) pTransform1.AbsRotateCoordinateSystem(protate) pTransform2.AbsRotateCoordinateSystem(protate)
chartVu.SetFractionalZViewportDepth(0.1)
Dim transforms As PhysicalCoordinates() = {pTransform1, pTransform2} Dim rotatebutton As New RotateButtonUserControl(transforms) rotatebutton.Size = New Size(32, 32) rotatebutton.Location = New Point(8, 8) chartVu.Controls.Add(rotatebutton) End If End Sub 'InitializeChart '
This is the class:
Imports System.Drawing.Drawing2D Imports com.quinncurtis.chart3dnet Imports System.Drawing.Imaging Imports System.Windows.Forms Imports System.Data Imports System Imports System.IO Imports System.Collections.Generic
Public Class XYPlotDatasets Public xer() As Double Public yer() As Double Dim _allQCDatasets As New Dictionary(Of String, SimpleDataset) Dim _selectedQCDatasets As New Dictionary(Of String, SimpleDataset) Dim _listOfDataCollections As New List(Of String) Dim _listOfXParams As New List(Of String) Dim _listOfYParams As New List(Of String) Public Property ListOfDataCollections() As List(Of String) Get Return _listOfDataCollections End Get Set(ByVal value As List(Of String)) _listOfDataCollections = value End Set End Property Public Property ListOfXParams() As List(Of String) Get Return _listOfXParams End Get Set(ByVal value As List(Of String)) _listOfXParams = value End Set End Property Public Property ListOfYParams() As List(Of String) Get Return _listOfYParams End Get Set(ByVal value As List(Of String)) _listOfYParams = value End Set End Property
Public Property AllQCDatasets() As Dictionary(Of String, SimpleDataset) Get Return _allQCDatasets End Get Set(ByVal value As Dictionary(Of String, SimpleDataset)) _allQCDatasets = value End Set End Property Public Property SelectedQCDatasets() As Dictionary(Of String, SimpleDataset) Get Return _selectedQCDatasets End Get Set(ByVal value As Dictionary(Of String, SimpleDataset)) _selectedQCDatasets = value End Set End Property Public Sub ReadHeaderAndDatasets(ByVal sr As StreamReader) Dim buffer() As String Dim xAxes As New List(Of String) Dim yAxes As New List(Of String)
Dim DSName As String Dim i, t As Integer
'Dim x1(100 - 1) As Double 'x1(0) = 1 ''y1(0) = 1000 ''y2(0) = 1000.0
'For i = 1 To 99 ' x1(i) = CDbl(0.01 + i) ' 'y1(i) = y1((i - 1)) + 400.0 * (0.55 - ChartSupport.GetRandomDouble()) ' 'y2(i) = y2((i - 1)) + 190.0 * (0.45 - ChartSupport.GetRandomDouble())
'Next i Dim Elements() As String Try DSName = sr.ReadLine() _listOfDataCollections.Add(DSName) Elements = Split(sr.ReadLine) Dim xData(Elements(1)) As List(Of Double) Dim yData(Elements(2)) As List(Of Double)
For i = 0 To Elements(1) - 1 _listOfXParams.Add(sr.ReadLine()) xData(i) = New List(Of Double) 'xData.Add(New List(Of Double)) Next 'Dim xData() As List(Of Double) 'Dim yData() As List(Of Double) For i = 0 To Elements(2) - 1 _listOfYParams.Add(sr.ReadLine()) yData(i) = New List(Of Double) Next For i = 0 To Elements(3) - 1 buffer = Split(sr.ReadLine, " ") For t = 0 To Elements(1) - 1 xData(t).Add(CType(buffer(t + 1), Double)) Next For t = 0 To Elements(2) - 1 yData(t).Add(CType(buffer(Elements(1) + t + 1), Double)) Next Next For i = 0 To Elements(1) - 1 For t = 0 To Elements(2) - 1
xer = xData(i).ToArray yer = yData(t).ToArray _allQCDatasets.Add(t, New XYPlotDataset(t, xer, yer, 0.5, 0.0)) Next Next '_allQCDatasets.Add("DS1Par1ParX", New XYPlotDataset("DS1Par1ParX", x1, y1, 0.5, 0.0)) Catch ex As Exception
End Try End Sub Public Sub LoadDatasetsFromFile(ByVal dir As String) 'Mock up currently
Dim dinfo As DirectoryInfo = New DirectoryInfo("D:\projects\WonderGraphPro") 'DirectoryInfo dinfo = new DirectoryInfo(completeDirPath); Dim finfo As FileInfo() = dinfo.GetFiles("*.DAT") 'FileInfo[] finfo = dinfo.GetFiles(strExtension);
Dim fs As FileStream = File.OpenRead(finfo(0).FullName) Dim sr As New StreamReader(fs)
Try
ReadHeaderAndDatasets(sr)
Catch ex As Exception Finally sr.Close() fs.Close() End Try
End Sub End Class
And the file data is :
Infection Risk vs Ingested Dose for each Pathogen 0 1 3 100 1 1 0 No._Microbes_Ingested Helminth[No.Infections/10000_Persons] PolioVirus3[No.Infections/10000_Persons] Salmonella[No.Infections/10000_Persons] 0.1000E+01 0.4659E+02 0.2847E+04 0.2348E+02 0.1200E+01 0.5588E+02 0.3151E+04 0.2815E+02 0.1440E+01 0.6702E+02 0.3463E+04 0.3374E+02 0.1728E+01 0.8037E+02 0.3780E+04 0.4043E+02 0.2074E+01 0.9637E+02 0.4099E+04 0.4844E+02 0.2488E+01 0.1155E+03 0.4417E+04 0.5801E+02 0.2986E+01 0.1385E+03 0.4731E+04 0.6945E+02 0.3583E+01 0.1659E+03 0.5038E+04 0.8311E+02 0.4300E+01 0.1988E+03 0.5337E+04 0.9940E+02 0.5160E+01 0.2381E+03 0.5625E+04 0.1188E+03 0.6192E+01 0.2850E+03 0.5902E+04 0.1419E+03 0.7430E+01 0.3410E+03 0.6167E+04 0.1693E+03 0.8916E+01 0.4078E+03 0.6419E+04 0.2018E+03 0.1070E+02 0.4874E+03 0.6658E+04 0.2403E+03 0.1284E+02 0.5820E+03 0.6883E+04 0.2856E+03 0.1541E+02 0.6942E+03 0.7096E+04 0.3389E+03 0.1849E+02 0.8272E+03 0.7295E+04 0.4013E+03 0.2219E+02 0.9842E+03 0.7483E+04 0.4742E+03 0.2662E+02 0.1169E+04 0.7658E+04 0.5587E+03 0.3195E+02 0.1386E+04 0.7822E+04 0.6562E+03 0.3834E+02 0.1639E+04 0.7975E+04 0.7681E+03 0.4601E+02 0.1933E+04 0.8118E+04 0.8956E+03 0.5521E+02 0.2273E+04 0.8251E+04 0.1040E+04 0.6625E+02 0.2661E+04 0.8375E+04 0.1201E+04 0.7950E+02 0.3101E+04 0.8491E+04 0.1380E+04 0.9540E+02 0.3595E+04 0.8599E+04 0.1577E+04 0.1145E+03 0.4141E+04 0.8698E+04 0.1791E+04 0.1374E+03 0.4735E+04 0.8791E+04 0.2021E+04 0.1648E+03 0.5369E+04 0.8878E+04 0.2266E+04 0.1978E+03 0.6030E+04 0.8958E+04 0.2523E+04 0.2374E+03 0.6700E+04 0.9033E+04 0.2792E+04 0.2849E+03 0.7356E+04 0.9102E+04 0.3068E+04 0.3418E+03 0.7974E+04 0.9166E+04 0.3350E+04 0.4102E+03 0.8527E+04 0.9226E+04 0.3635E+04 0.4922E+03 0.8996E+04 0.9282E+04 0.3921E+04 0.5907E+03 0.9366E+04 0.9333E+04 0.4204E+04 0.7088E+03 0.9635E+04 0.9381E+04 0.4484E+04 0.8506E+03 0.9812E+04 0.9426E+04 0.4758E+04 0.1021E+04 0.9915E+04 0.9467E+04 0.5025E+04 0.1225E+04 0.9967E+04 0.9505E+04 0.5284E+04 0.1470E+04 0.9990E+04 0.9541E+04 0.5534E+04 0.1764E+04 0.9997E+04 0.9574E+04 0.5775E+04 0.2116E+04 0.9999E+04 0.9604E+04 0.6005E+04 0.2540E+04 0.1000E+05 0.9633E+04 0.6226E+04 0.3048E+04 0.1000E+05 0.9659E+04 0.6436E+04 0.3657E+04 0.1000E+05 0.9684E+04 0.6636E+04 0.4389E+04 0.1000E+05 0.9706E+04 0.6826E+04 0.5266E+04 0.1000E+05 0.9727E+04 0.7006E+04 0.6320E+04 0.1000E+05 0.9747E+04 0.7177E+04 0.7584E+04 0.1000E+05 0.9765E+04 0.7338E+04 0.9100E+04 0.1000E+05 0.9782E+04 0.7491E+04 0.1092E+05 0.1000E+05 0.9798E+04 0.7636E+04 0.1310E+05 0.1000E+05 0.9812E+04 0.7772E+04 0.1573E+05 0.1000E+05 0.9826E+04 0.7901E+04 0.1887E+05 0.1000E+05 0.9838E+04 0.8023E+04 0.2264E+05 0.1000E+05 0.9850E+04 0.8137E+04 0.2717E+05 0.1000E+05 0.9861E+04 0.8246E+04 0.3261E+05 0.1000E+05 0.9871E+04 0.8348E+04 0.3913E+05 0.1000E+05 0.9880E+04 0.8444E+04 0.4696E+05 0.1000E+05 0.9889E+04 0.8534E+04 0.5635E+05 0.1000E+05 0.9897E+04 0.8620E+04 0.6762E+05 0.1000E+05 0.9904E+04 0.8700E+04 0.8114E+05 0.1000E+05 0.9911E+04 0.8776E+04 0.9737E+05 0.1000E+05 0.9917E+04 0.8847E+04 0.1168E+06 0.1000E+05 0.9923E+04 0.8914E+04 0.1402E+06 0.1000E+05 0.9929E+04 0.8978E+04 0.1683E+06 0.1000E+05 0.9934E+04 0.9037E+04 0.2019E+06 0.1000E+05 0.9939E+04 0.9094E+04 0.2423E+06 0.1000E+05 0.9943E+04 0.9146E+04 0.2907E+06 0.1000E+05 0.9947E+04 0.9196E+04 0.3489E+06 0.1000E+05 0.9951E+04 0.9243E+04 0.4187E+06 0.1000E+05 0.9954E+04 0.9287E+04 0.5024E+06 0.1000E+05 0.9958E+04 0.9329E+04 0.6029E+06 0.1000E+05 0.9961E+04 0.9368E+04 0.7235E+06 0.1000E+05 0.9964E+04 0.9405E+04 0.8682E+06 0.1000E+05 0.9966E+04 0.9440E+04 0.1042E+07 0.1000E+05 0.9969E+04 0.9472E+04 0.1250E+07 0.1000E+05 0.9971E+04 0.9503E+04 0.1500E+07 0.1000E+05 0.9973E+04 0.9532E+04 0.1800E+07 0.1000E+05 0.9975E+04 0.9560E+04 0.2160E+07 0.1000E+05 0.9977E+04 0.9585E+04 0.2592E+07 0.1000E+05 0.9978E+04 0.9610E+04 0.3111E+07 0.1000E+05 0.9980E+04 0.9632E+04 0.3733E+07 0.1000E+05 0.9981E+04 0.9654E+04 0.4479E+07 0.1000E+05 0.9983E+04 0.9674E+04 0.5375E+07 0.1000E+05 0.9984E+04 0.9693E+04 0.6450E+07 0.1000E+05 0.9985E+04 0.9711E+04 0.7741E+07 0.1000E+05 0.9986E+04 0.9728E+04 0.9289E+07 0.1000E+05 0.9987E+04 0.9744E+04 0.1115E+08 0.1000E+05 0.9988E+04 0.9759E+04 0.1338E+08 0.1000E+05 0.9989E+04 0.9773E+04 0.1605E+08 0.1000E+05 0.9990E+04 0.9786E+04 0.1926E+08 0.1000E+05 0.9990E+04 0.9799E+04 0.2311E+08 0.1000E+05 0.9991E+04 0.9810E+04 0.2774E+08 0.1000E+05 0.9992E+04 0.9821E+04 0.3328E+08 0.1000E+05 0.9992E+04 0.9832E+04 0.3994E+08 0.1000E+05 0.9993E+04 0.9842E+04 0.4793E+08 0.1000E+05 0.9993E+04 0.9851E+04 0.5751E+08 0.1000E+05 0.9994E+04 0.9860E+04 0.6902E+08 0.1000E+05 0.9994E+04 0.9868E+04
When I am using x1 in XYDatasets to set up the x values (instead of the file list of x values), I get one two y axes 18 points apart (like it should be). When I use xer variable (which is the x values from the file), I get two y axes on top of each other! which doesnt make sense at all.
quote: Originally posted by quinncurtis
Sorry, but based on the information provided we do not have any suggestions, other than there is a 100% probability that it is a programming error and not a bug.
What is the range of the x-values in your data ? What is the scaled range that the x-axis shows in the graph ?
Exactly how does the calculation yAxisList(yname).SetAxisIntercept((graphNum - 1) * -18) relate to the range of the x-values?
|
|
|
guyguy2003
10 Posts |
Posted - 10 Mar 2008 : 23:57:14
|
as for your question 'Exactly how does the calculation yAxisList(yname).SetAxisIntercept((graphNum - 1) * -18) relate to the range of the x-values?' - It doesn't! thats why I am confused, and why I think there is a bug with the product (if there is a problem with my x values it should give me a proper error message and not mess up the graph's y axes..)
|
|
|
quinncurtis
1586 Posts |
Posted - 11 Mar 2008 : 09:44:54
|
First you should read FAQ #2 in the Frequently Asked Questions section of our QC3DChart Chapter 25 - titled "How do you create a chart with multiple coordinate systems and axes?"
The units of the y-axis SetAxisIntercept call are the same as x-coordinates of the scale. In our example, the x-scale has a range of 0-100. The y-axes are offset -18, -35, -52 units with respect to that scale. If your x-axis scale had a range of 0-10000, you would use y-intercept values approximatley -1800, -3500, and -5200, resulting in the same proportional offset.
It would be best if you automatically calculated the y-axis intercept based on the actual range of the x-axis that has already been scaled to the range of your x-values. read from the file, without knowing the range in advance. In that case you could use something like below, that uses the range of the coordinate system, pTransform2, that has already been scaled for your data.
yAxis2 = New LinearAxis(pTransform2, ChartObj.Y_AXIS)
Dim xintercept As Double = pTransform2.ScaleMinX - 0.18 * (pTransform2.ScaleMaxX - pTransform2.ScaleMinX)
yAxis2.SetAxisIntercept(xintercept)
The value of 0.18 has no special significance. It represents the relative percentage offset of the axis with respect to the plotting area of the graph. Make it larger and the axis moves to the left, make is smaller and it moves to the right. Select a value which matches your own aesthetic of what you want the graph to look like.
|
|
|
guyguy2003
10 Posts |
Posted - 12 Mar 2008 : 21:37:51
|
Thank you, that solved my issue :)
|
|
|
guyguy2003
10 Posts |
Posted - 12 Mar 2008 : 22:26:39
|
Actually, didn't solve it completely - any idea what to do when the x axis is Log? it doesn't work in this situation..
|
|
|
guyguy2003
10 Posts |
Posted - 12 Mar 2008 : 23:53:10
|
Never mind solved it - just use 1/10, 1/100, 1/1000 as SetAxisIntercept paramter values
|
|
|
quinncurtis
1586 Posts |
Posted - 12 Mar 2008 : 23:54:57
|
You are correct, the formula we gave only applies to a linear x-scale. But the concepts are exactly the same; you need to ask, if you exend the x-axis (linear or log) into the area outside of the plot area, what x-value gives you the y-axis position that you want? Dealing with a log x-scale just means you have to do some log/anti-log work to calculate the appropriate value. Below is a generalized routine that should work with linear and log scales.
Public Function CalcIntercept(ByVal ptransform As CartesianCoordinates, ByVal reloffset As Double) As Double
Dim result As Double = 0
If (TypeOf ptransform.XScale Is LogScale) Then
result = Math.Log10(ptransform.ScaleMinX) - reloffset * (Math.Log10(ptransform.ScaleMaxX) - Math.Log10(ptransform.ScaleMinX))
result = ChartSupport.Antilog10Ex(result)
Else
result = ptransform.ScaleMinX - reloffset * (ptransform.ScaleMaxX - ptransform.ScaleMinX)
End If
Return result
End Function
You would call it using:
yAxis2 = New LinearAxis(pTransform2, ChartObj.Y_AXIS)
Dim yintercept As Double = CalcIntercept(pTransform2, 0.18)
yAxis2.SetAxisIntercept(yintercept)
yAxis2.SetChartObjAttributes(attrib2) ' axis color matches line color
chartVu.AddChartObject(yAxis2) |
|
|
guyguy2003
10 Posts |
Posted - 14 Mar 2008 : 03:04:15
|
Thanks for that guys! you helped me out heaps :) Good to get fast and efficient support, much appriciated!
|
|
|
|
Topic |
|
|
|