List of usage examples for org.jfree.chart.axis NumberAxis setTickUnit
public void setTickUnit(NumberTickUnit unit)
From source file:userinterface.graph.AxisSettings.java
private void updateAxis() { /** -- First check whether we still have the right axis object */ /* If we do not have a logarithmic scale, but the axis settings want one, then change the axis. */ if (axis instanceof NumberAxis && isLogarithmic()) { /** Update xAxis such that other settings can be checked for consistency. */ PrismLogarithmicAxis newAxis = new PrismLogarithmicAxis(getHeading()); /** We need to discard all negative and zero values should there be any. */ /* TODO: Do this in a more elegant way. */ synchronized (graph.getSeriesLock()) { for (Graph.SeriesKey key : graph.getAllSeriesKeys()) { XYSeries series = graph.getXYSeries(key); if (series instanceof PrismXYSeries) { PrismXYSeries prismSeries = (PrismXYSeries) series; if (isDomain) prismSeries.setLogarithmicDomainAxis(true); else prismSeries.setLogarithmicRangeAxis(true); }/*from w w w. j av a2s . c o m*/ } } if (isDomain) { this.plot.setDomainAxis(newAxis); axis = this.plot.getDomainAxis(); } else { this.plot.setRangeAxis(newAxis); axis = this.plot.getRangeAxis(); } } /* If we have a logarithmic scale, but the axis settings want a normal scale, then change the axis. */ if (axis instanceof PrismLogarithmicAxis && !isLogarithmic()) { /** Update xAxis such that other settings can be checked for consistency. */ if (isDomain) { this.plot.setDomainAxis(new NumberAxis(getHeading())); axis = this.plot.getDomainAxis(); } else { this.plot.setRangeAxis(new NumberAxis(getHeading())); axis = this.plot.getRangeAxis(); } /** It could be we discarded some negative and zero values, lets bring them back. */ synchronized (graph.getSeriesLock()) { for (Graph.SeriesKey key : graph.getAllSeriesKeys()) { XYSeries series = graph.getXYSeries(key); if (series instanceof PrismXYSeries) { PrismXYSeries prismSeries = (PrismXYSeries) series; if (isDomain) prismSeries.setLogarithmicDomainAxis(false); else prismSeries.setLogarithmicRangeAxis(false); } } } } /** -- Check done, now look for smaller changes. */ /* If the heading of the axis does not match the heading set in the settings... */ if (!(axis.getLabel().equals(getHeading()))) { axis.setLabel(getHeading()); } /* Update axis heading font if appropriate */ if (!(axis.getLabelFont().equals(getHeadingFont().f))) { axis.setLabelFont(getHeadingFont().f); } /* Update axis heading colour if appropriate */ if (!(axis.getLabelPaint().equals(getHeadingFont().c))) { axis.setLabelPaint(getHeadingFont().c); } /* Update axis numbering font if appropriate */ if (!(axis.getTickLabelFont().equals(getNumberFont().f))) { axis.setTickLabelFont(getNumberFont().f); } /* Update axis numbering colour if appropriate */ if (!(axis.getTickLabelPaint().equals(getNumberFont().c))) { axis.setTickLabelPaint(getNumberFont().c); } /* Update gridlines if appropriate. */ if (isDomain && (plot.isDomainGridlinesVisible() != showGrid.getBooleanValue())) { plot.setDomainGridlinesVisible(showGrid.getBooleanValue()); } if (!isDomain && (plot.isRangeGridlinesVisible() != showGrid.getBooleanValue())) { plot.setRangeGridlinesVisible(showGrid.getBooleanValue()); } /* Update gridline colour if appropriate. */ if (isDomain && (!plot.getDomainGridlinePaint().equals(gridColour.getColorValue()))) { plot.setDomainGridlinePaint(gridColour.getColorValue()); } if (!isDomain && (!plot.getRangeGridlinePaint().equals(gridColour.getColorValue()))) { plot.setRangeGridlinePaint(gridColour.getColorValue()); } /** Check properties specific to logarithmic axis. */ if (axis instanceof PrismLogarithmicAxis) { PrismLogarithmicAxis logAxis = (PrismLogarithmicAxis) axis; if ((logStyle.getCurrentIndex() == BASE_AND_EXPONENT) != logAxis.isBaseAndExponentFormatOverride()) { logAxis.setBaseAndExponentFormatOverride(logStyle.getCurrentIndex() == BASE_AND_EXPONENT); } if ((logStyle.getCurrentIndex() == VALUES) && logAxis.getNumberFormatOverride() != this.valuesFormatter) { logAxis.setNumberFormatOverride(this.valuesFormatter); } /* Switched from auto to manual? */ if (logAxis.isAutoRange() && !autoScale.getBooleanValue()) { Range range = logAxis.getRange(); logAxis.setAutoRange(false); try { this.minimumPower.setValue(logAxis.calculateLog(range.getLowerBound())); this.maximumPower.setValue(logAxis.calculateLog(range.getUpperBound())); } catch (SettingException e) { // best effort. } } /* Switched from manual to auto? */ if (!axis.isAutoRange() && autoScale.getBooleanValue()) { axis.setAutoRange(true); } /* If the log base is wrong. */ if (logBase.getDoubleValue() != logAxis.getBase()) { Range range = axis.getRange(); logAxis.setBase(logBase.getDoubleValue()); try { this.minimumPower.setValue(logAxis.calculateLog(range.getLowerBound())); this.maximumPower.setValue(logAxis.calculateLog(range.getUpperBound())); } catch (SettingException e) { // best effort } if (Math.round(logBase.getDoubleValue()) == logBase.getDoubleValue()) logAxis.setMinorTickCount((int) logBase.getDoubleValue()); else logAxis.setMinorTickCount(1); } /* If manual, logarithmic, and range does not match our settings, then update */ if (!axis.isAutoRange()) { Range range = logAxis.getRange(); if (range.getLowerBound() != logAxis.calculateValue(minimumPower.getDoubleValue()) || range.getUpperBound() != logAxis.calculateValue(maximumPower.getDoubleValue())) { axis.setRange(logAxis.calculateValue(minimumPower.getDoubleValue()), logAxis.calculateValue(maximumPower.getDoubleValue())); } } } /** Check properties specific to numeric axis. */ if (axis instanceof NumberAxis) { NumberAxis numAxis = (NumberAxis) axis; /* Switched from auto to manual? */ if (axis.isAutoRange() && !autoScale.getBooleanValue()) { Range range = axis.getRange(); axis.setAutoRange(false); axis.setAutoTickUnitSelection(false); try { this.minValue.setValue(range.getLowerBound()); this.maxValue.setValue(range.getUpperBound()); this.gridInterval.setValue(numAxis.getTickUnit().getSize()); } catch (SettingException e) { // best effort. } } /* Switched from manual to auto? */ if (!axis.isAutoRange() && autoScale.getBooleanValue()) { axis.setAutoRange(true); axis.setAutoTickUnitSelection(true); } /* If manual, numeric, and range does not match our settings, then update */ if (!axis.isAutoRange()) { Range range = axis.getRange(); if (range.getLowerBound() != minValue.getDoubleValue() || range.getUpperBound() != maxValue.getDoubleValue()) { axis.setRange(minValue.getDoubleValue(), maxValue.getDoubleValue()); } if (gridInterval.getDoubleValue() != numAxis.getTickUnit().getSize()) { // FIXME: With i.e. interval 0.01 it rounds "0.10" to "0.1" numAxis.setTickUnit(new NumberTickUnit(gridInterval.getDoubleValue())); // Some experimental code to make axis display only odd numbers: /*if (axisShouldOnlyShowOdd) numAxis.setNumberFormatOverride(new DecimalFormat() { public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return ((int)number % 2 == 0) ? new StringBuffer("") : super.format(number, toAppendTo, pos); } });*/ } } } }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * For a given axis, adjust the tick unit size, in order to * have a customizable number of ticks on that axis *//*from www .ja va 2 s . co m*/ protected void calculateTickUnits(Axis axis, boolean isRangeAxis) { Integer tickCount = null; Number tickInterval = null; boolean axisIntegerUnit = false; if (getChart().hasProperties()) { String tickCountProperty = null; String tickIntervalProperty = null; String axisIntegerUnitProperty = null; if (isRangeAxis) { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT); } else { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT); } if (tickCountProperty != null && tickCountProperty.trim().length() > 0) { tickCount = Integer.valueOf(tickCountProperty); } if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) { tickInterval = Double.valueOf(tickIntervalProperty); } if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) { axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty); } } if (axis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) axis; int axisRange = (int) numberAxis.getRange().getLength(); if (axisIntegerUnit) { ChartUtil chartUtil = ChartUtil.getInstance(chartContext.getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } else if (axisRange > 0) { if (tickInterval != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), NumberFormat.getNumberInstance(getLocale()))); } } else if (tickCount != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit( new NumberTickUnit(axisRange / tickCount, numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount, NumberFormat.getNumberInstance(getLocale()))); } } else { ChartUtil chartUtil = ChartUtil.getInstance(chartContext.getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } } } // else if (axis instanceof DateAxis) // { // DateAxis dateAxis = (DateAxis)axis; // int axisRange = (int)dateAxis.getRange().getLength(); // if (dateAxis.getDateFormatOverride() != null) // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount, dateAxis.getDateFormatOverride())); // } // else // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount)); // } // } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * For a given axis, adjust the tick unit size, in order to * have a customizable number of ticks on that axis *//*from ww w. j a v a 2s . co m*/ protected void calculateTickUnits(Axis axis, AxisSettings axisSettings, int timePeriodUnit) { Integer tickCount = null; Number tickInterval = null; if (getChart().hasProperties()) { String tickCountProperty = null; String tickIntervalProperty = null; if (axisSettings == getChartThemeSettings().getRangeAxisSettings()) { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL); } else { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL); } if (tickCountProperty != null && tickCountProperty.trim().length() > 0) { tickCount = Integer.valueOf(tickCountProperty); } if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) { tickInterval = Double.valueOf(tickIntervalProperty); } } else { tickCount = axisSettings.getTickCount(); tickInterval = axisSettings.getTickInterval(); } if (tickInterval == null && tickCount == null) { return; } if (axis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) axis; int axisRange = (int) numberAxis.getRange().getLength(); if (axisRange > 0) { if (tickInterval != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue())); } } else if (tickCount != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount.intValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount.intValue())); } } } } // else if(axis instanceof DateAxis) // { // DateAxis dateAxis = (DateAxis)axis; // int axisRange = (int)dateAxis.getRange().getLength(); // if(dateAxis.getDateFormatOverride() != null) // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount, dateAxis.getDateFormatOverride())); // } // else // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount)); // } // } }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * For a given axis, adjust the tick unit size, in order to * have a customizable number of ticks on that axis *///ww w . j a va 2 s. co m protected void calculateTickUnits(Axis axis, boolean isRangeAxis, String timePeriodUnit) { Integer tickCount = null; Number tickInterval = null; if (getChart().hasProperties()) { String tickCountProperty = null; String tickIntervalProperty = null; if (isRangeAxis) { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL); } else { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL); } if (tickCountProperty != null && tickCountProperty.trim().length() > 0) { tickCount = Integer.valueOf(tickCountProperty); } if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) { tickInterval = Double.valueOf(tickIntervalProperty); } } else { if (isRangeAxis) { tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_TICK_COUNT); tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_TICK_INTERVAL); } else { tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_TICK_COUNT); tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_TICK_INTERVAL); } } if (tickInterval == null && tickCount == null) { return; } // if(axis instanceof NumberAxis) // { // NumberAxis numberAxis = (NumberAxis)axis; // int axisRange = (int)numberAxis.getRange().getLength(); // if(numberAxis.getNumberFormatOverride() != null) // { // if(tickInterval != null && tickInterval.length() > 0) // numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval).doubleValue(), numberAxis.getNumberFormatOverride())); // else // numberAxis.setTickUnit(new NumberTickUnit( axisRange/tickCount, numberAxis.getNumberFormatOverride())); // } // else // { // if(tickInterval != null && tickInterval.length() > 0) // numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval).doubleValue())); // else // numberAxis.setTickUnit(new NumberTickUnit(axisRange/tickCount)); // } // } if (axis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) axis; int axisRange = (int) numberAxis.getRange().getLength(); if (axisRange > 0) { if (tickInterval != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue())); } } else if (tickCount != null) { int newTickUnitSize = axisRange / tickCount.intValue(); if (newTickUnitSize > numberAxis.getTickUnit().getSize()) { int tickUnitSize = newTickUnitSize; //preferably multiple of 5 values should be used as tick units lengths: int i = 1; while (tickUnitSize > 9) { tickUnitSize /= 10; i *= 10; } tickUnitSize *= i; newTickUnitSize = tickUnitSize + i / 2; if (newTickUnitSize > 0 && axisRange / newTickUnitSize > tickCount.intValue()) { newTickUnitSize += i / 2; } if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit( new NumberTickUnit(newTickUnitSize, numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(newTickUnitSize)); } } } } } // else if(axis instanceof DateAxis) // { // DateAxis dateAxis = (DateAxis)axis; // int axisRange = (int)dateAxis.getRange().getLength(); // int timeUnit = getTimePeriodUnit(timePeriodUnit); // // if(dateAxis.getDateFormatOverride() != null) // { // if(tickInterval != null && tickInterval.length() > 0) // dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval).intValue(), dateAxis.getDateFormatOverride())); // else // dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount, dateAxis.getDateFormatOverride())); // } // else // { // if(tickInterval != null && tickInterval.length() > 0) // dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval).intValue())); // else // dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount)); // } // } }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * For a given axis, adjust the tick unit size, in order to * have a customizable number of ticks on that axis *//*from w w w . ja va2 s. c o m*/ protected void calculateTickUnits(Axis axis, AxisSettings axisSettings, DateTickUnitType timePeriodUnitx) { Integer tickCount = null; Number tickInterval = null; boolean axisIntegerUnit = false; if (getChart().hasProperties()) { String tickCountProperty = null; String tickIntervalProperty = null; String axisIntegerUnitProperty = null; if (axisSettings == getChartThemeSettings().getRangeAxisSettings()) { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT); } else { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT); } if (tickCountProperty != null && tickCountProperty.trim().length() > 0) { tickCount = Integer.valueOf(tickCountProperty); } if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) { tickInterval = Double.valueOf(tickIntervalProperty); } if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) { axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty); } } else { tickCount = axisSettings.getTickCount(); tickInterval = axisSettings.getTickInterval(); if (axisSettings.getAxisIntegerUnit() != null) { axisIntegerUnit = axisSettings.getAxisIntegerUnit(); } } if (axis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) axis; int axisRange = (int) numberAxis.getRange().getLength(); if (axisIntegerUnit) { ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } else if (axisRange > 0) { if (tickInterval != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), NumberFormat.getNumberInstance(getLocale()))); } } else if (tickCount != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit( new NumberTickUnit(axisRange / tickCount, numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount, NumberFormat.getNumberInstance(getLocale()))); } } else { ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } } } // else if (axis instanceof DateAxis) // { // DateAxis dateAxis = (DateAxis)axis; // int axisRange = (int)dateAxis.getRange().getLength(); // if (dateAxis.getDateFormatOverride() != null) // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount, dateAxis.getDateFormatOverride())); // } // else // { // dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount)); // } // } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * For a given axis, adjust the tick unit size, in order to * have a customizable number of ticks on that axis *//*from ww w. j a va 2s .c o m*/ protected void calculateTickUnits(Axis axis, boolean isRangeAxis, String timePeriodUnit) { Integer tickCount = null; Number tickInterval = null; boolean axisIntegerUnit = false; if (getChart().hasProperties()) { String tickCountProperty = null; String tickIntervalProperty = null; String axisIntegerUnitProperty = null; if (isRangeAxis) { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT); } else { tickCountProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT); tickIntervalProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL); axisIntegerUnitProperty = getChart().getPropertiesMap() .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT); } if (tickCountProperty != null && tickCountProperty.trim().length() > 0) { tickCount = Integer.valueOf(tickCountProperty); } if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) { tickInterval = Double.valueOf(tickIntervalProperty); } if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) { axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty); } } else { if (isRangeAxis) { tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_TICK_COUNT); tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_TICK_INTERVAL); if (getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_INTEGER_UNIT) != null) { axisIntegerUnit = (Boolean) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.RANGE_AXIS_INTEGER_UNIT); } } else { tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_TICK_COUNT); tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_TICK_INTERVAL); if (getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_INTEGER_UNIT) != null) { axisIntegerUnit = (Boolean) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.DOMAIN_AXIS_INTEGER_UNIT); } } } // if (axis instanceof NumberAxis) // { // NumberAxis numberAxis = (NumberAxis)axis; // int axisRange = (int)numberAxis.getRange().getLength(); // if (numberAxis.getNumberFormatOverride() != null) // { // if (tickInterval != null && tickInterval.length() > 0) // numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval), numberAxis.getNumberFormatOverride())); // else // numberAxis.setTickUnit(new NumberTickUnit( axisRange/tickCount, numberAxis.getNumberFormatOverride())); // } // else // { // if (tickInterval != null && tickInterval.length() > 0) // numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval))); // else // numberAxis.setTickUnit(new NumberTickUnit(axisRange/tickCount)); // } // } if (axis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) axis; int axisRange = (int) numberAxis.getRange().getLength(); if (axisIntegerUnit) { ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } else if (axisRange > 0) { if (tickInterval != null) { if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(), NumberFormat.getNumberInstance(getLocale()))); } } else if (tickCount != null) { int newTickUnitSize = axisRange / tickCount; if (newTickUnitSize > numberAxis.getTickUnit().getSize()) { int tickUnitSize = newTickUnitSize; //preferably multiple of 5 values should be used as tick units lengths: int i = 1; while (tickUnitSize > 9) { tickUnitSize /= 10; i *= 10; } tickUnitSize *= i; newTickUnitSize = tickUnitSize + i / 2; if (newTickUnitSize > 0 && axisRange / newTickUnitSize > tickCount) { newTickUnitSize += i / 2; } if (numberAxis.getNumberFormatOverride() != null) { numberAxis.setTickUnit( new NumberTickUnit(newTickUnitSize, numberAxis.getNumberFormatOverride())); } else { numberAxis.setTickUnit(new NumberTickUnit(newTickUnitSize, NumberFormat.getNumberInstance(getLocale()))); } } } else { ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale())); chartUtil.setAutoTickUnit(numberAxis); } } } // else if (axis instanceof DateAxis) // { // DateAxis dateAxis = (DateAxis)axis; // int axisRange = (int)dateAxis.getRange().getLength(); // int timeUnit = getTimePeriodUnit(timePeriodUnit); // // if (dateAxis.getDateFormatOverride() != null) // { // if (tickInterval != null && tickInterval.length() > 0) // dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval), dateAxis.getDateFormatOverride())); // else // dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount, dateAxis.getDateFormatOverride())); // } // else // { // if (tickInterval != null && tickInterval.length() > 0) // dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval))); // else // dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount)); // } // } }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.java
@Override public void resetAxes(final IScope scope) { NumberAxis domainAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(); NumberAxis range2Axis = rangeAxis;/*from ww w . j a v a 2 s. co m*/ boolean secondaxis = false; if (getUseSecondYAxis(scope)) { secondaxis = true; range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1); if (range2Axis == null) { NumberAxis secondAxis = new NumberAxis(""); ((XYPlot) this.chart.getPlot()).setRangeAxis(1, secondAxis); range2Axis = secondAxis; range2Axis = (NumberAxis) ((XYPlot) this.chart.getPlot()).getRangeAxis(1); range2Axis = formatYAxis(scope, range2Axis); ((XYPlot) this.chart.getPlot()).setRangeAxis(1, range2Axis); } } if (getX_LogScale(scope)) { LogarithmicAxis logAxis = new LogarithmicAxis(domainAxis.getLabel()); logAxis.setAllowNegativesFlag(true); ((XYPlot) this.chart.getPlot()).setDomainAxis(logAxis); domainAxis = logAxis; } if (getY_LogScale(scope)) { LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel()); logAxis.setAllowNegativesFlag(true); logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis); ((XYPlot) this.chart.getPlot()).setRangeAxis(logAxis); rangeAxis = logAxis; } if (secondaxis) { if (getY2_LogScale(scope)) { LogarithmicAxis logAxis = new LogarithmicAxis(range2Axis.getLabel()); logAxis.setAllowNegativesFlag(true); logAxis = (LogarithmicAxis) formatYAxis(scope, logAxis); ((XYPlot) this.chart.getPlot()).setRangeAxis(1, logAxis); range2Axis = logAxis; } } if (!getUseXRangeInterval(scope) && !getUseXRangeMinMax(scope)) { domainAxis.setAutoRange(true); } if (this.getUseXRangeInterval(scope)) { domainAxis.setFixedAutoRange(getXRangeInterval(scope)); domainAxis.setAutoRangeMinimumSize(getXRangeInterval(scope)); domainAxis.setAutoRange(true); } if (this.getUseXRangeMinMax(scope)) { domainAxis.setRange(getXRangeMin(scope), getXRangeMax(scope)); } if (this.getXTickLineVisible(scope)) { ((XYPlot) this.chart.getPlot()).setDomainGridlinePaint(this.tickColor); if (getXTickUnit(scope) > 0) { domainAxis.setTickUnit(new NumberTickUnit(getXTickUnit(scope))); ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(true); } else ((XYPlot) this.chart.getPlot()) .setDomainGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue()); } else { ((XYPlot) this.chart.getPlot()).setDomainGridlinesVisible(false); } if (!getUseYRangeInterval(scope) && !getUseYRangeMinMax(scope)) { rangeAxis.setAutoRange(true); } if (this.getUseYRangeInterval(scope)) { rangeAxis.setFixedAutoRange(getYRangeInterval(scope)); rangeAxis.setAutoRangeMinimumSize(getYRangeInterval(scope)); rangeAxis.setAutoRange(true); } if (this.getUseYRangeMinMax(scope)) { rangeAxis.setRange(getYRangeMin(scope), getYRangeMax(scope)); } if (this.getYTickLineVisible(scope)) { ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor); if (getYTickUnit(scope) > 0) { rangeAxis.setTickUnit(new NumberTickUnit(getYTickUnit(scope))); ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true); } else ((XYPlot) this.chart.getPlot()) .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue()); } else { ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false); } if (secondaxis) { if (!getUseY2RangeInterval(scope) && !getUseY2RangeMinMax(scope)) { range2Axis.setAutoRange(true); } if (this.getUseY2RangeInterval(scope)) { range2Axis.setFixedAutoRange(getY2RangeInterval(scope)); range2Axis.setAutoRangeMinimumSize(getY2RangeInterval(scope)); range2Axis.setAutoRange(true); } if (this.getUseY2RangeMinMax(scope)) { range2Axis.setRange(getY2RangeMin(scope), getY2RangeMax(scope)); } if (this.getYTickLineVisible(scope)) { ((XYPlot) this.chart.getPlot()).setRangeGridlinePaint(this.tickColor); if (getY2TickUnit(scope) > 0) { range2Axis.setTickUnit(new NumberTickUnit(getY2TickUnit(scope))); ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(true); } else ((XYPlot) this.chart.getPlot()) .setRangeGridlinesVisible(GamaPreferences.Displays.CHART_GRIDLINES.getValue()); } else { ((XYPlot) this.chart.getPlot()).setRangeGridlinesVisible(false); } } if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) { domainAxis.setLabel(getXLabel(scope)); } if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) { rangeAxis.setLabel(getYLabel(scope)); } if (secondaxis) { if (getY2Label(scope) != null && !getY2Label(scope).isEmpty()) { range2Axis.setLabel(getY2Label(scope)); } } if (this.series_label_position.equals("none")) { (this.chart).getLegend().setVisible(false); } if (!this.getXTickValueVisible(scope)) { domainAxis.setTickMarksVisible(false); domainAxis.setTickLabelsVisible(false); } }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
void createSeries(final IScope scope, final boolean isTimeSeries) throws GamaRuntimeException { final XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setTickLabelFont(getTickFont()); domainAxis.setLabelFont(getLabelFont()); if (isTimeSeries) { domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (timeSeriesXData == null) { timeSeriesXData = (ChartDataStatement) DescriptionFactory.create(IKeyword.DATA, description, IKeyword.LEGEND, xAxisName, IKeyword.VALUE, SimulationAgent.CYCLE).compile(); if (getFacet(IKeyword.TIMEXSERIES) != null) { timeSeriesXData.getDescription().getFacets().get(IKeyword.VALUE) .setExpression(getFacet(IKeyword.TIMEXSERIES)); }/*from ww w . ja v a 2 s .co m*/ } // FIXME: datas can NOT contain timeSeriesXData (a ChartDataStatement and not a ChartData) if (!datas.contains(timeSeriesXData)) { datas.add(0, timeSeriesXData.createData(scope)); } } IExpression expr = getFacet(XRANGE); IExpression expr2 = getFacet(XTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { domainAxis.setFixedAutoRange(r); domainAxis.setAutoRangeMinimumSize(r); } domainAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { domainAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { domainAxis.setTickUnit(new NumberTickUnit(r)); } } } if (datas.size() > 0) { domainAxis.setLabel(datas.get(0).getName()); } final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickLabelFont(getTickFont()); yAxis.setLabelFont(getLabelFont()); expr = getFacet(YRANGE); expr2 = getFacet(YTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setFixedAutoRange(r); yAxis.setAutoRangeMinimumSize(r); } yAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setTickUnit(new NumberTickUnit(r)); } } } if (datas.size() == 2) { yAxis.setLabel(datas.get(1).getName()); chart.removeLegend(); } final LegendTitle ll = chart.getLegend(); if (ll != null) { ll.setItemFont(getLegendFont()); } for (int i = 0; i < datas.size(); i++) { ChartData e = datas.get(i); final String legend = e.getName(); if (i != 0 | !isTimeSeries) { // the first data is the domain XYDataset data = plot.getDataset(i); XYSeries serie = new XYSeries(0, false, false); if (type == SERIES_CHART || type == XY_CHART) { dataset = new DefaultTableXYDataset(); // final XYSeries nserie = new XYSeries(serie.getKey(), false, false); final XYSeries nserie = new XYSeries(e.getName(), false, false); ((DefaultTableXYDataset) dataset).addSeries(nserie); } if (type == SCATTER_CHART) { dataset = new XYSeriesCollection(); final XYSeries nserie = new XYSeries(e.getName(), false, true); // final XYSeries nserie = new XYSeries(serie.getKey(), false, true); ((XYSeriesCollection) dataset).addSeries(nserie); } // dataset = new DefaultTableXYDataset(); // final XYSeries serie = new XYSeries(legend, false, false); // final XYSeries serie = new XYSeries(legend, false, true); // ((DefaultTableXYDataset) dataset).addSeries(serie); expressions_index.put(legend, i); plot.setRenderer(i, (XYItemRenderer) e.getRenderer(), false); // final Color c = e.getColor(); // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesPaint(0, c); // TODO Control this with a facet // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setBaseShapesFilled(false); // TODO Control this with a facet // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesShapesVisible(0, false); // if (type==SERIES_CHART) // plot.setDataset(i-1, (DefaultTableXYDataset) dataset); // else plot.setDataset(i, (XYDataset) dataset); } history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); }