List of usage examples for org.jfree.chart.plot XYPlot setDomainAxis
public void setDomainAxis(int index, ValueAxis axis)
From source file:com.spotify.heroic.http.render.RenderUtils.java
private static JFreeChart buildChart(final String title, final XYDataset lineAndShape, final XYDataset interval, final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer) { final ValueAxis timeAxis = new DateAxis(); timeAxis.setLowerMargin(0.02);/* w w w. ja v a 2 s. c om*/ timeAxis.setUpperMargin(0.02); final NumberAxis valueAxis = new NumberAxis(); valueAxis.setAutoRangeIncludesZero(false); final XYPlot plot = new XYPlot(); plot.setDomainAxis(0, timeAxis); plot.setRangeAxis(0, valueAxis); plot.setDataset(0, lineAndShape); plot.setRenderer(0, lineAndShapeRenderer); plot.setDomainAxis(1, timeAxis); plot.setRangeAxis(1, valueAxis); plot.setDataset(1, interval); plot.setRenderer(1, intervalRenderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) { ValueAxis axis = null;//from w w w. j av a2s .c o m if (chartAxisData.getType() != null) { if (chartAxisData.getType().equals("number")) axis = createNumberAxis(chart, chartAxisData); else if (chartAxisData.getType().equals("date")) axis = createDateAxis(chart, chartAxisData); if (chartAxisData.getTickLabelFontSize() > 0) { Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT .deriveFont(chartAxisData.getTickLabelFontSize()); axis.setTickLabelFont(tickFont); } axis.setTickLabelsVisible(chartAxisData.isTickLabels()); axis.setTickMarksVisible(chartAxisData.isTickMarks()); axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels()); } XYPlot plot = chart.getXYPlot(); if (chartAxisData.isDomain()) { plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis); } else { plot.setRangeAxis(axisIndex, axis); XYDataset dataset = (XYDataset) chartAxisData.getDatasource(); plot.setRenderer(axisIndex, new StandardXYItemRenderer()); plot.setDataset(axisIndex, dataset); plot.mapDatasetToRangeAxis(axisIndex, axisIndex); } setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex)); }
From source file:org.jfree.chart.demo.CompareToPreviousYearDemo.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset2006(); XYDataset xydataset1 = createDataset2007(); DateAxis dateaxis = new DateAxis("Date"); Month month = new Month(1, 2007); Month month1 = new Month(12, 2007); dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond()); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM")); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setBaseFillPaint(Color.white); xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}", new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer); xyplot.setDomainPannable(true);//w w w. j ava 2 s . c om xyplot.setRangePannable(true); DateAxis dateaxis1 = new DateAxis(); dateaxis1.setVisible(false); xyplot.setDomainAxis(1, dateaxis1); xyplot.setDataset(1, xydataset); xyplot.mapDatasetToDomainAxis(1, 1); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setUseFillPaint(true); xylineandshaperenderer1.setBaseFillPaint(Color.white); xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}", new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00"))); xyplot.setRenderer(1, xylineandshaperenderer1); JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis(); dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:org.jfree.chart.demo.MultipleAxisDemo4.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset("March 2007", 100D, new Day(1, 3, 2007), 31); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 4", "Date", "Value", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setOrientation(PlotOrientation.VERTICAL); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy")); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.red); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setTickLabelPaint(Color.red); DateAxis dateaxis1 = new DateAxis("Date"); dateaxis1.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy")); xyplot.setDomainAxis(1, dateaxis1); xyplot.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT); NumberAxis numberaxis1 = new NumberAxis("Value"); numberaxis1.setAutoRangeIncludesZero(false); numberaxis1.setTickLabelPaint(Color.blue); xyplot.setRangeAxis(1, numberaxis1); xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); XYDataset xydataset1 = createDataset("July 2007", 1000D, new Day(1, 7, 2007), 31); xyplot.setDataset(1, xydataset1);/*from ww w . j a v a2 s. c om*/ xyplot.mapDatasetToDomainAxis(1, 1); xyplot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xyplot.setRenderer(1, xylineandshaperenderer); return jfreechart; }
From source file:com.trivadis.loganalysis.ui.ChartPanel.java
protected void removeDomainAxis(final int index, final XYPlot plot) { plot.setDomainAxis(index, null); }
From source file:com.trivadis.loganalysis.ui.ChartPanel.java
private void initializeChart() { final XYPlot plot = (XYPlot) jfreeChart.getPlot(); plot.setRangeAxis(0, null);/* ww w.j av a 2 s . com*/ plot.setDomainAxis(0, null); for (final Serie serie : chart.getSeries()) { add(serie); } if (chart.isShowOldCollections()) addMarkers(GarbageCollectionType.OLD); if (chart.isShowYoungCollections()) addMarkers(GarbageCollectionType.YOUNG); chart.addPropertyChangeListener(Chart.PROPERTY_SERIES, seriesListener); chart.addPropertyChangeListener(Chart.PROPERTY_LABEL, labelListener); chart.addPropertyChangeListener(Chart.PROPERTY_SHOW_OC, oldCollectionListener); chart.addPropertyChangeListener(Chart.PROPERTY_SHOW_YC, youngCollectionListener); }
From source file:com.trivadis.loganalysis.ui.ChartPanel.java
private void add(final Serie serie) { if (!isDisposed()) { serie.setIndex(seriesSequence.get()); final XYSeriesCollection dataset = new XYSeriesCollection(datasetProvider.getDataset(jvm, serie)); final int index = serie.getIndex(); final XYPlot plot = (XYPlot) jfreeChart.getPlot(); final Color color = getColor(index); removeDataset(index, plot);//from w w w. j av a 2 s . com plot.setDataset(index, dataset); plot.setRangeAxis(index, axis(color, serie.getYaxis().getValueProvider().getUnit())); plot.setDomainAxis(index, axis(color, serie.getXaxis().getValueProvider().getUnit())); plot.mapDatasetToDomainAxis(index, index); plot.mapDatasetToRangeAxis(index, index); plot.setRenderer(index, getRenderer(color, serie.isDotted())); seriesSequence.incrementAndGet(); } }
From source file:com.mugarov.neview.view.GraphPanel.java
public void setValues(ArrayList<DotBag> dotBags, ArrayList<Median> lines, String name) { CoordinateSeries ser;//www .ja va 2s. co m for (DotBag db : dotBags) { ser = new CoordinateSeries(db.getName()); for (Dot d : db) { ser.add(d.getCoordinates(), d.getName(), d.getScaffoldName()); // System.out.println("New dot:"+d.getLogX()+", "+d.getLogY()); } this.dotSeries.add(ser); } for (Median med : lines) { ser = new CoordinateSeries(med.getName()); ser.add(med.getStart(), med.getName(), null); ser.add(med.getEnd(), med.getName(), null); // System.out.println("New line from " + med.getStart().getX()+","+ med.getStart().getY()+" to "+med.getEnd().getX()+","+ med.getEnd().getY()); this.lineSeries.add(ser); } this.seriesCollection = new CoordinateSeriesCollection(); for (CoordinateSeries dotSeries : this.dotSeries) { this.seriesCollection.addSeries(dotSeries); } for (CoordinateSeries line : this.lineSeries) { this.seriesCollection.addSeries(line); } this.chart = ChartFactory.createXYLineChart(name, GraphPanel.XAxis, GraphPanel.YAxis, this.seriesCollection, PlotOrientation.VERTICAL, true, true, false); this.chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); ExpAxis x1Axis = new ExpAxis(GraphPanel.XAxis); ExpAxis y1Axis = new ExpAxis(GraphPanel.YAxis); NumberAxis x2Axis = new NumberAxis("Proportion to max of " + GraphPanel.XAxis); NumberAxis y2Axis = new NumberAxis("Proportion to max of " + GraphPanel.YAxis); plot.setDomainAxis(0, x1Axis); plot.setDomainAxis(1, x2Axis); plot.setRangeAxis(0, y1Axis); plot.setRangeAxis(1, y2Axis); // plot.setDomainAxis(1, yAxis); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < this.dotSeries.size(); i++) { renderer.setSeriesLinesVisible(i, false); renderer.setSeriesPaint(i, this.colorGen.get(i)); } for (int i = this.dotSeries.size(); i < this.lineSeries.size() + this.dotSeries.size(); i++) { renderer.setSeriesShapesVisible(i, false); // renderer.setSeriesPaint(i, Color.black); renderer.setSeriesPaint(i, this.colorGen.get(i - this.dotSeries.size())); } renderer.setBaseToolTipGenerator(new ItemGenerator()); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.MAGENTA); plot.setRangeGridlinePaint(Color.MAGENTA); boolean add = (this.chartPanel == null); this.chartPanel = new ChartPanel(chart); if (add) { this.content.add(this.chartPanel, BorderLayout.CENTER); this.scroll.setViewportView(this.chartPanel); } this.setBackground(Color.green); this.chartPanel.setBackground(Color.MAGENTA); this.updateUI(); }
From source file:org.operamasks.faces.render.graph.CompositeChartRenderer.java
private JFreeChart createXYCompositeChart(List<JFreeChart> subcharts, UIChart comp) { XYPlot compositePlot = new XYPlot(); compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); compositePlot.setOrientation(getChartOrientation(comp)); for (int i = 0; i < subcharts.size(); i++) { XYPlot subplot = (XYPlot) subcharts.get(i).getPlot(); compositePlot.setDataset(i, subplot.getDataset()); compositePlot.setRenderer(i, subplot.getRenderer()); if (i == 0) { compositePlot.setDomainAxis(0, subplot.getDomainAxis()); compositePlot.setRangeAxis(0, subplot.getRangeAxis()); } else {/* ww w. j a v a 2s. co m*/ int yAxisMap = getRangeAxisMap(comp, i); ValueAxis yAxis = null; if (yAxisMap == -1) { yAxisMap = 0; // map to axis zero by default } else if (yAxisMap == i) { yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot } compositePlot.setRangeAxis(i, yAxis); compositePlot.mapDatasetToRangeAxis(i, yAxisMap); } } return new JFreeChart(null, null, compositePlot, false); }
From source file:org.jfree.chart.demo.MultipleAxisDemo2.java
/** * Creates the demo chart.//from w w w. ja v a 2 s. c o m * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 2", "Time of Day", "Primary Range Axis", dataset1, 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); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); // RANGE AXIS 2 final NumberAxis yAxis2 = new NumberAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return chart; }