|
Line graph with inconsistent step for both x axis and y axis |
Posted by Alfred on Jun-05-2014 17:59 |
|
Dear Sir/Madam,
We are having issue to plot a graph that where both x axis and y axis step value is inconsistent.
This is the graph we have plotted
Please refer to output.jpg
We would like to change the y axis to display the depth in such a way like this
1.0, 2.0, 3.0, 4.0 etc instead of 0.026667, 0.1833333, 0.401667, etc
So we have tried with Compact Line Chart with setLinearScale where the depth (y axis) data is divided evenly. The graph is wrong as the y axis is not the actual depth and its didn't match with the x axis data
Please refer to output2.jpg
Is there any other graph type suitable for this ?
Thanks
|
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Peter Kwan on Jun-06-2014 01:32 |
|
Hi Alfred,
ChartDirector always assume the y-coordinates are not evenly distributed. For the x-
coordinates, if they are not evenly distribute, you may use Layer.setXData to provide the
x-coordinates to ChartDirector, so ChartDirector can know how they are distributed. You
may refer to the "Uneven Data Points" and "Arbitrary XY Line Chart" sample code for some
examples. (You may look up these sample code from the ChartDirector documentation
index.)
For example, in C#/Java, it is like:
LineLayer layer = c.addLineLayer(yData, ....);
layer.setXData(xData);
c.swapXY();
With the above code, by default, ChartDirector will auto-scale the x-axis, just like it will
auto-scale the y-axis. ChartDirector will always choose nice labels (like 0, 1, 2, 3, ...) as
the axis labels. If you do not want auto-scaling, you may also use Axis.setLinearScale to
specify the axis scale explicitly.
Note that in ChartDirector terminology, with "swapXY", the x-axis is the vertical axis, and
the y-axis is the horizontal axis.
Hope this can help.
Regards
Peter Kwan |
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Alfred on Jun-06-2014 21:47 |
|
Dear Peter,
Thanks for your help, it works!
Yes, I manage to plot the graph now. But is there anyway to fill the graph area like my previous graph ?
Have a nice weekend!
Peter Kwan wrote:
Hi Alfred,
ChartDirector always assume the y-coordinates are not evenly distributed. For the x-
coordinates, if they are not evenly distribute, you may use Layer.setXData to provide the
x-coordinates to ChartDirector, so ChartDirector can know how they are distributed. You
may refer to the "Uneven Data Points" and "Arbitrary XY Line Chart" sample code for some
examples. (You may look up these sample code from the ChartDirector documentation
index.)
For example, in C#/Java, it is like:
LineLayer layer = c.addLineLayer(yData, ....);
layer.setXData(xData);
c.swapXY();
With the above code, by default, ChartDirector will auto-scale the x-axis, just like it will
auto-scale the y-axis. ChartDirector will always choose nice labels (like 0, 1, 2, 3, ...) as
the axis labels. If you do not want auto-scaling, you may also use Axis.setLinearScale to
specify the axis scale explicitly.
Note that in ChartDirector terminology, with "swapXY", the x-axis is the vertical axis, and
the y-axis is the horizontal axis.
Hope this can help.
Regards
Peter Kwan
|
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Peter Kwan on Jun-06-2014 23:55 |
|
Hi Alfred,
Instead of a line layer, you can use an area layer:
AreaLayer layer = c.addAreaLayer(yData, ....);
layer.setXData(xData);
c.swapXY();
Hope this can help.
Regards
Peter Kwan |
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Alfred on Jun-15-2014 21:23 |
|
Dear Peter,
Thanks for your help.
We would like to draw a middle line on y axis. But we don't know how to calculate the average value. Let say y axis data has min value of 0 and max value of 300. When we plot the graph, the upper limit of y axis is 500 now. How to calculate and get the value of 250 ?
c.yAxis().addMark(avgValue, c.dashLineColor(0x00FF00, Chart.DotLine));
|
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Peter Kwan on Jun-16-2014 16:37 |
|
Hi Alfred,
For your case, the line is at the same place (the middle of the plot area) regardless of the
y-axis range. This means the line does not depend on the axis range, and it should not be
necessary to know the axis range to draw the line. You may simply add a vertical line at the
middle of the plot area using pixel coordinates, like:
PlotArea p = c.getPlotArea();
c.addLine((p.getLeftX() + p.getRightX()) / 2, p.getTopY(), (p.getLeftX() + p.getRightX()) /
2, p.getBottomY(), c.dashLineColor(0x00FF00, Chart.DotLine)).setZOrder(Chart.GridLinesZ);
Hope this can help.
Regards
Peter Kwan |
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Alfred on Jun-16-2014 21:59 |
|
You are the man. It works. Thanks |
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Alfred on Jun-17-2014 23:53 |
|
Hi,
I try to set lower and upper limit of the graph, so any data outside this range will be ignored.
c.xAxis().setLinearScale(0, depth.Max(), 1);
LineLayer layer1 = c.addLineLayer(pGraphData, colorCode, "Depth");
layer1.setXData(depth);
layer1.setLineWidth(3);
layer1.getDataSet(0).setDataSymbol(Chart.CircleShapeNoShading, 2, colorCode);
PlotArea p = c.getPlotArea();
c.addLine((p.getLeftX() + p.getRightX()) / 2, p.getTopY(), (p.getLeftX() + p.getRightX()) / 2, p.getBottomY(), c.dashLineColor(0x00FF00, Chart.DotLine)).setZOrder(Chart.GridLinesZ);
c.yAxis().setLinearScale(0, 200);
Any idea? Thanks
|
Re: Line graph with inconsistent step for both x axis and y axis |
Posted by Peter Kwan on Jun-18-2014 00:34 |
|
Hi Alfred,
You can use XYChart.setClipping to clip the graph to the plot area. For example:
c.setClipping();
Hope this can help.
Regards
Peter Kwan |
|