public int showDialog(JChart chart) { JOptionPane optionPane = new JOptionPane( optionPanel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null); optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); Axis xAxis = chart.getXAxis(); Axis yAxis = chart.getYAxis(); if (canLogXAxis) { logXAxis.setSelected(xAxis instanceof LogAxis); } if (canLogYAxis) { logYAxis.setSelected(yAxis instanceof LogAxis); } if (!manualXAxis.isSelected()) { minXValue.setValue(xAxis.getMinAxis()); maxXValue.setValue(xAxis.getMaxAxis()); } if (!manualYAxis.isSelected()) { minYValue.setValue(yAxis.getMinAxis()); maxYValue.setValue(yAxis.getMaxAxis()); } final JDialog dialog = optionPane.createDialog(frame, "Setup Chart"); dialog.pack(); dialog.setVisible(true); final Integer value = (Integer) optionPane.getValue(); final int result = (value != null && value != -1) ? value : JOptionPane.CANCEL_OPTION; if (result == JOptionPane.OK_OPTION) { applySettings(chart); } return result; }
/** Get the FrequencyDistribution object */ protected FrequencyDistribution getFrequencyDistribution(Variate data, int minimumBinCount) { double min = (Double) data.getMin(); double max = (Double) data.getMax(); if (min == max) { if (min == 0) { min = -1.0; } else { min -= Math.abs(min / 10.0); } if (max == 0) { max = 1.0; } else { max += Math.abs(max / 10.0); } } Axis axis = new LinearAxis(Axis.AT_MAJOR_TICK, Axis.AT_MAJOR_TICK); axis.setRange(min, max); int majorTickCount = axis.getMajorTickCount(); axis.setPrefNumTicks(majorTickCount, 4); double binSize = axis.getMinorTickSpacing(); int binCount = (int) ((axis.getMaxAxis() - axis.getMinAxis()) / binSize) + 2; if (minimumBinCount > 0) { while (binCount < minimumBinCount) { majorTickCount++; axis.setPrefNumTicks(majorTickCount, 4); binSize = axis.getMinorTickSpacing(); binCount = (int) ((axis.getMaxAxis() - axis.getMinAxis()) / binSize) + 2; // should +2, otherwise the last bar will lose } } FrequencyDistribution frequency = new FrequencyDistribution(axis.getMinAxis(), binCount, binSize); for (int i = 0; i < raw.getCount(); i++) { frequency.addValue((Double) raw.get(i)); } return frequency; }