List of usage examples for org.jfree.chart.axis ValueAxis setLabelFont
public void setLabelFont(Font font)
From source file:jhplot.HChart.java
/** * Update the chart//from w ww. jav a 2s . com * * @param N1 * location in X * @param N2 * location in Y */ public void update(int N1, int N2) { if (cdatPie[N1][N2] != null || cdatPie3D[N1][N2] != null || cdatBar[N1][N2] != null || cdatBar3D[N1][N2] != null || cdatLine[N1][N2] != null || cdatArea[N1][N2] != null || cdatPolar[N1][N2] != null) { if (cdatPie[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart(title[N1][N2], (PieDataset) cdatPie[N1][N2], true, true, true); } else if (cdatPie3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart3D(title[N1][N2], (PieDataset) cdatPie3D[N1][N2], true, true, true); PiePlot3D pieplot3d = (PiePlot3D) chart[N1][N2].getPlot(); // pieplot3d.setStartAngle(290D); // pieplot3d.setDirection(Rotation.CLOCKWISE); // pieplot3d.setForegroundAlpha(0.5F); pieplot3d.setBackgroundPaint(DEFAULT_BG_COLOR); } else if (cdatBar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } else if (cdatBar3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart3D(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar3D[N1][N2], PlotOrientation.VERTICAL, true, true, true); } else if (cdatLine[N1][N2] != null) { chart[N1][N2] = ChartFactory.createLineChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatLine[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); lineplot.setOutlineStroke(new BasicStroke(axisPenwidth)); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineplot.getRenderer(); renderer.setBaseStroke(new BasicStroke(linestroke)); for (int m = 0; m < cdatLine[N1][N2].getColumnCount() + 1; m++) renderer.setSeriesStroke(m, new BasicStroke(linestroke)); } else if (cdatPolar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPolarChart(title[N1][N2], (XYSeriesCollection) cdatPolar[N1][N2], true, true, true); PolarPlot lineplot = (PolarPlot) chart[N1][N2].getPlot(); ValueAxis yy = lineplot.getAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); } else if (cdatArea[N1][N2] != null) { chart[N1][N2] = ChartFactory.createAreaChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatArea[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); return; } for (int i = 0; i < indexdat[N1][N2]; i++) { if (type[N1][N2].get(i) == "array") xyplot[N1][N2].setRenderer(i, (StandardXYItemRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "f") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "h") xyplot[N1][N2].setRenderer(i, (XYBarRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "p") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "pe") xyplot[N1][N2].setRenderer(i, (XYErrorRenderer) (rdat[N1][N2].get(i))); // System.out.println(i); } chart[N1][N2] = new JFreeChart(title[N1][N2], JFreeChart.DEFAULT_TITLE_FONT, xyplot[N1][N2], true); chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java
private static ValueAxis createNumberOrDateDomainAxis(PlotInstance plotInstance, boolean date) throws ChartPlottimeException { PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone(); DomainConfigManager domainConfigManager = plotConfiguration.getDomainConfigManager(); DomainConfigManagerData domainConfigManagerData = plotInstance.getPlotData().getDomainConfigManagerData(); DimensionConfig domainConfig;/*from w w w .j a v a2 s .c om*/ domainConfig = domainConfigManager.getDomainConfig(false); if (domainConfig.isNominal()) { throw new IllegalArgumentException("Cannot create nominal domain axis from numerical domain config."); } ValueRange range = domainConfigManagerData.getEffectiveRange(); double upperBound = range.getUpperBound(); double lowerBound = range.getLowerBound(); double lowerBoundWithMargin = lowerBound; double upperBoundWithMargin = upperBound; // fetch old zooming LinkAndBrushMaster linkAndBrushMaster = plotInstance.getMasterPlotConfiguration().getLinkAndBrushMaster(); Range domainZoom = linkAndBrushMaster.getDomainZoom(); ValueAxis domainAxis; boolean logarithmic = false; if (domainConfigManager.isLogarithmicDomainAxis()) { logarithmic = true; if (date) { // disable logarithmic scale for dates. // Yes, a warning should be created, see DefaultDimensionConfig.getWarnings() for // this. logarithmic = false; } } if (logarithmic) { if (range.getLowerBound() <= 0) { throw new ChartPlottimeException("axis_configuration_error", domainConfigManager.getDimension().getName()); } CustomLogarithmicAxis customLogAxis = new CustomLogarithmicAxis(null); if (!domainConfigManager.isUsingUserDefinedLowerBound()) { lowerBoundWithMargin = lowerBound - (0.15 * lowerBound); } if (!domainConfigManager.isUsingUserDefinedUpperBound()) { upperBoundWithMargin = upperBound + (0.15 * upperBound); } // apply domain dimension range customLogAxis.saveUpperBound(upperBoundWithMargin, upperBound); customLogAxis.saveLowerBound(lowerBoundWithMargin, lowerBound); domainAxis = customLogAxis; } else { LinkAndBrushAxis linkAndBrushAxis; if (date) { CustomDateAxis dateAxis = new CustomDateAxis(null); if (domainConfig.isUsingUserDefinedDateFormat()) { dateAxis.setDateFormatOverride(domainConfig.getDateFormat()); dateAxis.setTimeZone(TimeZone.getTimeZone("GMT")); } linkAndBrushAxis = dateAxis; } else { linkAndBrushAxis = new CustomNumberAxis(null); ((NumberAxis) linkAndBrushAxis).setAutoRangeIncludesZero(false); } domainAxis = (ValueAxis) linkAndBrushAxis; // add margin double margin = upperBound - lowerBound; double pad = 0.04 * margin; if (!domainConfigManager.isUsingUserDefinedLowerBound()) { lowerBoundWithMargin = lowerBound - pad; } if (!domainConfigManager.isUsingUserDefinedUpperBound()) { upperBoundWithMargin = upperBound + pad; } // apply domain dimension range linkAndBrushAxis.saveUpperBound(upperBoundWithMargin, upperBound); linkAndBrushAxis.saveLowerBound(lowerBoundWithMargin, lowerBound); } // apply old zoom if axis has been zoomed before if (domainZoom != null) { domainAxis.setRange(domainZoom); } // domainAxis.setAutoRange(true); String label = domainConfigManager.getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); } domainAxis.setLabel(label); Font axesFont = plotConfiguration.getAxesFont(); if (axesFont != null) { domainAxis.setLabelFont(axesFont); domainAxis.setTickLabelFont(axesFont); } formatAxis(plotConfiguration, domainAxis); return domainAxis; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final XYPlot plot = chart.getXYPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }/*from ww w . ja v a 2 s. c o m*/ } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum; final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum; if (lineRangeMinimum != null) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (lineRangeMaximum != null) { linesAxis.setUpperBound(getRangeMaximum()); } if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { if (lineRangeMinimum != null) { linesAxis.setLowerBound(lineRangeMinimum); } if (lineRangeMaximum != null) { linesAxis.setUpperBound(lineRangeMaximum); } linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle())); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BarLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot plot = chart.getCategoryPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }//from w ww. j a v a 2s.c om } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (getRangeMaximum() != 1) { linesAxis.setUpperBound(getLineRangeMaximum()); } if (getLineRangeMinimum() == 0 && getLineRangeMaximum() == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { linesAxis.setLowerBound(getLineRangeMinimum()); linesAxis.setUpperBound(getLineRangeMaximum()); linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final LineAndShapeRenderer linesRenderer = (LineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(lineWidth, lineStyle)); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final XYPlot plot = chart.getXYPlot(); final XYItemRenderer renderer = plot.getRenderer(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula())); }// w ww . j a v a 2s .com if (StringUtils.isEmpty(getUrlFormula()) == false) { renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula())); } renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible())); if (getItemLabelFont() != null) { renderer.setBaseItemLabelFont(getItemLabelFont()); } plot.setOrientation(computePlotOrientation()); // May be an axis that supports dates final ValueAxis domainAxis = plot.getDomainAxis(); if (domainAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) domainAxis; numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero()); numberAxis.setAutoRangeStickyZero(isDomainStickyZero()); if (getDomainPeriodCount() > 0) { if (getDomainTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat())); } else if (getDomainTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getDomainTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount())); } } else { if (getDomainTickFormat() != null) { numberAxis.setNumberFormatOverride(getDomainTickFormat()); } else if (getDomainTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getDomainTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (domainAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) domainAxis; if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null) { if (getDomainTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getDomainTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount())); } } } if (domainAxis != null) { domainAxis.setLabel(getDomainTitle()); if (getDomainTitleFont() != null) { domainAxis.setLabelFont(getDomainTitleFont()); } domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels()); if (getDomainTickFont() != null) { domainAxis.setTickLabelFont(getDomainTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getDomainMinimum() != 0) { domainAxis.setLowerBound(getDomainMinimum()); } if (getDomainMaximum() != 1) { domainAxis.setUpperBound(getDomainMaximum()); } if (getDomainMinimum() == 0 && getDomainMaximum() == 0) { domainAxis.setLowerBound(0); domainAxis.setUpperBound(1); domainAxis.setAutoRange(true); } } else { domainAxis.setLowerBound(getDomainMinimum()); domainAxis.setUpperBound(getDomainMaximum()); domainAxis.setAutoRange(isDomainAxisAutoRange()); } } final ValueAxis rangeAxis = plot.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero()); numberAxis.setAutoRangeStickyZero(isRangeStickyZero()); if (getRangePeriodCount() > 0) { if (getRangeTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat())); } else if (getRangeTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount())); } } else { if (getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(getRangeTickFormat()); } else if (getRangeTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); standardTickUnitsApplyFormat(numberAxis, formatter); } } } else if (rangeAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) rangeAxis; if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit( new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount())); } } else { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } } if (rangeAxis != null) { rangeAxis.setLabel(getRangeTitle()); if (getRangeTitleFont() != null) { rangeAxis.setLabelFont(getRangeTitleFont()); } if (getRangeTickFont() != null) { rangeAxis.setTickLabelFont(getRangeTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { rangeAxis.setLowerBound(getRangeMinimum()); } if (getRangeMaximum() != 1) { rangeAxis.setUpperBound(getRangeMaximum()); } if (getRangeMinimum() == 0 && getRangeMaximum() == 0) { rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1); rangeAxis.setAutoRange(true); } } else { rangeAxis.setLowerBound(getRangeMinimum()); rangeAxis.setUpperBound(getRangeMaximum()); rangeAxis.setAutoRange(isRangeAxisAutoRange()); } } final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, parseColorFromString(colors[i])); } }
From source file:org.mwc.cmap.xyplot.views.XYPlotView.java
@SuppressWarnings("deprecation") private void fillThePlot(final String title, final String units, final formattingOperation theFormatter, final AbstractSeriesDataset dataset) { final StepControl _theStepper = null; // the working variables we rely on later _thePlotArea = null;//from w w w .j ava2 s .c o m ValueAxis xAxis = null; XYToolTipGenerator tooltipGenerator = null; // the y axis is common to hi & lo res. Format it here final NumberAxis yAxis = new NumberAxis(units); final Font tickFont = new Font("SansSerif", Font.PLAIN, 14); Font labelFont = new Font("SansSerif", Font.PLAIN, 16); yAxis.setLabelFont(labelFont); yAxis.setTickLabelFont(tickFont); // hmm, see if we are in hi-res mode. If we are, don't use a formatted // y-axis, just use the plain long microseconds // value if (HiResDate.inHiResProcessingMode()) { // final SimpleDateFormat _secFormat = new SimpleDateFormat("ss"); // ok, simple enough for us... final NumberAxis nAxis = new NumberAxis("time (secs.micros)") { /** * */ private static final long serialVersionUID = 1L; // public String getTickLabel(double currentTickValue) // { // long time = (long) currentTickValue; // Date dtg = new HiResDate(0, time).getDate(); // String res = _secFormat.format(dtg) + "." // + DebriefFormatDateTime.formatMicros(new HiResDate(0, time)); // return res; // } }; nAxis.setAutoRangeIncludesZero(false); xAxis = nAxis; // just show the raw data values tooltipGenerator = new StandardXYToolTipGenerator(); } else { // create a date-formatting axis final DateAxis dAxis = new RelativeDateAxis(); dAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits()); xAxis = dAxis; // also create the date-knowledgable tooltip writer tooltipGenerator = new DatedToolTipGenerator(); } xAxis.setTickLabelFont(tickFont); xAxis.setLabelFont(labelFont); // create the special stepper plot final ColourStandardXYItemRenderer theRenderer = new ColourStandardXYItemRenderer(tooltipGenerator, null, null); _thePlot = new StepperXYPlot(null, (RelativeDateAxis) xAxis, yAxis, _theStepper, theRenderer); theRenderer.setPlot(_thePlot); theRenderer.setStroke(new BasicStroke(3.0f)); _thePlot.setRangeGridlineStroke(new BasicStroke(1f)); _thePlot.setDomainGridlineStroke(new BasicStroke(1f)); _thePlot.setRangeGridlinePaint(Color.LIGHT_GRAY); xAxis.setTickMarkStroke(new BasicStroke(1f)); yAxis.setTickMarkStroke(new BasicStroke(1f)); _thePlot.setOutlineStroke(new BasicStroke(2f)); // loop through the datasets, setting the color of each series to the first // color in that series if (dataset instanceof TimeSeriesCollection) { Color seriesCol = null; final TimeSeriesCollection tsc = (TimeSeriesCollection) dataset; for (int i = 0; i < dataset.getSeriesCount(); i++) { final TimeSeries ts = tsc.getSeries(i); if (ts.getItemCount() > 0) { final TimeSeriesDataItem dataItem = ts.getDataItem(0); if (dataItem instanceof ColouredDataItem) { final ColouredDataItem cd = (ColouredDataItem) dataItem; seriesCol = cd.getColor(); _thePlot.getRenderer().setSeriesPaint(i, seriesCol); } } } } // apply any formatting for this choice if (theFormatter != null) { theFormatter.format(_thePlot); } boolean createLegend = dataset.getSeriesCount() > 1; _thePlotArea = new NewFormattedJFreeChart(title, null, _thePlot, createLegend, _theStepper); // set the color of the area surrounding the plot // - naah, don't bother. leave it in the application background color. _thePlotArea.setBackgroundPaint(Color.white); // //////////////////////////////////////////////// // put the holder into one of our special items // //////////////////////////////////////////////// _chartInPanel = new StepperChartPanel(_thePlotArea, true, _theStepper); // ok - we need to fire time-changes to the chart setupFiringChangesToChart(); // format the chart _chartInPanel.setName(title); _chartInPanel.setMouseZoomable(true, true); // and insert into the composite _plotControl.setChart(_thePlotArea); // get the cross hairs ready _thePlot.setDomainCrosshairVisible(true); _thePlot.setRangeCrosshairVisible(true); _thePlot.setDomainCrosshairPaint(Color.GRAY); _thePlot.setRangeCrosshairPaint(Color.GRAY); _thePlot.setDomainCrosshairStroke(new BasicStroke(2)); _thePlot.setRangeCrosshairStroke(new BasicStroke(2)); // and the plot object to display the cross hair value _crosshairValueText = new XYTextAnnotation(" ", 0, 0); _crosshairValueText.setTextAnchor(TextAnchor.TOP_LEFT); _crosshairValueText.setFont(new Font("SansSerif", Font.BOLD, 15)); _crosshairValueText.setPaint(Color.black); _crosshairValueText.setBackgroundPaint(Color.white); _thePlot.addAnnotation(_crosshairValueText); _thePlotArea.addChangeListener(new ChartChangeListener() { @Override public void chartChanged(ChartChangeEvent event) { if (_showSymbols.isShowSymbols() != _thePlotArea.isShowSymbols()) { _showSymbols.updateAction(); } } }); _showSymbols.updateAction(); _thePlotArea.addProgressListener(new ChartProgressListener() { public void chartProgress(final ChartProgressEvent cpe) { if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED) return; // double-check our label is still in the right place final double xVal = _thePlot.getRangeAxis().getUpperBound(); final double yVal = _thePlot.getDomainAxis().getLowerBound(); boolean annotChanged = false; if (_crosshairValueText.getX() != yVal) { _crosshairValueText.setX(yVal); annotChanged = true; } if (_crosshairValueText.getY() != xVal) { _crosshairValueText.setY(xVal); annotChanged = true; } // and write the text final String numA = MWC.Utilities.TextFormatting.GeneralFormat .formatOneDecimalPlace(_thePlot.getRangeCrosshairValue()); final Date newDate = new Date((long) _thePlot.getDomainCrosshairValue()); final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss"); _df.setTimeZone(TimeZone.getTimeZone("GMT")); final String dateVal = _df.format(newDate); final String theMessage = " [" + dateVal + "," + numA + "]"; if (!theMessage.equals(_crosshairValueText.getText())) { _crosshairValueText.setText(theMessage); annotChanged = true; } if (annotChanged) { _plotControl.getChart().setNotify(true); } } }); // //////////////////////////////////////////////////// // put the time series into the plot // //////////////////////////////////////////////////// _thePlot.setDataset((XYDataset) dataset); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected void configureRangeAxis(final CategoryPlot cpl, final Font labelFont) { final ValueAxis rangeAxis = cpl.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero()); numberAxis.setAutoRangeStickyZero(isRangeStickyZero()); if (getRangePeriodCount() > 0) { if (getRangeTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat())); } else if (getRangeTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount())); }/*from ww w .j a v a2 s. com*/ } else { if (getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(getRangeTickFormat()); } else if (getRangeTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); standardTickUnitsApplyFormat(numberAxis, formatter); } } } else if (rangeAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) rangeAxis; if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit( new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (rangeAxis != null) { rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); if (getRangeTitleFont() != null) { rangeAxis.setLabelFont(getRangeTitleFont()); } if (getRangeTickFont() != null) { rangeAxis.setTickLabelFont(getRangeTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { rangeAxis.setLowerBound(getRangeMinimum()); } if (getRangeMaximum() != 1) { rangeAxis.setUpperBound(getRangeMaximum()); } if (getRangeMinimum() == 0 && getRangeMaximum() == 0) { rangeAxis.setAutoRange(true); } } else { if (isAutoRange()) { rangeAxis.setAutoRange(isAutoRange()); } else { double factor = getScaleFactor(); if (factor > DEFAULT_SCALE_FACTOR) { // PRD-5340 hack // this method is invoked after all series were populated // hence the axis already has the graph's max and min values; double lower = rangeAxis.getLowerBound(); if (lower < 0) { lower *= factor; } else if (lower > 0) { lower /= factor; } double upper = rangeAxis.getUpperBound(); if (upper > 0) { upper *= factor; } else if (upper < 0) { upper /= factor; } rangeAxis.setRange(lower, upper); } else { // the 'scaleFactor' property is left intact or has an incorrect value rangeAxis.setUpperBound(getRangeMaximum()); rangeAxis.setLowerBound(getRangeMinimum()); } } } } }
From source file:atlas.kingj.roi.FrmMain.java
private void UpdateROIMaint(Machine[] mach) { //ResetStatusLabel(); if (results != null && RoiData.maintenance.size() >= results.getSize()) { DefaultCategoryDataset maintdata = new DefaultCategoryDataset(); String series1 = "Basic Costs"; String series2 = "Production Loss"; for (int i = 0; i < results.getSize(); ++i) { String name = results.get(i).getModel() + ": " + results.get(i).getName(); maintdata.addValue(RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost, series1, name);/* ww w .jav a2 s . c om*/ maintdata.addValue( RoiData.value * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000, series2, name); RoiResults.get(i).prodloss = RoiData.value * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000; RoiResults.get(i).partcosts = RoiData.maintenance .get(listCompareRoi.getSelectedIndices()[i]).totcost; RoiResults .get(i).maintcost = RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost + RoiData.value * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000; } // draw graph //JFreeChart chart = ChartFactory.createBarChart("", "", "Maintenance Cost ( / year)", maintdata, PlotOrientation.VERTICAL, false, true, false); JFreeChart chart = ChartFactory.createStackedBarChart("", "", "Maintenance Cost ( / year)", maintdata, PlotOrientation.VERTICAL, true, true, false); CategoryPlot cp = chart.getCategoryPlot(); cp.setBackgroundPaint(new Color(240, 240, 240)); cp.setRangeGridlinePaint(Color.gray); CategoryItemRenderer renderer = new CustomRenderer( new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85), new Color(251, 251, 0), new Color(86, 228, 200) }); //cp.setRenderer(renderer); cp.setShadowGenerator(new DefaultShadowGenerator(7, Color.DARK_GRAY, 1f, 5, -Math.PI / 4)); BarRenderer b = (BarRenderer) cp.getRenderer(); b.setBarPainter(new StandardBarPainter()); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); ValueAxis va = cp.getRangeAxis(); va.setLabelFont(new Font("Tahoma", Font.BOLD, 13)); RoiResults.setMaintGraph(chart); // Display results graph try { pnlGraphMaint.remove(lblNoGraph3); } catch (Exception e) { } try { pnlGraphMaint.remove(pnlGraphMaintInner); } catch (Exception e) { } pnlGraphMaintInner = new ChartPanel(RoiResults.getMaintGraph()); pnlGraphMaintInner.setBounds(2, 2, 435, 238); pnlGraphMaintInner.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphMaintInner.contains(e.getPoint()) && RoiResults != null && RoiResults.getMaintGraph() != null) { JFreeChart chart = RoiResults.getMaintGraph(); JFrame pop = new JFrame(); pop.getContentPane().add(new ChartPanel(chart)); try { pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png"))); } catch (Exception e11) { } pop.setTitle("ROI Graph"); pop.pack(); pop.setLocationRelativeTo(frmTitanRoiCalculator); pop.setVisible(true); } } }); pnlGraphMaint.add(pnlGraphMaintInner); pnlGraphMaintInner.repaint(); // Update production loss stat try { int sel = cmbMachinesmaintenance.getSelectedIndex(); if (arrayContains(listCompareRoi.getSelectedIndices(), sel)) lblProdLoss .setText("" + formatDecimal(RoiData.value * RoiData.maintenance.get(sel).tothours * results.get(arrayIndex(listCompareRoi.getSelectedIndices(), sel)) .getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000) + " / year"); else lblProdLoss.setText("Machine not selected"); } catch (Exception e) { lblProdLoss.setText("0.00 / year"); } // marginal improvement label int ind1 = cmbMargMaint1.getSelectedIndex(); int ind2 = cmbMargMaint2.getSelectedIndex(); double diff = maintdata.getValue(0, ind1).doubleValue() + maintdata.getValue(1, ind1).doubleValue() - maintdata.getValue(0, ind2).doubleValue() - maintdata.getValue(1, ind2).doubleValue(); lblMarginalMaint.setText("" + formatDecimal(diff) + " per annum"); } }
From source file:atlas.kingj.roi.FrmMain.java
private void UpdateROIProd(Machine[] machs) { //TODO don't need machs actually... (part of results) if (results != null && RoiData.value >= 0) { if (listCompareRoi.getSelectedIndices().length > 1) { DefaultCategoryDataset roidata = new DefaultCategoryDataset(); String series1 = "Value Added"; double offset = 0.; for (int i = 0; i < results.getSize(); ++i) { String name = results.get(i).getModel() + ": " + results.get(i).getName(); if (i == 0) { // offset all relative to first value offset = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value / 1000;//from w ww . j a v a 2 s. co m roidata.addValue(0, series1, name); RoiResults.get(i).value = 0; } else { roidata.addValue( results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value / 1000 - offset, series1, name); RoiResults.get(i).value = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value / 1000 - offset; } } // draw graph JFreeChart chart = ChartFactory.createBarChart("", "", "Relative Value Added (/year)", roidata, PlotOrientation.VERTICAL, false, true, false); CategoryPlot cp = chart.getCategoryPlot(); cp.setBackgroundPaint(new Color(240, 240, 240)); cp.setRangeGridlinePaint(Color.gray); CategoryItemRenderer renderer = new CustomRenderer( new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85), new Color(251, 251, 0), new Color(86, 228, 200) }); cp.setRenderer(renderer); BarRenderer b = (BarRenderer) cp.getRenderer(); b.setBarPainter(new StandardBarPainter()); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); ValueAxis va = cp.getRangeAxis(); va.setLabelFont(new Font("Tahoma", Font.BOLD, 13)); ResetStatusLabel(); RoiResults.setProdGraph(chart); // Display results graph try { pnlGraphProd.remove(lblNoGraph); } catch (Exception e) { } try { pnlGraphProd.remove(pnlGraphProdInner); } catch (Exception e) { } pnlGraphProdInner = new ChartPanel(RoiResults.getProdGraph()); pnlGraphProdInner.setBounds(2, 2, 435, 226); pnlGraphProdInner.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphProdInner.contains(e.getPoint()) && RoiResults != null && RoiResults.getProdGraph() != null) { JFreeChart chart = RoiResults.getProdGraph(); JFrame pop = new JFrame(); pop.getContentPane().add(new ChartPanel(chart)); try { pop.setIconImage( ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png"))); } catch (Exception e11) { } pop.setTitle("ROI Graph"); pop.pack(); pop.setLocationRelativeTo(frmTitanRoiCalculator); pop.setVisible(true); } } }); pnlGraphProd.add(pnlGraphProdInner); pnlGraphProdInner.repaint(); // marginal improvement label int ind1 = cmbMarg1.getSelectedIndex(); int ind2 = cmbMarg2.getSelectedIndex(); double diff = roidata.getValue(0, ind2).doubleValue() - roidata.getValue(0, ind1).doubleValue(); lblMarginalImprovement.setText("" + formatDecimal(diff) + " per annum"); } else { ResetStatusLabel(); ShowMessageStandard("Select at least 2 machines to view marginal benefits."); lblMarginalImprovement.setText("0.00 per annum"); // Display results graph try { pnlGraphProd.remove(pnlGraphProdInner); } catch (Exception e) { } pnlGraphProd.add(lblNoGraph); lblNoGraph.repaint(); } } else { ShowMessageStandard("Enter relevant data above to view graph."); lblMarginalImprovement.setText("0.00 per annum"); // Display results graph try { pnlGraphProd.remove(pnlGraphProdInner); } catch (Exception e2) { } pnlGraphProd.add(lblNoGraph); lblNoGraph.repaint(); } }