List of usage examples for org.jfree.chart.axis NumberAxis setLabelPaint
public void setLabelPaint(Paint paint)
From source file:org.encog.workbench.dialogs.training.ChartPane.java
/** * Create the initial chart.// w ww . j a v a 2 s . co m * @return The chart. */ private JFreeChart createChart() { this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.getRangeAxis().setFixedDimension(15.0); // AXIS 2 final NumberAxis axis2 = new NumberAxis("Error Improvement"); axis2.setFixedDimension(10.0); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, this.dataset2); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); ChartUtilities.applyCurrentTheme(this.chart); return this.chart; }
From source file:com.trivadis.loganalysis.ui.ChartPanel.java
private NumberAxis axis(final Color color, final String label) { final NumberAxis yNumberAxis = new NumberAxis(label); yNumberAxis.setTickLabelPaint(color); yNumberAxis.setLabelPaint(color); return yNumberAxis; }
From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java
private XYPlot createPlot(TimeZone timezone, boolean plotAirTemp, boolean plotWaterTemp, boolean plotDewpointTemp) throws ParseException { Date startTime = null;//ww w. j av a 2 s .c om NumberPhenomenon aTemperature = null; NumberPhenomenon wTemperature = null; NumberPhenomenon dTemperature = null; // default setting ChartPlotter plotter = new ChartPlotter(); plotter.setHeight(this.getHeight()); plotter.setWidth(this.getWidth()); plotter.setPlotDefaultProperties("", ""); double minValue = 100; double maxValue = -100; int plotIndex = 0; if (plotAirTemp) { aTemperature = getLocationForecastDataModel().getPhenomenen(PhenomenonName.AirTemperature.toString(), NumberPhenomenon.class); minValue = aTemperature.getMinValue() < minValue ? aTemperature.getMinValue() : minValue; maxValue = aTemperature.getMaxValue() > maxValue ? aTemperature.getMaxValue() : maxValue; startTime = aTemperature.getTime().get(0); plotTemperature(plotter, aTemperature, new BasicStroke(2.0f), Color.RED, messages.getString("label.air"), true); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(1, true); plotIndex++; } if (plotWaterTemp) { wTemperature = getOceanForecastDataModel().getPhenomenen(PhenomenonName.seaTemperature.toString(), NumberPhenomenon.class); // only plot water temperature if it is availbe for this location if (wTemperature != null) { minValue = wTemperature.getMinValue() < minValue ? wTemperature.getMinValue() : minValue; maxValue = wTemperature.getMaxValue() > maxValue ? wTemperature.getMaxValue() : maxValue; startTime = wTemperature.getTime().get(0); BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f); plotTemperature(plotter, wTemperature, dottedStroke, Color.RED, messages.getString("label.water"), true); plotter.getPlot().getRenderer(plotIndex++).setSeriesVisibleInLegend(0, true); } } if (plotDewpointTemp) { dTemperature = getLocationForecastDataModel() .getPhenomenen(PhenomenonName.dewPointTemperature.toString(), NumberPhenomenon.class); minValue = dTemperature.getMinValue() < minValue ? dTemperature.getMinValue() : minValue; maxValue = dTemperature.getMaxValue() > maxValue ? dTemperature.getMaxValue() : maxValue; startTime = dTemperature.getTime().get(0); plotTemperature(plotter, dTemperature, new BasicStroke(2.0f), Color.ORANGE, messages.getString("label.dewpoint"), false); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true); } double tick = (maxValue - minValue) / 3.5; tick = Math.ceil(tick); double lowBound = Math.floor(minValue / (tick)) * (tick); lowBound = lowBound - tick / 2; double upperBound = lowBound + tick * 7; // set range axis NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(Color.RED); numberAxis.setTickLabelPaint(Color.RED); numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)"); numberAxis.setTickUnit(new NumberTickUnit(tick)); numberAxis.setLowerBound(lowBound); numberAxis.setUpperBound(upperBound); //Set left axis and right axis plotter.getPlot().setRangeAxis(0, numberAxis); plotter.getPlot().setRangeAxis(1, numberAxis); //Set the third axis and hide the third axis if (plotAirTemp && plotWaterTemp && plotDewpointTemp) { NumberAxis numberAxis2 = new NumberAxis(); numberAxis2.setTickUnit(new NumberTickUnit(tick)); numberAxis2.setLowerBound(lowBound); numberAxis2.setUpperBound(upperBound); plotter.getPlot().setRangeAxis(2, numberAxis2); plotter.getPlot().getRangeAxis(2).setVisible(false); } //Show legend at the top right position of the plot LegendTitle lt = new LegendTitle(plotter.getPlot()); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(255, 255, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.TOP); XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.95, lt, RectangleAnchor.TOP_RIGHT); plotter.getPlot().addAnnotation(ta); // set domain range after (must) plot all the data plotter.addHourBasedDomainGridLines(); // add markers plotter.addDomainMarkers(getShortTermTime(startTime), timezone, locale); Date minDate = getShortTermTime(startTime).get(0); Date maxDate = getShortTermTime(startTime).get(getShortTermTime(startTime).size() - 1); plotter.setDomainRange(minDate, maxDate); plotter.setDomainDateFormat(timezone, "HH"); plotter.getPlot().setOutlineVisible(true); // invisible the domain i.e, x axis plotter.getPlot().getDomainAxis().setTickLabelsVisible(false); return plotter.getPlot(); }
From source file:org.jls.toolbox.math.chart.XYBarChart.java
/** * Permet de paramtrer le graphique une fois cr. *//* w ww.j a v a2 s . co m*/ private void setChartStyle() { // Paramtrage des courbes this.plot.setBackgroundAlpha((float) 0.0); this.plot.setDomainCrosshairVisible(this.isGridXVisible); this.plot.setDomainCrosshairLockedOnData(true); this.plot.setRangeCrosshairVisible(this.isGridYVisible); this.plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); this.plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); this.chart.setBackgroundPaint(this.CHART_BACKGROUND_COLOR); NumberAxis xAxis = (NumberAxis) this.plot.getDomainAxis(); NumberAxis yAxis = (NumberAxis) this.plot.getRangeAxis(); xAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR); xAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR); xAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR); xAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR); xAxis.setAutoRange(true); xAxis.setAutoRangeIncludesZero(false); yAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR); yAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR); yAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR); yAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR); yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(false); this.plot.setBackgroundPaint(this.CHART_FOREGROUND_COLOR); this.plot.setDomainGridlinePaint(this.CHART_FOREGROUND_COLOR); this.plot.setRangeGridlinePaint(this.CHART_FOREGROUND_COLOR); this.plot.setDomainCrosshairPaint(this.CROSSHAIR_COLOR); this.plot.setRangeCrosshairPaint(this.CROSSHAIR_COLOR); }
From source file:no.met.jtimeseries.marinogram.MarinogramWavePlot.java
private XYPlot createPlot(TimeZone timezone, boolean plotWaveDirection, boolean plotWaveHeight) { ChartPlotter plotter = new ChartPlotter(); // default setting plotter.setHeight(this.getHeight()); plotter.setWidth(this.getWidth()); plotter.setPlotDefaultProperties("", ""); Color waveHeightColor = new Color(0, 105, 161); Color waveDirectionColor = new Color(0, 105, 161); // plot style PlotStyle.Builder waveStyleBuilder = new PlotStyle.Builder("Wave"); PlotStyle plotStyle;/*ww w . ja v a 2s .c o m*/ NumberPhenomenon waveDirection = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.WaveDirection.toString(), NumberPhenomenon.class); NumberPhenomenon waveHeight = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.WaveHeight.toString(), NumberPhenomenon.class); if (waveHeight == null || waveDirection == null) { return null; } double tick = (waveHeight.getMaxValue() - waveHeight.getMinValue()) / 2; tick = Math.ceil(tick); double lowBound = Math.floor(waveHeight.getMinValue() / (tick)) * (tick); //The minimum scale is 0 lowBound = lowBound < 0 ? 0 : lowBound; lowBound = lowBound - tick / 2; double upperBound = lowBound + tick * 4; // reference the range axis NumberAxis leftNumberAxis = new NumberAxis(); leftNumberAxis.setLabel(messages.getString("parameter.wave") + " (m)"); leftNumberAxis.setLabelPaint(waveHeightColor); leftNumberAxis.setTickLabelPaint(waveHeightColor); leftNumberAxis.setLowerBound(lowBound); leftNumberAxis.setUpperBound(upperBound); leftNumberAxis.setTickUnit(new NumberTickUnit(tick)); NumberAxis rightNumberAxis = new NumberAxis(); rightNumberAxis.setLabelPaint(waveHeightColor); rightNumberAxis.setTickLabelPaint(waveHeightColor); rightNumberAxis.setLowerBound(lowBound); rightNumberAxis.setUpperBound(upperBound); rightNumberAxis.setTickUnit(new NumberTickUnit(tick)); List<Date> shortTermTime = this.getShortTermTime(waveDirection.getTime().get(0)); //set thte plot wave height color to be transparent if show wave height is false if (!plotWaveHeight) { waveHeightColor = new Color(0, 0, 0, 0); } // plot style plotStyle = waveStyleBuilder.spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f)) .seriesColor(waveHeightColor).numberAxis(leftNumberAxis).nonNegative(true).build(); //Draw the wave height even if plotWaveHeight is false (but with transparent in such a case) //for the purpose to keep the same background grid and tick label on the y-axis //no matter the wave height is shown or not plotter.addLineChart(TimeBase.SECOND, waveHeight, plotStyle); plotter.getPlot().setRangeAxis(1, rightNumberAxis); plotter.getPlot().setOutlineVisible(true); // first set domain date format and then add hour based domain grid // lines // TODO: wrap this inside the addHourBasedDomainGridLines for // simplicity Date minDate = shortTermTime.get(0); Date maxDate = shortTermTime.get(shortTermTime.size() - 1); plotter.setDomainRange(minDate, maxDate); plotter.setDomainDateFormat(timezone, "HH"); // set domain range after (must) plot all the data plotter.addHourBasedDomainGridLines(); // invisible domain axis plotter.getPlot().getDomainAxis().setTickLabelsVisible(false); // add markers plotter.addDomainMarkers(shortTermTime, timezone, locale); if (plotWaveDirection) { List<Date> symbolTimes = Utility.filterMinimumHourInterval(waveDirection.getTime(), 2, 1); InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes); waveDirection.filter(symbolTimesFilter); waveHeight = null; if (plotWaveHeight) { waveHeight = getOceanForecastDataModel().getPhenomenen(PhenomenonName.WaveHeight.toString(), NumberPhenomenon.class); waveHeight.filter(symbolTimesFilter); } plotStyle = waveStyleBuilder.seriesColor(waveDirectionColor).build(); plotter.addArrowDirectionPlot(waveDirection, waveHeight, 0.1, plotStyle); } plotter.getPlot().setRangeZeroBaselineVisible(false); return plotter.getPlot(); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, legend, true, false);/*from w w w .j ava 2 s .c o m*/ /*Font font = new Font("Tahoma", Font.BOLD, titleDimension); TextTitle title = new TextTitle(name, font); chart.setTitle(title);*/ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); chart.setBackgroundPaint(color); XYPlot plot = (XYPlot) chart.getPlot(); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); //plot.setForegroundAlpha(0.50f); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //define colors int seriesN = dataset.getSeriesCount(); if (colorMap != null) { boolean isSerieSel = true; for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); String tmpName = serieName.replaceAll(" ", ""); tmpName = tmpName.replace('.', ' ').trim(); if (serie_selected != null && serie_selected.size() > 0) { String serieSel = serie_selected.get(tmpName).toString(); isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES") || serieSel.equalsIgnoreCase("1")) ? true : false; serieName = tmpName; } if (color != null && isSerieSel) { Color color = (Color) colorMap.get(serieName); renderer.setSeriesPaint(i, color); } else { Color color = new Color(Integer.decode(defaultColor).intValue()); renderer.setSeriesPaint(i, color); } } } // increase the margins to account for the fact that the auto-range // doesn't take into account the bubble size... NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); 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.setAutoRange(true); rangeAxis.setRange(xMin, xMax); TickUnits units = null; if (decimalXValues == false) units = (TickUnits) NumberAxis.createIntegerTickUnits(); else units = (TickUnits) NumberAxis.createStandardTickUnits(); rangeAxis.setStandardTickUnits(units); TickUnits domainUnits = null; if (decimalYValues == false) domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits(); else domainUnits = (TickUnits) NumberAxis.createStandardTickUnits(); domainAxis.setStandardTickUnits(domainUnits); rangeAxis.setLowerMargin(1.0); rangeAxis.setUpperMargin(1.0); 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()); domainAxis.setLowerMargin(1.0); domainAxis.setUpperMargin(1.0); //DecimalFormat format=(new DecimalFormat("0")); //rangeAxis.setNumberFormatOverride(format); if (legend == true) drawLegend(chart); return chart; }
From source file:net.vanosten.dings.swing.SummaryView.java
public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange, final TimeSeriesCollection numberOfEntries, final int maxTotalRange) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score", averageScore, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setPaint(Color.blue); //axis 1/*from w w w . jav a 2 s . com*/ final NumberAxis axis1 = new NumberAxis("Average Score"); axis1.setLabelPaint(Color.blue); axis1.setTickLabelPaint(Color.blue); axis1.setRange(0.0d, maxScoreRange + 1); plot.setRangeAxis(0, axis1); //axis 2 final NumberAxis axis2 = new NumberAxis("Number of Entries"); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1)); plot.setRangeAxis(1, axis2); plot.setDataset(1, numberOfEntries); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setPaint(Color.red); plot.setRenderer(1, renderer2); placeChart(chart); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.linecharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); NumberAxis rangeAxis = new NumberAxis("Kpi Values"); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);//from w w w .j a va 2s . com CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
From source file:no.met.jtimeseries.marinogram.MarinogramCurrentPlot.java
private XYPlot createPlot(TimeZone timezone, boolean plotCurrentDirection, boolean plotCurrentSpeed) { ChartPlotter plotter = new ChartPlotter(); // default setting plotter.setHeight(this.getHeight()); plotter.setWidth(this.getWidth()); plotter.setPlotDefaultProperties("", ""); Color currentSpeedColor = new Color(142, 25, 131); Color currentDirectionColor = new Color(142, 25, 131); // plot style PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Current"); PlotStyle plotStyle;/*w ww . j a v a2 s . com*/ NumberPhenomenon currentDirection = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.CurrentDirection.toString(), NumberPhenomenon.class); NumberPhenomenon currentSpeed = getOceanForecastDataModel() .getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class); if (currentSpeed == null || currentDirection == null) { return null; } currentSpeed = currentSpeed.scaling(100); double tick = (currentSpeed.getMaxValue() - currentSpeed.getMinValue()) / 2; tick = Math.ceil(tick / 10) * 10; double lowBound = Math.floor(currentSpeed.getMinValue() / (tick)) * (tick); //The minimum scale is 0 lowBound = lowBound < 0 ? 0 : lowBound; lowBound = lowBound - tick / 2; double upperBound = lowBound + tick * 4; // reference the range axis NumberAxis leftNumberAxis = new NumberAxis(); leftNumberAxis.setLabel(messages.getString("parameter.current") + " (cm/s)"); leftNumberAxis.setLabelPaint(currentSpeedColor); leftNumberAxis.setTickLabelPaint(currentSpeedColor); leftNumberAxis.setLowerBound(lowBound); leftNumberAxis.setUpperBound(upperBound); leftNumberAxis.setTickUnit(new NumberTickUnit(tick)); NumberAxis rightNumberAxis = new NumberAxis(); rightNumberAxis.setLabel(messages.getString("label.knots")); rightNumberAxis.setLabelPaint(currentSpeedColor); rightNumberAxis.setTickLabelPaint(currentSpeedColor); lowBound = lowBound / 100.0 / KNOT; upperBound = upperBound / 100.0 / KNOT; rightNumberAxis.setLowerBound(lowBound); rightNumberAxis.setUpperBound(upperBound); rightNumberAxis.setTickUnit(new NumberTickUnit(tick / 100.0 / KNOT)); NumberFormat formatter = new DecimalFormat("#0.00"); rightNumberAxis.setNumberFormatOverride(formatter); List<Date> shortTermTimeList = this.getShortTermTime(currentDirection.getTime().get(0)); //set thte plot current speed color to be transparent if show current speed is false if (!plotCurrentSpeed) { currentSpeedColor = new Color(0, 0, 0, 0); } // plot style BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f, new float[] { 2.0f, 6.0f }, 0.0f); plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(dottedStroke) .seriesColor(currentSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build(); //Draw the current direction even if plotCurrentSpeed is false (but with transparent in such a case) //for the purpose to keep the same background grid and tick label on the y-axis //no matter the wave height is shown or not plotter.addLineChart(TimeBase.SECOND, currentSpeed, plotStyle); plotter.getPlot().setRangeAxis(1, rightNumberAxis); plotter.getPlot().setOutlineVisible(true); Date minDate = shortTermTimeList.get(0); Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1); plotter.setDomainRange(minDate, maxDate); plotter.setDomainDateFormat(timezone, "HH"); // set domain range after (must) plot all the data plotter.addHourBasedDomainGridLines(); // invisible domain axis plotter.getPlot().getDomainAxis().setTickLabelsVisible(false); // add markers plotter.addDomainMarkers(shortTermTimeList, timezone, locale); if (plotCurrentDirection) { List<Date> symbolTimes = Utility.filterMinimumHourInterval(currentDirection.getTime(), 2, 1); InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes); currentDirection.filter(symbolTimesFilter); currentSpeed = null; if (plotCurrentSpeed) { currentSpeed = getOceanForecastDataModel().getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class); currentSpeed.filter(symbolTimesFilter); currentSpeed = currentSpeed.scaling(1 / 100.0 / KNOT); } plotStyle = currentStyleBuilder.seriesColor(currentDirectionColor).build(); plotter.addArrowDirectionPlot(currentDirection, currentSpeed, 2, plotStyle); } plotter.getPlot().setRangeZeroBaselineVisible(false); return plotter.getPlot(); }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder(); String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName"); NumberAxis rangeAxis = new NumberAxis(rangeAxisName); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);/*from w w w.j a v a 2 s. c o m*/ CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }