List of usage examples for org.jfree.chart.axis NumberAxis setNumberFormatOverride
public void setNumberFormatOverride(NumberFormat formatter)
From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java
/** * Generates a chart in PNG format.// ww w. j a va2 s.co m * @param outputFile the output file, it should exist. * @param pxWidth the image width in pixels. * @param pxHeight the image height in pixels. * @param chartTitle the chart title, may be null. * @param xAxisTitle the x axis title * @param yDataSeriesRange the axis range (null for auto) * @param yDataSeriesTitles the Y axis titles. * @param timeValuesInSeconds the time values in seconds * @param yDataSeries the Y axis value series. * @param yDataSeriesColors the Y axis value series drawing colors. * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix * @param drawBorder draw, or not, the border. * @param backgroundColor the chart background color. */ final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle, String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange, double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder, Color backgroundColor) { // Domain axis NumberAxis xAxis = new NumberAxis(xAxisTitle); xAxis.setFixedDimension(CHART_AXIS_DIMENSION); xAxis.setLabelPaint(Color.black); xAxis.setTickLabelPaint(Color.black); double maxSeconds = getMaxValue(timeValuesInSeconds); TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds); xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep)); double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds); String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name()); xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'")); // First dataset String firstDataSetTitle = yDataSeriesTitles[0]; XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]); Color firstDataSetColor = yDataSeriesColors[0]; // First range axis NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle); firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(firstYAxis, yDataSeriesRange[0]); firstYAxis.setLabelPaint(firstDataSetColor); firstYAxis.setTickLabelPaint(firstDataSetColor); String firstAxisTickSuffix = yDataSeriesTickSuffix[0]; if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) { firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'")); } // Create the plot with domain axis and first range axis XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null); XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(firstRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); firstRenderer.setSeriesPaint(0, firstDataSetColor); // Now iterate on next axes for (int i = 1; i < yDataSeries.length; i++) { // Create axis String seriesTitle = yDataSeriesTitles[i]; Color seriesColor = yDataSeriesColors[i]; NumberAxis yAxis = new NumberAxis(seriesTitle); yAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(yAxis, yDataSeriesRange[i]); yAxis.setLabelPaint(seriesColor); yAxis.setTickLabelPaint(seriesColor); String yAxisTickSuffix = yDataSeriesTickSuffix[i]; if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) { yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'")); } // Create dataset and add axis to plot plot.setRangeAxis(i, yAxis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i])); plot.mapDatasetToRangeAxis(i, i); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, seriesColor); plot.setRenderer(i, renderer); } // Create the chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false); // Customize rendering chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); // Render image try { ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight); } catch (IOException e) { LOG.error("Chart export failed", e); } }
From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java
@FXML public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null);//from w ww. j a v a 2 s .c o m plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (retention time) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("Retention time (min)"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartTitle.setText("Chromatogram"); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (ChromatogramPlotDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (ChromatogramPlotDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
From source file:com.android.ddmuilib.net.NetworkPanel.java
/** * Create chart of recent network activity. *//* ww w . ja v a 2 s . c o m*/ private void createChart() { mChart = ChartFactory.createTimeSeriesChart(null, null, null, null, false, false, false); // create backing datasets and series mRxTotalSeries = new TimeSeries("RX total"); mTxTotalSeries = new TimeSeries("TX total"); mRxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTxTotalSeries.setMaximumItemAge(HISTORY_MILLIS); mTotalCollection = new TimeSeriesCollection(); mTotalCollection.addSeries(mRxTotalSeries); mTotalCollection.addSeries(mTxTotalSeries); mRxDetailDataset = new LiveTimeTableXYDataset(); mTxDetailDataset = new LiveTimeTableXYDataset(); mTotalRenderer = new XYAreaRenderer(XYAreaRenderer.AREA); mRenderer = new StackedXYAreaRenderer2(); final XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyPlot.setDataset(0, mTotalCollection); xyPlot.setDataset(1, mRxDetailDataset); xyPlot.setDataset(2, mTxDetailDataset); xyPlot.setRenderer(0, mTotalRenderer); xyPlot.setRenderer(1, mRenderer); xyPlot.setRenderer(2, mRenderer); // we control domain axis manually when taking samples mDomainAxis = xyPlot.getDomainAxis(); mDomainAxis.setAutoRange(false); final NumberAxis axis = new NumberAxis(); axis.setNumberFormatOverride(new BytesFormat(true)); axis.setAutoRangeMinimumSize(50); xyPlot.setRangeAxis(axis); xyPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); // draw thick line to separate RX versus TX traffic xyPlot.addRangeMarker(new ValueMarker(0, java.awt.Color.BLACK, new java.awt.BasicStroke(2))); // label to indicate that positive axis is RX traffic final ValueMarker rxMarker = new ValueMarker(0); rxMarker.setStroke(new java.awt.BasicStroke(0)); rxMarker.setLabel("RX"); rxMarker.setLabelFont(rxMarker.getLabelFont().deriveFont(30f)); rxMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); rxMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); rxMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); xyPlot.addRangeMarker(rxMarker); // label to indicate that negative axis is TX traffic final ValueMarker txMarker = new ValueMarker(0); txMarker.setStroke(new java.awt.BasicStroke(0)); txMarker.setLabel("TX"); txMarker.setLabelFont(txMarker.getLabelFont().deriveFont(30f)); txMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY); txMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); txMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); xyPlot.addRangeMarker(txMarker); mChartComposite = new ChartComposite(mPanel, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 4096, 4096, true, true, true, true, false, true); final FormData data = new FormData(); data.top = new FormAttachment(mHeader); data.left = new FormAttachment(0); data.bottom = new FormAttachment(70); data.right = new FormAttachment(100); mChartComposite.setLayoutData(data); }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; String secondValueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); // split BarLineChartDefinition in two Definitions CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); /*/*from ww w. j a v a2s . c o m*/ * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset = * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){} */ // get column and row count of the data set int iColumnCount = chartDefinition.getColumnCount(); int iRowCount = chartDefinition.getRowCount(); if (iRowCount <= 0) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$ } /* * Copy data to the two new data sets */ // Loop through columns for (int r = 0; r < iRowCount; r++) { // check if measure should be include in bar or line dataset String strMeasureName = (String) chartDefinition.getRowKey(r); boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName); boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName); // getting all values for (int c = 0; c < iColumnCount; c++) { Comparable compColumnName = chartDefinition.getColumnKey(c); Number nValue = chartDefinition.getValue(strMeasureName, compColumnName); if (bIsBarColumn) { barsDataset.addValue(nValue, strMeasureName, compColumnName); } if (bIsLineColumn) { linesDataset.addValue(nValue, strMeasureName, compColumnName); } } } if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$ } // Create Axis Objects CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel); NumberAxis barsAxis = new NumberAxis(valueAxisLabel); NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel); // set title and font for lines Axis linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle()); linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont()); if (chartDefinition.getLinesRangeTickFormat() != null) { linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat()); } // create renderer BarRenderer barRenderer = null; LineAndShapeRenderer lineRenderer = null; // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { barRenderer = new StackedBarRenderer3D(); lineRenderer = new LineRenderer3D(); } else if (chartDefinition.isStacked()) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineRenderer3D(); } } else { barRenderer = new BarRenderer(); lineRenderer = new LineAndShapeRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } if (tooltips) { barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } // setting some line attributes lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible()); lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible()); /* * Create plot and make necessary adjustments for overlaid chart */ // create the plot with bar chart CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer); // add line renderer plot.setRenderer(1, lineRenderer); // add lines dataset, renderer and axis to plot plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // standard settings for plots JFreeChartEngine.updatePlot(plot, barsDataset); // additional settings for second axis ValueAxis secondValueAxis = plot.getRangeAxis(1); if (secondValueAxis != null) { if (chartDefinition.getLinesRangeTitle() != null) { secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle()); } if (chartDefinition.getLinesRangeTitleFont() != null) { secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont()); } if (chartDefinition.getLinesRangeTickFont() != null) { secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont()); } if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum()); } if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum()); } } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java
private synchronized JFreeChart createChart() { initSummaries(this.portfolioManagementJPanel); final XYDataset priceData = this.createInvestDataset(); JFreeChart chart = ChartFactory.createTimeSeriesChart(" ", GUIBundle.getString("InvestmentFlowChartJDialog_Date"), GUIBundle.getString("InvestmentFlowChartJDialog_Value"), priceData, true, // create legend? true, // generate tooltips? false // generate URLs? );// w w w . jav a 2s. c o m XYPlot plot = chart.getXYPlot(); NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final String currencySymbol = jStockOptions.getCurrencySymbol(jStockOptions.getCountry()); // Use apostrophes to escape currencySymbol. If currencySymbol contains // apostrophes, we may need to escape those by doubling them. // // 0 decimal place, to save up some display area. final NumberFormat currencyFormat = new DecimalFormat("'" + currencySymbol.replace("'", "''") + "'#,##0"); rangeAxis1.setNumberFormatOverride(currencyFormat); plot.setRenderer(1, new StandardXYItemRenderer()); this.ROITimeSeries = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_ReturnOfInvestment")); plot.setDataset(1, new TimeSeriesCollection(this.ROITimeSeries)); this.updateROITimeSeries(); return chart; }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initRangeAxis(ChartDefinitionVO chartDefinition) { int axisNumber = 0; int datasetNumber = 0; for (AxisDefinitionVO axisDefinition : chartDefinition.getAxisDefinitions()) { // configure the axis NumberAxis rangeAxis = new NumberAxis(axisDefinition.getLabel()); // set the properteis rangeAxis.setAutoRange(axisDefinition.isAutoRange()); if (axisDefinition.isAutoRange()) { rangeAxis.setAutoRangeIncludesZero(axisDefinition.isAutoRangeIncludesZero()); } else {/* w ww. ja v a 2 s. c om*/ rangeAxis.setLowerBound(axisDefinition.getLowerBound()); rangeAxis.setUpperBound(axisDefinition.getUpperBound()); } if (axisDefinition.getNumberFormat() != null) { rangeAxis.setNumberFormatOverride(new DecimalFormat(axisDefinition.getNumberFormat())); //##0.00% / "##0.000" } getPlot().setRangeAxis(axisNumber, rangeAxis); getPlot().setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT); // initialize datasets for (DatasetDefinitionVO datasetDefinition : axisDefinition.getDatasetDefinitions()) { XYDataset dataset; if (DatasetType.TIME.equals(datasetDefinition.getType())) { // create the time series collection dataset = new TimeSeriesCollection(); getPlot().setDataset(datasetNumber, dataset); // create the renderer XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); getPlot().setRenderer(datasetNumber, renderer); } else if (DatasetType.OHLC.equals(datasetDefinition.getType())) { // create the ohlc series collection dataset = new OHLCSeriesCollection(); getPlot().setDataset(datasetNumber, dataset); // create the renderer HideableCandlestickRenderer renderer = new HideableCandlestickRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator( new SimpleDateFormat("dd.MM.yyyy kk:mm:ss"), NumberFormat.getInstance())); getPlot().setRenderer(datasetNumber, renderer); } else { throw new IllegalArgumentException("illegal dataset type " + datasetDefinition.getType()); } getPlot().mapDatasetToRangeAxis(datasetNumber, axisNumber); // initialize series initSeries(datasetNumber, datasetDefinition, dataset); datasetNumber++; } axisNumber++; } }
From source file:no.met.jtimeseries.MeteogramWrapper.java
private void plotWindSpeedDirection(GenericDataModel model, ChartPlotter plotter, boolean showWindDirection, String unit, List<Date> symbolTimes) { // plot wind speed NumberPhenomenon windSpeed = model.getNumberPhenomenon(PhenomenonName.WindSpeedMPS.toString()).clone(); Color windSpeedColor = new Color(0, 0, 0); // number axis to be used for wind speed plot NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(windSpeedColor); numberAxis.setTickLabelPaint(windSpeedColor); if (unit.equalsIgnoreCase("ms")) { numberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)"); } else {/*from w w w. jav a 2 s .c om*/ windSpeed.scaling(1 / MarinogramPlot.KNOT); numberAxis.setLabel( messages.getString("parameter.wind") + " (" + messages.getString("label.knots") + ")"); NumberFormat formatter = new DecimalFormat("#0.0"); numberAxis.setNumberFormatOverride(formatter); } double maxValue = windSpeed.getMaxValue(); double minValue = windSpeed.getMinValue(); ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES); PlotStyle plotStyle = new PlotStyle.Builder("Wind").seriesColor(windSpeedColor) .plusDegreeColor(windSpeedColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f)) .numberAxis(numberAxis).nonNegative(true).build(); plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle); // plot wind direction if (showWindDirection) { NumberPhenomenon windDirection = model .getNumberPhenomenon(PhenomenonName.WindDirectionDegree.toString()).clone(); InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes); windDirection.filter(symbolTimesFilter); windSpeed.filter(symbolTimesFilter); // when plot wind direction, the arrow should be rotated 180 degree windDirection = windDirection.transform(180); NumberAxis numberAxisDirection = null; try { numberAxisDirection = (NumberAxis) numberAxis.clone(); } catch (CloneNotSupportedException e) { } numberAxisDirection.setVisible(false); plotter.getPlot().setRangeAxis(plotter.getPlotIndex(), numberAxisDirection); plotter.addArrowDirectionPlot(windDirection, windSpeed, 0.08, plotStyle); // transform back after plot windDirection = windDirection.transform(180); } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBarGroup.java
/** * Inherited by IChart./*from w w w.j a v a 2 s . c om*/ * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation legend, // legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); int numElForGroup = 0; for (int idx = 0; idx < numGroups.intValue(); idx++) { for (int j = 0; j < numSerieForGroup.intValue(); j++) { try { String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue()); map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1)); } catch (Exception e) { logger.error("out of range error in inserting in stacked bar group: continue anayway", e); } } } renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; /* MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); renderer.setItemURLGenerator(mycatUrl); */ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } int seriesN = dataset.getRowCount(); int numSerieColored = 0; if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { while (numSerieColored < seriesN) { for (int i = 1; i <= colorMap.size(); i++) { Color color = (Color) colorMap.get("SER" + i); Color gradient = new Color(Integer.decode("#FFFFFF").intValue()); if (gradientMap != null) gradient = (Color) gradientMap.get("SER" + i); if (color != null) { Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient); //renderer.setSeriesPaint(numSerieColored, color); renderer.setSeriesPaint(numSerieColored, p); } numSerieColored++; } } } renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); MyStandardCategoryItemLabelGenerator generator = null; if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); double orient = (-Math.PI / 2.0); if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient)); //horizontal labels /* renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER)); */ } SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel); String subCatLabel = ""; for (int j = 1; j <= numGroups.intValue(); j++) { if (subCatLabelsMap != null) subCatLabel = (String) subCatLabelsMap.get("CAT" + j); else subCatLabel = subCategoryLabel; domainAxis.addSubCategory(subCatLabel); domainAxis .setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis.setTickLabelFont( new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); } plot.setDomainAxis(domainAxis); plot.setRenderer(renderer); /* domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions( Math.PI / 6.0)); */ if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java
private void updateShown() { //Remove All//w w w . jav a 2 s .co m while (dataset.getSeriesCount() != 0) { dataset.removeSeries(0); } render.clear(); if (jTotal.isSelected()) { //Update total TimePeriodValues total = new TimePeriodValues(TabsTracker.get().total()); for (Map.Entry<SimpleTimePeriod, Value> entry : cache.entrySet()) { double t = 0; if (jWalletBalance.isSelected() && walletBalance != null) { t += entry.getValue().getBalanceTotal(); } if (jAssets.isSelected() && assets != null) { t += entry.getValue().getAssetsTotal(); } if (jSellOrders.isSelected() && sellOrders != null) { t += entry.getValue().getSellOrders(); } if (jEscrows.isSelected() && escrows != null) { t += entry.getValue().getEscrows(); } //Escrows To Cover is not money you own, It's technically money you owe //Therefor it's not included in the total //See: https://forums.eveonline.com/default.aspx?g=posts&m=6607898#post6607898 //if (jEscrowsToCover.isSelected() && escrowsToCover != null) { // t += entry.getValue().getEscrowsToCover(); //} if (jManufacturing.isSelected() && manufacturing != null) { t += entry.getValue().getManufacturing(); } if (jContractCollateral.isSelected() && contractCollateral != null) { t += entry.getValue().getContractCollateral(); } if (jContractValue.isSelected() && contractValue != null) { t += entry.getValue().getContractValue(); } total.add(entry.getKey(), t); } dataset.addSeries(total); Integer minColumn = null; if (jWalletBalance.isSelected() && walletColumn != null) { minColumn = walletColumn; } if (jAssets.isSelected() && assetColumn != null) { if (minColumn != null) { minColumn = Math.min(minColumn, assetColumn); } else { minColumn = assetColumn; } } render.add(dataset.getSeriesCount() - 1, minColumn); updateRender(dataset.getSeriesCount() - 1, Color.RED.darker()); } if (jWalletBalance.isSelected() && walletBalance != null) { dataset.addSeries(walletBalance); render.add(dataset.getSeriesCount() - 1, walletColumn); updateRender(dataset.getSeriesCount() - 1, Color.BLUE.darker()); } if (jAssets.isSelected() && assets != null) { dataset.addSeries(assets); render.add(dataset.getSeriesCount() - 1, assetColumn); updateRender(dataset.getSeriesCount() - 1, Color.GREEN.darker().darker()); } if (jSellOrders.isSelected() && sellOrders != null) { dataset.addSeries(sellOrders); updateRender(dataset.getSeriesCount() - 1, Color.CYAN.darker()); } if (jEscrows.isSelected() && escrows != null) { dataset.addSeries(escrows); updateRender(dataset.getSeriesCount() - 1, Color.BLACK); } if (jEscrowsToCover.isSelected() && escrowsToCover != null) { dataset.addSeries(escrowsToCover); updateRender(dataset.getSeriesCount() - 1, Color.GRAY); } if (jManufacturing.isSelected() && manufacturing != null) { dataset.addSeries(manufacturing); updateRender(dataset.getSeriesCount() - 1, Color.MAGENTA); } if (jContractCollateral.isSelected() && contractCollateral != null) { dataset.addSeries(contractCollateral); updateRender(dataset.getSeriesCount() - 1, Color.PINK); } if (jContractValue.isSelected() && contractValue != null) { dataset.addSeries(contractValue); updateRender(dataset.getSeriesCount() - 1, Color.ORANGE); } //Add empty dataset if (dataset.getSeriesCount() == 0) { TimePeriodValues timePeriodValues = new TimePeriodValues(TabsTracker.get().empty()); dataset.addSeries(timePeriodValues); updateRender(dataset.getSeriesCount() - 1, Color.BLACK); } jNextChart.getXYPlot().getRangeAxis().setAutoRange(true); jNextChart.getXYPlot().getDomainAxis().setAutoRange(true); Number maxNumber = DatasetUtilities.findMaximumRangeValue(dataset); NumberAxis rangeAxis = (NumberAxis) jNextChart.getXYPlot().getRangeAxis(); rangeAxis.setNumberFormatOverride(Formater.LONG_FORMAT); //Default if (maxNumber != null && (maxNumber instanceof Double)) { double max = (Double) maxNumber; if (max > 1000000000000.0) { //Higher than 1 Trillion rangeAxis.setNumberFormatOverride(Formater.TRILLIONS_FORMAT); } else if (max > 1000000000.0) { //Higher than 1 Billion rangeAxis.setNumberFormatOverride(Formater.BILLIONS_FORMAT); } else if (max > 1000000.0) { //Higher than 1 Million rangeAxis.setNumberFormatOverride(Formater.MILLIONS_FORMAT); } } }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * configure range axis ( lowerBound, upperBound, label, format ticks) * of time-series chart/* w ww .ja va2 s . c o m*/ * @param numberAxis * @param label */ private void configureRangeAxis(NumberAxis numberAxis, String label) { double min = numberAxis.getLowerBound(); double max = numberAxis.getUpperBound(); Double delta = 0.01 * (max - min); numberAxis.setLowerBound(min - delta); numberAxis.setUpperBound(max + delta); numberAxis.setLabel(label); // format Ticks double fontHeight = numberAxis.getTickLabelFont().getLineMetrics("X", this.frc).getHeight(); double maxTicks = this.paintPanel.getSize().height / fontHeight; int digits = Math.max(0, (int) -Math.floor(Math.log10((max - min) / maxTicks))); //System.out.println(fontHeight+" "+digits+" "+Math.log10((max - min)/ maxTicks)); NumberFormat formatter = NumberFormat.getNumberInstance(this.locale); formatter.setMinimumFractionDigits(digits); formatter.setMaximumFractionDigits(digits); formatter.setGroupingUsed(true); numberAxis.setNumberFormatOverride(formatter); }