|
Dual Y Axis Problem |
Posted by Paul on Feb-04-2011 19:06 |
|
Hi I have been looking at the example code found in dualaxis.php in the demo folder. I want to create a dual axis graph but every example I can find is not quite what I want. In the examples given the data points for the two plots occur at the same point on the x- axis, so you have the dual axis plots will each be in the same position horizontally along the x-axis.
The data sets would be somewthing like the below.
Y Axis 1: Page Size:
X Axis : Time
Y Axis 2: Speed
X Axis: Time
-----------
Y Axis 1 data:
1. Time=100, Page Size=20
2. TIme=200, Page Size=13
3. Time=300, Page Size=14
4. Time=400, Page Size=17
Y Axis 2 data:
1. Time=119, Speed=67
2. Time=345, Speed=34
2. Time=355, Speed=44
I have attached an image of what I have and what I woudl like to do - hopefully it is clear.
Thankyou for your help
Paul
|
Re: Dual Y Axis Problem |
Posted by Peter Kwan on Feb-05-2011 00:40 |
|
Hi Paul,
For your case, you just need to provide the x-coordinates of the data points for your layers. They can be different for different layers. There is an example "Uneven Data Points" in ChartDirector that shows how to plot data series with uneven and different x-coordinates.
To use two y-axes, you just need to bind one or more of the datasets to the second y-axis using Layer.setUseYAxis2. The "Dual Y-Axes" sample code demonstrates this.
For example:
$layer0 = $c->addBarLayer($barYData, ...);
$layer0->setXData($barXData);
$layer1 = $c->addLineLayer($lineYData, ...);
$layer1->setXData($lineXData);
$layer1->setUseYAxis2();
There is no need to use Axis.setLabels to configure the x-axis labels (just like you would not need to configure the y-axis labels). By default, the x-axis would be auto-scaled like the y-axis. If you would like to control the x-axis scale, you may use Axis.setLinearScale or Axis.setLinearScale2.
Hope this can help.
Regards
Peter Kwan |
Re: Dual Y Axis Problem |
Posted by Paul on Feb-08-2011 20:01 |
|
Thanks Peter - fantastic! |
|