hi,
thanks in advance for assistance. This is a fun package to work with.
I'm having some problems with getting the axes on my overlaid charts to line up properly.
1. On my vertical axis, the numbers appear slightly lower than the grid lines, I'd like them to be exactly lined up.
2. In the lower left hand exterior corner of the chart, the "0.0" labels for x and y get cut off - I see roughly half the zeros in both cases.
3. My horizontal axis sometimes appears to begin before the beginning of the graph... ie, the scale begins to the left of the vertical axis and the lines start from off the chart (to the left). This seems to depend on my data.
In general, I'd like to be able to set mins and maxes and also the little distance between the edge of the chart and where 0 should be for both vert and hor, to have a little white space. However setting mins and maxs and spatial positions doesn't seem to work with combined charts. Can anybody offer any assistance?
Code is below if it helps. Here I'm combining simple lines (xydatasets). Changing the axis constructor parameters has no effect, nor does the setmax../min methods.
thanks,
matt
//get data
XYDataset[] datasets = liftChartBuilder.createDatasets(chartType, costValues);
int numGraphs = datasets.length;
CombinedDataset data = new CombinedDataset();
//first add the dataset for the reference line
XYDataset refLineDataset = liftChartBuilder.buildRefDataset(chartType);
((DefaultXYDataset)refLineDataset).setSeriesNames(new String[] {"Reference Line"});
data.add(new SubSeriesDataset(refLineDataset, 0));
//now add in the datasets for the lines.
for(int i=0;i<numGraphs;i++){
XYDataset dataset = datasets;
((DefaultXYDataset)dataset).setSeriesNames(getDatasetName(i));
data.add(new SubSeriesDataset(dataset, 0));
}
JFreeChart chart = null;
try {
// common horizontal and vertical axes
HorizontalNumberAxis xAxis = null;
VerticalNumberAxis yAxis = null;
if(chartType == LiftChartFrame.CUM_GAIN_TYPE){
yAxis = new VerticalNumberAxis( yAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(0),
new Double(100));
xAxis = new HorizontalNumberAxis(xAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(0),
new Double(100));
}else if(chartType == LiftChartFrame.LIFT_TYPE){
yAxis = new VerticalNumberAxis( yAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(verticalMin),
NumberAxis.DEFAULT_MAXIMUM_AXIS_VALUE);
xAxis = new HorizontalNumberAxis(xAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(0.0),
new Double(100.0));
}else if(chartType == LiftChartFrame.ROC_TYPE){
yAxis = new VerticalNumberAxis( yAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(0),
new Double(100));
xAxis = new HorizontalNumberAxis(xAxisLabel,
Axis.DEFAULT_AXIS_LABEL_FONT,
new Double(0),
new Double(100));
}
yAxis.setAutoRange(false);
// make an overlaid CombinedPlot
CombinedPlot overlaidPlot = new CombinedPlot(xAxis, yAxis);
//add the reference line, and the sub-plots
for(int i=0;i<numGraphs+1;i++){
CombinedChart cc = ChartFactory.createCombinableXYChart(xAxis, yAxis, new SubSeriesDataset(data, i));
overlaidPlot.add(cc);
}
// call this method after all sub-plots have been added
overlaidPlot.adjustPlots();
overlaidPlot.setInsets(new Insets(2,2,5,15));
overlaidPlot.setSeriesPaint(getChartColors());
// make the top level JFreeChart object
chart = new JFreeChart(data, overlaidPlot, title, JFreeChart.DEFAULT_TITLE_FONT, true);
}catch (AxisNotCompatibleException e) {
// this won't happen unless you mess with the axis constructors above
System.err.println("axis not compatible.");
}catch (PlotNotCompatibleException e) {
// this won't happen unless you mess with the axis constructors above
System.err.println("axis not compatible.");
}