List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java
private JPanel getUsedPanel() { DateAxis domain = new DateAxis(Translation.getTranslation("stats_information_card.date")); TimeSeriesCollection series = new TimeSeriesCollection(); NumberAxis axis = new NumberAxis(Translation.getTranslation("stats_information_card.bandwidth")); series.addSeries(availableBandwidthSeries); series.addSeries(usedBandwidthSeries); series.addSeries(averageBandwidthSeries); XYItemRenderer renderer = new StandardXYItemRenderer(); XYPlot plot = new XYPlot(series, domain, axis, renderer); JFreeChart graph = new JFreeChart(plot); ChartPanel cp = new ChartPanel(graph); FormLayout layout = new FormLayout("3dlu, fill:pref:grow, 3dlu", "3dlu, pref , 3dlu, pref, 3dlu, fill:pref:grow, 3dlu"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); CellConstraints cc = new CellConstraints(); JPanel p = buildUsedStatsControlPanel(); builder.add(p, cc.xy(2, 2));//from w ww .j a v a 2s.c o m builder.addSeparator(null, cc.xyw(1, 4, 3)); builder.add(cp, cc.xy(2, 6)); return builder.getPanel(); }
From source file:net.sourceforge.processdash.ev.ui.ScheduleBalancingDialog.java
private void addChartToPanel(JPanel panel, int gridY) { // create a dataset for displaying schedule data chartData = new ChartData(); updateChart();//from w w w . ja va 2s .c o m // customize a renderer for displaying schedules XYBarRenderer renderer = new XYBarRenderer(); renderer.setUseYInterval(true); renderer.setBaseToolTipGenerator(chartData); renderer.setDrawBarOutline(true); // use an inverted, unadorned numeric Y-axis NumberAxis yAxis = new NumberAxis(); yAxis.setInverted(true); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setUpperMargin(0); // use a Date-based X-axis DateAxis xAxis = new DateAxis(); // create an XY plot to display the data XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(false); plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message")); // create a chart and a chart panel JFreeChart chart = new JFreeChart(plot); chart.removeLegend(); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setInitialDelay(50); chartPanel.setDismissDelay(60000); chartPanel.setMinimumDrawHeight(40); chartPanel.setMinimumDrawWidth(40); chartPanel.setMaximumDrawHeight(3000); chartPanel.setMaximumDrawWidth(3000); chartPanel.setPreferredSize(new Dimension(300, gridY * 25)); // add the chart to the dialog content pane GridBagConstraints c = new GridBagConstraints(); c.gridy = gridY; c.gridwidth = 4; c.weightx = 2; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 0, 0, 0); panel.add(chartPanel, c); // retrieve the colors used for each chart bar, and register those // colors with the schedule rows so they can act as a legend for (int i = scheduleRows.size(); i-- > 0;) { ScheduleTableRow oneRow = scheduleRows.get(i); oneRow.addColoredIcon(renderer.lookupSeriesPaint(i)); } }
From source file:OAT.ui.util.UiUtil.java
/** * Returns a chart object./* w w w. ja v a 2 s. c o m*/ * * @param title * @param timeAxisLabel * @param valueAxisLabel * @param dataSet * @param timeline * @param theme * @param legend * @return */ public static Chart createTimeBasedChart(String title, String timeAxisLabel, String valueAxisLabel, ChartDataset dataSet, Timeline timeline, DefaultTheme theme, boolean legend) { //x-axis DateAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setTimeline(timeline); //timeAxis.setTimeZone(dataSet.getTimeline().timeZone); if (dataSet instanceof TickChart || dataSet instanceof ContractChart) { timeAxis.setStandardTickUnits(createSimpleTimeTickUnits()); //timeAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, 30, // new SimpleDateFormat("HH:mm")), // false, true); } //y-axis NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeStickyZero(false); valueAxis.setAutoRangeIncludesZero(false); //renderer OHLCRenderer renderer = new OHLCRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); //Primary plot XYPlot plot = new XYPlot(dataSet, timeAxis, valueAxis, renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT, false); Chart chart = new Chart(title, Chart.DEFAULT_TITLE_FONT, plot, legend); theme.apply(chart); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createTimeSeriesChart2(XYDataset dataset) { DateAxis timeAxis = new DateAxis(xAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from ww w. ja v a 2 s. c om*/ NumberAxis valueAxis = new NumberAxis(yAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Creates a sample chart.//from w w w . j a v a 2 s .c o m * * @return a sample chart. */ private JFreeChart createChart() { final XYSeriesCollection primaryJFreeColl = new XYSeriesCollection(); final XYSeries left1 = new XYSeries("Left 1"); left1.add(1, 2); left1.add(2.8, 5.9); left1.add(3, null); left1.add(3.4, 2); left1.add(5, -1); left1.add(7, 1); primaryJFreeColl.addSeries(left1); final XYSeriesCollection secondaryJFreeColl = new XYSeriesCollection(); final XYSeries right1 = new XYSeries("Right 1"); right1.add(3.5, 2.2); right1.add(1.2, 1.3); right1.add(5.7, 4.1); right1.add(7.5, 7.4); secondaryJFreeColl.addSeries(right1); final NumberAxis xAxis = new NumberAxis("X"); xAxis.setAutoRangeIncludesZero(false); xAxis.setAutoRangeStickyZero(false); final NumberAxis primaryYAxis = new NumberAxis("Y1"); primaryYAxis.setAutoRangeIncludesZero(false); primaryYAxis.setAutoRangeStickyZero(false); // create plot final XYItemRenderer y1Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); y1Renderer.setSeriesPaint(0, Color.blue); y1Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); final XYPlot xyPlot = new XYPlot(primaryJFreeColl, xAxis, primaryYAxis, y1Renderer); // 2nd y-axis final NumberAxis secondaryYAxis = new NumberAxis("Y2"); secondaryYAxis.setAutoRangeIncludesZero(false); secondaryYAxis.setAutoRangeStickyZero(false); xyPlot.setRangeAxis(1, secondaryYAxis); xyPlot.setDataset(1, secondaryJFreeColl); xyPlot.mapDatasetToRangeAxis(1, 1); xyPlot.mapDatasetToDomainAxis(1, 1); final XYItemRenderer y2Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); y2Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); xyPlot.setRenderer(1, y2Renderer); // set some fixed y-dataranges and remember them // because default chartPanel.autoRangeBoth() // would destroy them ValueAxis axis = xyPlot.getRangeAxis(); this.primYMinMax[0] = -5; this.primYMinMax[1] = 15; axis.setLowerBound(this.primYMinMax[0]); axis.setUpperBound(this.primYMinMax[1]); axis = xyPlot.getRangeAxis(1); this.secondYMinMax[0] = -1; this.secondYMinMax[1] = 10; axis.setLowerBound(this.secondYMinMax[0]); axis.setUpperBound(this.secondYMinMax[1]); // Title + legend final String title = "To pan in zoom mode hold right mouse pressed"; final JFreeChart ret = new JFreeChart(title, null, xyPlot, true); final TextTitle textTitle = new TextTitle("(but you can only pan if the chart was zoomed before)"); ret.addSubtitle(textTitle); return ret; }
From source file:org.jstockchart.plot.TimeseriesPlot.java
private XYPlot createPricePlot() { Font axisFont = new Font("Arial", 0, 12); Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); PriceArea priceArea = timeseriesArea.getPriceArea(); Color averageColor = new Color(243, 182, 117); priceArea.setAverageColor(averageColor); priceArea.setPriceColor(Color.BLUE); TimeSeriesCollection priceDataset = new TimeSeriesCollection(); priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries()); if (priceArea.isAverageVisible()) { priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries()); }/*from w w w .j a v a 2 s .com*/ CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis(); logicPriceAxis.setTickCount(7); CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks()); priceAxis.setShowUD(true); priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); priceAxis.setTickMarksVisible(false); XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false); priceAxis.setUpperBound(logicPriceAxis.getUpperBound()); priceAxis.setLowerBound(logicPriceAxis.getLowerBound()); priceAxis.setAxisLineVisible(false); priceAxis.setTickLabelFont(axisFont); priceRenderer.setSeriesPaint(0, priceArea.getPriceColor()); priceRenderer.setSeriesPaint(1, priceArea.getAverageColor()); CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks()); rateAxis.setShowUD(true); rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); rateAxis.setTickMarksVisible(false); ; rateAxis.setTickLabelFont(axisFont); rateAxis.setAxisLineVisible(false); rateAxis.setUpperBound(logicPriceAxis.getUpperBound()); rateAxis.setLowerBound(logicPriceAxis.getLowerBound()); XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer); plot.setBackgroundPaint(priceArea.getBackgroudColor()); plot.setOrientation(priceArea.getOrientation()); plot.setRangeAxisLocation(priceArea.getPriceAxisLocation()); plot.setRangeMinorGridlinesVisible(false); Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 2.0f, 2.0f }, 1.0f); plot.setRangeGridlineStroke(gridLineStroke); plot.setDomainGridlineStroke(gridLineStroke); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setOutlineVisible(true); plot.setOutlineStroke(outLineStroke); plot.setOutlinePaint(Color.BLACK); if (priceArea.isRateVisible()) { plot.setRangeAxis(1, rateAxis); plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation()); plot.setDataset(1, null); plot.mapDatasetToRangeAxis(1, 1); } if (priceArea.isMarkCentralValue()) { Number centralPrice = logicPriceAxis.getCentralValue(); if (centralPrice != null) { plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(), new BasicStroke())); } } return plot; }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
private XYPlot createSnpIntervalHistogramPlot(final List<? extends RealValuedBasePairInterval> intervals, final HighlightedSnpInterval visualInterval, ValueAxis domainAxis, ValueAxis rangeAxis) { XYDataset dataset = this.createSnpIntervalHistogramData(intervals, visualInterval); XYBarRenderer renderer = new XYBarRenderer() { /**//from w w w . j a v a 2 s . co m * every serializable is supposed to have one of these */ private static final long serialVersionUID = -7907956889918704042L; /** * {@inheritDoc} */ @Override public Paint getItemPaint(int row, int column) { // Always render in black return Color.BLACK; } }; renderer.setShadowVisible(false); renderer.setDrawBarOutline(false); // renderer.setGradientPaintTransformer(null); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setMargin(0.0); return new XYPlot(dataset, domainAxis, rangeAxis, renderer); }
From source file:org.drools.planner.benchmark.statistic.calculatecount.CalculateCountStatistic.java
private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (Map.Entry<String, CalculateCountStatisticListener> listenerEntry : statisticListenerMap.entrySet()) { String configName = listenerEntry.getKey(); XYSeries series = new XYSeries(configName); List<CalculateCountStatisticPoint> statisticPointList = listenerEntry.getValue() .getStatisticPointList(); for (CalculateCountStatisticPoint statisticPoint : statisticPointList) { long timeMillisSpend = statisticPoint.getTimeMillisSpend(); long calculateCountPerSecond = statisticPoint.getCalculateCountPerSecond(); series.add(timeMillisSpend, calculateCountPerSecond); }//w w w . j av a2s . c o m seriesCollection.addSeries(series); } NumberAxis xAxis = new NumberAxis("Time millis spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Calculate count per second"); yAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(baseName + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "CalculateCountStatistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } return " <img src=\"" + graphStatisticFile.getName() + "\"/>\n"; }
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 w w . j av 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); }
From source file:org.jfree.chart.demo.StackedXYAreaChartDemo.java
/** * Creates a chart./*from w ww . j av a 2s. c o m*/ * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(final TableXYDataset dataset) { final StandardXYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd-MMM-yyyy", Locale.UK), NumberFormat.getInstance()); final DateAxis xAxis = new DateAxis("Domain (X)"); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); final NumberAxis yAxis = new NumberAxis("Range (Y)"); yAxis.setAutoRangeIncludesZero(true); final StackedXYAreaRenderer renderer = new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, null); renderer.setOutline(true); renderer.setSeriesPaint(0, new Color(255, 255, 206)); renderer.setSeriesPaint(1, new Color(206, 230, 255)); renderer.setSeriesPaint(2, new Color(255, 230, 230)); renderer.setShapePaint(Color.gray); renderer.setShapeStroke(new BasicStroke(0.5f)); renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6)); final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); return chart; }