-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello
I need to show Chart with two line series but each got independent value axis.
I was able to add a second axis correctly but I was not able to assign it to the second series. The problem is that jfreechart request a second Datasource to bind to axis while in ZK binding the model property can only be done to CategoryModel or XYModel which create two series in same Datasource.
Is there any way I can extend or create a new supported model that will create two data source instead of one so i can do the second axis binding in a clean way.
Note: HiLowModel create two datasources , the second one is for volume and a secondary axis is added to it as i want.
Note: I was able to do the above by creating the chart completely and then return the image to the content of img control in zul but I don't find this way as clean as using chart component plus i lose the tool tips and other features.
Is there any document on how to customize the model so i can create a new type as i want.
Best Regards
Hello
I was able to do that through the engine as below
public class DualAxisChartEngineViewModel extends JFreeChartEngine {
private int _width = 2;
private boolean showLine = true;
private boolean showShape = true;
private TimeSeriesCollection _ds0 = new TimeSeriesCollection();
private TimeSeriesCollection _ds1 = new TimeSeriesCollection();
private String _valueAxis1Label;
public boolean prepareJFreeChart(JFreeChart jfchart, Chart chart) {
XYPlot plot = (XYPlot) jfchart.getPlot();
XYLineAndShapeRenderer renderer0 = (XYLineAndShapeRenderer)plot.getRenderer(0);
NumberAxis rangeaxis0 = (NumberAxis)plot.getRangeAxis(0);
rangeaxis0.setAutoRangeIncludesZero(true);
TimeSeriesCollection ds = (TimeSeriesCollection) plot.getDataset(0);
//ds.addSeries(_ds0.getSeries(0));
plot.setDataset(0, _ds0);
for (int i = 0; i < _ds0.getSeriesCount(); i++) {
renderer0.setSeriesStroke(i, new BasicStroke(_width));
renderer0.setSeriesShapesVisible(i, showShape);
renderer0.setSeriesLinesVisible(i, showLine);
}
DateAxis domainaxis = (DateAxis) plot.getDomainAxis();
domainaxis.setDateFormatOverride(new SimpleDateFormat("hh:mma"));
NumberAxis rangeaxis1 = new NumberAxis(_valueAxis1Label);
rangeaxis1.setAutoRangeIncludesZero(true);
plot.setRangeAxis(1, rangeaxis1);
plot.setDataset(1, _ds1);
plot.mapDatasetToRangeAxis(1, 1);
XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
//renderer2.setSeriesPaint(0, Color.black);
//renderer2.setPlotShapes(true);
//renderer2.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
for (int i = 0; i < _ds1.getSeriesCount(); i++) {
renderer1.setSeriesStroke(i, new BasicStroke(_width));
renderer1.setSeriesShapesVisible(i, showShape);
renderer1.setSeriesLinesVisible(i, showLine);
}
plot.setRenderer(1, renderer1);
return false;
}
The only weird thing is that even thought i am overwriting both dataset but I had to set the model as below or i would have an error in array index and because I am using two dataset i had to add two series to my fake model
<chart id="chart" title="Half-Year Report" width="520" height="350" paneColor="#FFFFFF"
type="time_series" yAxis="Amount" model="@bind(vm._model)"
engine="@bind(vm._engine)" />
public XYModel getModel() {
XYModel xymodel = new SimpleXYModel();
xymodel.addValue("2001", new Integer(20), new Integer(120));
xymodel.addValue("2002", new Integer(30), new Integer(120));
return xymodel;
}
Hope this Help
Best Regards
Asked: 2013-04-18 15:05:48 +0800
Seen: 23 times
Last updated: Apr 23 '13
Multiple events on single line on Gantt chart
For Chart (gantt) ,Chinese Fonts garbled in X/Y,How to solve?
i have to install zk studio juno sr2 version in eclipse for windows 8
Dynamic upload of ExcelSheet data in mysql DB.
ZHighcharts using SimpleIntervalModel
JFreeChart Stacked Bar with XYModel
How to customize Dial Chart to show semi circle instead of full one?
I did find a work around but i am not able to post the answer till tomorrow !! cos i am new user :)
Shahbour ( 2013-04-19 11:38:19 +0800 )edit