// Create an XY Line chart XYSeries series = new XYSeries("Random Data"); series.add(1.0, 500.2); series.add(10.0, 694.1); XYSeriesCollection data = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // Create an NumberAxis NumberAxis xAxis = new NumberAxis(); xAxis.setTickUnit(new NumberTickUnit(2)); // Assign it to the chart XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(xAxis);
/** * Sets the domain axis for the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axis the new axis ({@code null} permitted). * * @see #getDomainAxis() * @see #setDomainAxis(int, ValueAxis) */ public void setDomainAxis(ValueAxis axis) { setDomainAxis(0, axis); }
/** * Sets the domain axis for the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axis the new axis (<code>null</code> permitted). * * @see #getDomainAxis() * @see #setDomainAxis(int, ValueAxis) */ public void setDomainAxis(ValueAxis axis) { setDomainAxis(0, axis); }
/** * Sets a domain axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * * @see #getDomainAxis(int) * @see #setRangeAxis(int, ValueAxis) */ public void setDomainAxis(int index, ValueAxis axis) { setDomainAxis(index, axis, true); }
/** * Sets a domain axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the axis index. * @param axis the axis ({@code null} permitted). * * @see #getDomainAxis(int) * @see #setRangeAxis(int, ValueAxis) */ public void setDomainAxis(int index, ValueAxis axis) { setDomainAxis(index, axis, true); }
chart.getXYPlot().setDomainAxis(0, new DateAxis()); chart.getXYPlot().setDomainAxis(1, new DateAxis()); chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));
XYPlot plot = chart.getXYPlot(); DateAxis axis = new DateAxis(); plot.setDomainAxis(axis); axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solution) { XYPlot plot = new XYPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem); plot.setDataset(0, problem); plot.setRenderer(0, problemRenderer); XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments); plot.setDataset(1, shipments); plot.setRenderer(1, shipmentsRenderer); if (solution != null) { XYItemRenderer solutionRenderer = getRouteRenderer(solution); plot.setDataset(2, solution); plot.setRenderer(2, solutionRenderer); } NumberAxis xAxis = new NumberAxis(); NumberAxis yAxis = new NumberAxis(); if (boundingBox == null) { xAxis.setRangeWithMargins(getDomainRange(problem)); yAxis.setRangeWithMargins(getRange(problem)); } else { xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX)); yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY)); } plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); return plot; }
ChartPanel chartPanel1 = createDemoPanel("Chart1"); ChartPanel chartPanel2 = createDemoPanel("Chart2"); XYPlot plot1 = chartPanel1.getChart().getXYPlot(); XYPlot plot2 = chartPanel2.getChart().getXYPlot(); plot2.setDomainAxis(plot1.getDomainAxis()); chartPanel1.setLayout(new GridLayout()); chartPanel2.setLayout(new GridLayout()); JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, chartPanel1, chartPanel2); add(splitPane, BorderLayout.CENTER);
@Override public void propertyChange(PropertyChangeEvent evt) { ValueAxis oldAxis = chart.getXYPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis((Boolean) evt.getNewValue(), oldAxis, true); chart.getXYPlot().setDomainAxis(newAxis); } });
private static XYPlot createPlot(ValueAxis domainAxis, ValueAxis... rangesAxis) { XYPlot plot = new XYPlot(); plot.setDomainAxis(domainAxis); int i = 0; for (ValueAxis rangeAxis : rangesAxis) { plot.setRangeAxis(i++, rangeAxis); } return defaultPlot(plot); }
JFreeChart chart1 = ChartFactory.createXYLineChart(); JFreeChart chart2 = ChartFactory.createXYLineChart(); XYPlot plot1 = chart1.getXYPlot(); XYPlot plot2 = chart2.getXYPlot(); plot2.setDomainAxis(plot1.getDomainAxis());
@Override public void propertyChange(PropertyChangeEvent evt) { ValueAxis oldAxis = chart.getXYPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis((Boolean) evt.getNewValue(), oldAxis, true); chart.getXYPlot().setDomainAxis(newAxis); } });
public void createThroughputChart( HistoricSamples samples, String dataId ) throws IOException { XYPlot xyplot = newPlot( samples.getThroughput( dataId ), "chronos.label.throughput.requests", true ); xyplot.setRangeAxisLocation( AxisLocation.BOTTOM_OR_LEFT ); xyplot.getRenderer().setSeriesPaint( 0, Color.GREEN ); String timeLabel = bundle.getString( "chronos.label.throughput.historytime" ); DateAxis timeAxis = ChartUtil.createTimeAxis( timeLabel, new SimpleDateFormat() ); xyplot.setDomainAxis( timeAxis ); JFreeChart chart = new JFreeChart( bundle.getString( "chronos.label.throughput" ), xyplot ); renderer.renderChart( "history-throughput-" + dataId, chart ); }
private JFreeChart createChart(TimeTableXYDataset chartData) { JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Dogs and Cats", "Time", "Count", chartData, PlotOrientation.VERTICAL, false, true, false); DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); dateAxis.setTickLabelFont(dateAxis.getTickLabelFont().deriveFont(20f)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(dateAxis); return chart; }
private void configureDomainAxis(int index, String nameX, int dataType) { ValueAxis axis = createAxis(dataType); axis.setAutoRange(true); axis.setAutoRangeMinimumSize(2); axis.setLabel(nameX); Font axisFont = axis.getLabelFont().deriveFont(Font.BOLD); axis.setLabelFont(axisFont); xyPlot.setDomainAxis(index, axis); }
public XYChartBuilder setDateXAxis(final boolean showAxisValues) { xAxis = new DateAxis(); ((DateAxis) xAxis).setTickMarkPosition(DateTickMarkPosition.MIDDLE); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setVisible(showAxisValues); plot.setDomainAxis(xAxis); return this; }
private void updateScalingOfXAxis() { final boolean logScaled = scatterPlotModel.xAxisLogScaled; final ValueAxis oldAxis = getPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis(logScaled, oldAxis, false); oldAxis.removeChangeListener(domainAxisChangeListener); newAxis.addChangeListener(domainAxisChangeListener); getPlot().setDomainAxis(newAxis); finishScalingUpdate(xAxisRangeControl, newAxis, oldAxis); }
private void updateScalingOfXAxis() { final boolean logScaled = scatterPlotModel.xAxisLogScaled; final ValueAxis oldAxis = getPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis(logScaled, oldAxis, false); oldAxis.removeChangeListener(domainAxisChangeListener); newAxis.addChangeListener(domainAxisChangeListener); getPlot().setDomainAxis(newAxis); finishScalingUpdate(xAxisRangeControl, newAxis, oldAxis); }
public void setLogScale(boolean range, boolean domain) { if( domain ) { NumberAxis axis = (NumberAxis)plot.getDomainAxis(); axis = new LogarithmicAxis(axis.getLabel()); plot.setDomainAxis(axis); } if( range ) { NumberAxis axis = (NumberAxis)plot.getRangeAxis(); axis = new LogarithmicAxis(axis.getLabel()); plot.setRangeAxis(axis); } }