List of usage examples for org.jfree.chart.axis NumberAxis setLowerBound
public void setLowerBound(double min)
From source file:com.intel.stl.ui.main.view.PacketRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;// w ww . j a v a 2s . c o m } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new PktsRateToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes))); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:com.intel.stl.ui.main.view.DataRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;/*from w w w. ja va 2 s . c om*/ } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes)) { private static final long serialVersionUID = 4825888117284967486L; @Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { String nullXString = "null"; String nullYString = "null"; Object[] result = new Object[3]; result[0] = dataset.getSeriesKey(series).toString(); double x = dataset.getXValue(series, item); if (Double.isNaN(x) && dataset.getX(series, item) == null) { result[1] = nullXString; } else { DateFormat xDateFormat = this.getXDateFormat(); if (xDateFormat != null) { result[1] = xDateFormat.format(new Date((long) x)); } else { result[1] = this.getXFormat().format(x); } } double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = nullYString; } else { DateFormat yDateFormat = this.getYDateFormat(); if (yDateFormat != null) { result[2] = yDateFormat.format(new Date((long) y)); } else { result[2] = this.getYFormat().format(y / tickUnitSize); } } return result; } }); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:org.sonar.server.charts.jruby.TrendsChart.java
public void initSerie(Long serieId, String legend, boolean isPercent) { TimeSeries series = new TimeSeries(legend); int index = seriesById.size(); seriesById.put(serieId, series);//from ww w. j a v a2 s .c o m TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection(); timeSeriesColl.addSeries(series); plot.setDataset(index, timeSeriesColl); if (isPercent) { if (percentAxisId == -1) { NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'")); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(100.0); rangeAxis.setLowerBound(0.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); percentAxisId = index; } else { plot.mapDatasetToRangeAxis(index, percentAxisId); } } else { NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeMinimumSize(2.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesPaint(0, COLORS[index % COLORS.length]); plot.setRenderer(index, renderer); }
From source file:opensonata.dataDisplays.BaselineImage.java
private JFreeChart createChart(String inFilename, String userTitle, NssBaseline nssBaseline) { XYSeries series = new XYSeries(""); float[] baselineValues = nssBaseline.getBaselineValues(); // plot subband values for (int i = 0; i < baselineValues.length; i++) { series.add(i, baselineValues[i]); }/*from ww w. j av a2 s . c o m*/ System.err.println("HERE!!!!"); // add a final point at the end with a zero Y value, series.add(baselineValues.length, 0.0); XYDataset data = new XYSeriesCollection(series); String inFilenameBase = new File(inFilename).getName(); DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz "); String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz()); DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz "); String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz()); String mainTitle = ""; String xAxisLabel = "Subband"; String yAxisLabel = "Power"; JFreeChart chart = ChartFactory.createXYLineChart(mainTitle, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, false, // legend true, // tooltips false // urls ); String subTitle1 = "Baseline: "; if (!userTitle.equals("")) { subTitle1 += userTitle; } else { subTitle1 += inFilenameBase; } chart.addSubtitle(new TextTitle(subTitle1)); String subTitle2 = "Center Freq: " + freqString + "Bandwidth: " + bandwidthString; chart.addSubtitle(new TextTitle(subTitle2)); // move the data off of the axes // by extending the minimum axis value XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot(); double axisMarginPercent = 0.02; NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); valueAxis = (NumberAxis) plot.getDomainAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); return chart; }
From source file:de.mpg.mpdl.inge.pubman.web.statistic_charts.StatisticChartServlet.java
/** * Creates the statistic chart.//from w ww. j a v a 2 s . c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); // set the background color for the chart chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5)); plot.setDomainGridlinePaint(Color.gray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); // set the range axis to display integers only final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // disable bar outlines... StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); // set up gradient paints for series /* * GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, * 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, * 0, 0)); */ Color series1Color = new Color(0xfa, 0x80, 0x72); Color series2Color = new Color(0x64, 0x95, 0xed); renderer.setSeriesPaint(1, series1Color); renderer.setSeriesPaint(0, series2Color); // remove shadow renderer.setShadowVisible(false); // // Labels in bars /* * renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white); * renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white); */ // setCategorySummary(dataset); // rotate labels on x-axis CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:de.mpg.escidoc.pubman.statistic_charts.StatisticChartServlet.java
/** * Creates the statistic chart./*from w ww . j ava2 s .c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips? false // URLs? ); // set the background color for the chart chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5)); plot.setDomainGridlinePaint(Color.gray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); // set the range axis to display integers only final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // disable bar outlines... StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); // set up gradient paints for series /* GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); */ Color series1Color = new Color(0xfa, 0x80, 0x72); Color series2Color = new Color(0x64, 0x95, 0xed); renderer.setSeriesPaint(1, series1Color); renderer.setSeriesPaint(0, series2Color); //remove shadow renderer.setShadowVisible(false); // //Labels in bars /* renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white); renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white); */ //setCategorySummary(dataset); //rotate labels on x-axis CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
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;/*from ww w .ja va 2 s . 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:ecosim.gui.SummaryPane.java
/** * Private method to build the binning chart. * * @return A ChartPanel containing the binning chart. *//*from w ww .j a va2 s . com*/ private ChartPanel makeBinningChart() { final DefaultXYDataset binData = new DefaultXYDataset(); final NumberFormat nf = NumberFormat.getInstance(); final NumberAxis xAxis = new NumberAxis("Sequence identity criterion"); nf.setMinimumFractionDigits(2); xAxis.setLowerBound(Binning.binLevels[0]); xAxis.setUpperBound(1.0D); xAxis.setTickUnit(new NumberTickUnit(0.05D, nf)); LogAxis yAxis = new LogAxis("Number of bins"); yAxis.setBase(2.0D); yAxis.setNumberFormatOverride(NumberFormat.getInstance()); yAxis.setTickUnit(new NumberTickUnit(2.0D)); yAxis.setMinorTickMarksVisible(true); yAxis.setAutoRangeMinimumSize(4.0D); yAxis.setSmallestValue(1.0D); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < seriesColors.length; i++) { renderer.setSeriesPaint(i, seriesColors[i]); renderer.setSeriesStroke(i, new BasicStroke(seriesStroke[i])); } XYPlot plot = new XYPlot(binData, xAxis, yAxis, renderer); JFreeChart binChart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); binChart.setPadding(new RectangleInsets(0.0D, 0.0D, 0.0D, 10.0D)); LegendTitle legend = new LegendTitle(plot); legend.setMargin(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); plot.addAnnotation(new XYTitleAnnotation(0.001D, 0.999D, legend, RectangleAnchor.TOP_LEFT)); final ChartPanel pane = new ChartPanel(binChart, false, true, true, false, false); // Watch for changes to the Summary object. summary.addObserver(new Observer() { public void update(Observable o, Object obj) { Summary s = (Summary) obj; ParameterEstimate estimate = s.getEstimate(); ArrayList<BinLevel> bins = s.getBins(); if (bins.size() > 0) { double[][] values = new double[2][bins.size()]; Double low = 1.0d; for (int i = 0; i < bins.size(); i++) { BinLevel bin = bins.get(i); values[0][i] = bin.getCrit(); values[1][i] = bin.getLevel(); if (values[0][i] < low) low = values[0][i]; } binData.addSeries("sequences", values); xAxis.setLowerBound(low); if (low > 0.95d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.005D, nf)); } else if (low > 0.90d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.010D, nf)); } else if (low > 0.80d - MasterVariables.EPSILON) { xAxis.setTickUnit(new NumberTickUnit(0.025D, nf)); } if (estimate != null) { double[][] omega = new double[2][bins.size()]; double[][] sigma = new double[2][bins.size()]; double[] omegaLine = estimate.getOmega(); double[] sigmaLine = estimate.getSigma(); for (int i = 0; i < bins.size(); i++) { double crit = 1.0D - values[0][i]; double snp = s.getLength() * crit; omega[0][i] = values[0][i]; sigma[0][i] = values[0][i]; omega[1][i] = Math.pow(2.0D, snp * omegaLine[0] + omegaLine[1]); sigma[1][i] = Math.pow(2.0D, snp * sigmaLine[0] + sigmaLine[1]); } if (-1.0D * omegaLine[0] > MasterVariables.EPSILON) { binData.addSeries("omega", omega); } if (-1.0D * sigmaLine[0] > MasterVariables.EPSILON) { binData.addSeries("sigma", sigma); } } // Repaint the summary pane. pane.repaint(); } } }); return pane; }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.Chromatogram1DHeatmapViewTopComponent.java
private XYPlot createPlot(ADataset2D<IChromatogram1D, IScan> ds) { XYBlockRenderer xybr = new XYBlockRenderer(); IPaintScaleProvider ips = Lookup.getDefault().lookup(IPaintScaleProvider.class); ips.setMin(ds.getMinZ());/*from www . j av a 2 s. co m*/ ips.setMax(ds.getMaxZ()); PaintScale ps = ips.getPaintScales().get(0); xybr.setPaintScale(ps); xybr.setDefaultEntityRadius(5); xybr.setBlockWidth(0.1); xybr.setBlockAnchor(RectangleAnchor.CENTER); xybr.setBlockHeight(1.0); RTUnit rtUnit = RTUnit.SECONDS; xybr.setToolTipGenerator( new StandardXYZToolTipGenerator("{0}: @({1}, {2}) = {3}", DecimalFormat.getNumberInstance(), DecimalFormat.getNumberInstance(), DecimalFormat.getNumberInstance())); NumberAxis rt1 = new NumberAxis("Retention Time [" + rtUnit.name().toLowerCase() + "]"); NumberAxis rt2 = new NumberAxis("M/Z"); rt1.setAutoRange(false); rt1.setLowerBound(ds.getMinX()); rt1.setUpperBound(ds.getMaxX()); rt1.setRangeWithMargins(ds.getMinX(), ds.getMaxX()); rt2.setFixedAutoRange(ds.getMaxX() - ds.getMinX()); rt2.setAutoRange(false); rt2.setLowerBound(ds.getMinY()); rt2.setUpperBound(ds.getMaxY()); rt2.setFixedAutoRange(ds.getMaxY() - ds.getMinY()); rt2.setRangeWithMargins(ds.getMinY(), ds.getMaxY()); XYPlot heatmapPlot = new XYPlot(ds, rt1, rt2, xybr); heatmapPlot.setDomainPannable(true); heatmapPlot.setRangePannable(true); return heatmapPlot; }
From source file:com.mothsoft.alexis.web.ChartServlet.java
private void doLineGraph(final HttpServletRequest request, final HttpServletResponse response, final String title, final String[] dataSetIds, final Integer width, final Integer height, final Integer numberOfSamples) throws ServletException, IOException { final DataSetService dataSetService = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()).getBean(DataSetService.class); final OutputStream out = response.getOutputStream(); response.setContentType("image/png"); response.setHeader("Cache-Control", "max-age: 5; must-revalidate"); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); final DateAxis dateAxis = new DateAxis(title != null ? title : "Time"); final DateTickUnit unit = new DateTickUnit(DateTickUnit.HOUR, 1); final DateFormat chartFormatter = new SimpleDateFormat("ha"); dateAxis.setDateFormatOverride(chartFormatter); dateAxis.setTickUnit(unit);/*from w ww . ja v a 2 s .c o m*/ dateAxis.setLabelFont(DEFAULT_FONT); dateAxis.setTickLabelFont(DEFAULT_FONT); if (numberOfSamples > 12) { dateAxis.setTickLabelFont( new Font(DEFAULT_FONT.getFamily(), Font.PLAIN, (int) (DEFAULT_FONT.getSize() * .8))); } final NumberAxis yAxis = new NumberAxis("Activity"); final StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); int colorCounter = 0; if (dataSetIds != null) { for (final String dataSetIdString : dataSetIds) { final Long dataSetId = Long.valueOf(dataSetIdString); final DataSet dataSet = dataSetService.get(dataSetId); // go back for numberOfSamples, but include current hour final Calendar calendar = new GregorianCalendar(); calendar.add(Calendar.HOUR_OF_DAY, -1 * (numberOfSamples - 1)); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); final Timestamp startDate = new Timestamp(calendar.getTimeInMillis()); calendar.add(Calendar.HOUR_OF_DAY, numberOfSamples); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); final Timestamp endDate = new Timestamp(calendar.getTimeInMillis()); logger.debug(String.format("Generating chart for period: %s to %s", startDate.toString(), endDate.toString())); final List<DataSetPoint> dataSetPoints = dataSetService .findAndAggregatePointsGroupedByUnit(dataSetId, startDate, endDate, TimeUnits.HOUR); final boolean hasData = addSeries(seriesCollection, dataSet.getName(), dataSetPoints, startDate, numberOfSamples, renderer); if (dataSet.isAggregate()) { renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1, Color.BLACK); } else if (hasData) { renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1, PAINTS[colorCounter++ % PAINTS.length]); } else { renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1, Color.LIGHT_GRAY); } } } final XYPlot plot = new XYPlot(seriesCollection, dateAxis, yAxis, renderer); // create the chart... final JFreeChart chart = new JFreeChart(plot); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... plot.setBackgroundPaint(new Color(253, 253, 253)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(DEFAULT_FONT); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0.00d); ChartUtilities.writeChartAsPNG(out, chart, width, height); }