List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer
public XYLineAndShapeRenderer(boolean lines, boolean shapes)
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createTimeSeriesChart(XYDataset dataset) { DateAxis timeAxis = new DateAxis(xAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/* w w w .j a va 2s. co m*/ 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:org.moeaframework.analysis.plot.Plot.java
/** * If the chart has not yet been initialized, creates a chart for XY data. * If the chart is already initialized, checks if the chart is for XY data. * /*from w w w .j a va 2 s .c o m*/ * @throws FrameworkException if the chart does not support XY data */ private void createXYPlot() { if (chart == null) { NumberAxis xAxis = new NumberAxis(""); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(); plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(); XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartFactory.getChartTheme().apply(chart); } else if (!(chart.getPlot() instanceof XYPlot)) { throw new FrameworkException("Can not combine XY plot and categorial plot"); } }
From source file:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java
private static ChartPanel buildChartPanel(final Instances dataSet, final int xidx, final int yidx, final int coloridx, final boolean asSerie) { final XYSeriesCollection data = new XYSeriesCollection(); final Map<Integer, List<Instance>> filteredInstances = new HashMap<Integer, List<Instance>>(); final int classIndex = dataSet.classIndex(); if (classIndex < 0) { final XYSeries series = new XYSeries("Serie", false); for (int i = 0; i < dataSet.numInstances(); i++) { series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); }//from www .java 2 s.com data.addSeries(series); } else { final Set<String> pvs = WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex); int p = 0; for (final String pv : pvs) { final XYSeries series = new XYSeries(pv, false); for (int i = 0; i < dataSet.numInstances(); i++) { if (dataSet.instance(i).stringValue(classIndex).equals(pv)) { if (!filteredInstances.containsKey(p)) { filteredInstances.put(p, new ArrayList<Instance>()); } filteredInstances.get(p).add(dataSet.instance(i)); series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); } } data.addSeries(series); p++; } } final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title dataSet.attribute(xidx).name(), // x axis label dataSet.attribute(yidx).name(), // y axis label data, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); final XYToolTipGenerator gen = new XYToolTipGenerator() { @Override public String generateToolTip(final XYDataset dataset, final int series, final int item) { if (classIndex < 0) { return InstanceFormatter.htmlFormat(dataSet.instance(item), true); } else { return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true); } } }; int nbSeries; if (classIndex < 0) { nbSeries = 1; } else { nbSeries = filteredInstances.keySet().size(); } final XYItemRenderer renderer = new XYLineAndShapeRenderer(asSerie, true) { /** */ private static final long serialVersionUID = 1L; @Override public Paint getItemPaint(final int row, final int col) { //System.out.println(row+" "+col); if (classIndex < 0) { final double v = dataSet.instance(col).value(coloridx); final double[] minmax = WekaDataStatsUtil.getMinMaxForAttributeAsArrayOfDoubles(dataSet, coloridx); final double rated = (v - minmax[0]) / (minmax[1] - minmax[0]); System.out.println("rated -> " + rated + " min=" + minmax[0] + "max=" + minmax[1]); final int colorIdx = (int) Math.round((ColorHelper.YlGnBu_9_COLORS.length - 1) * rated); //System.out.println(minmax[0]+" "+minmax[1]+" "+v+" "+rated+" "+colorIdx); return ColorHelper.YlGnBu_9_COLORS[colorIdx]; } else return super.getItemPaint(row, col); } }; xyPlot.setRenderer(renderer); for (int i = 0; i < nbSeries; i++) { renderer.setSeriesToolTipGenerator(i, gen); } return new ChartPanel(chart); }
From source file:net.sf.maltcms.common.charts.ui.XYChartTopComponent.java
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed final String renderer = (String) jComboBox1.getSelectedItem(); Task t = RequestProcessor.getDefault().create(new Runnable() { @Override/* w ww. j av a 2s .c o m*/ public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.setEnabled(false); panel.invalidate(); panel.validate(); } }); int nrenderer = panel.getChart().getXYPlot().getRendererCount(); XYPlot plot = panel.getChart().getXYPlot(); int ndatasets = panel.getChart().getXYPlot().getDatasetCount(); List<Shape> shapes = new LinkedList<>(); for (int i = 0; i < nrenderer; i++) { for (int j = 0; j < plot.getDataset(i).getSeriesCount(); j++) { XYDataset d = plot.getDataset(i); for (int k = 0; k < d.getSeriesCount(); k++) { Shape s = plot.getRendererForDataset(d).getSeriesShape(k); shapes.add(s); } } } switch (renderer) { case "Line And Shape": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(true, true)); break; case "Line": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(true, false)); break; case "Shape": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(false, true)); break; case "Area": panel.getChart().getXYPlot().setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA)); break; case "Area w/ Shapes": panel.getChart().getXYPlot().setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES)); break; } panel.getChart().getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator( "%2.5f", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance())); int shapeIndex = 0; for (int i = 0; i < nrenderer; i++) { for (int j = 0; j < plot.getDataset(i).getSeriesCount(); j++) { XYDataset d = plot.getDataset(i); for (int k = 0; k < d.getSeriesCount(); k++) { plot.getRendererForDataset(d).setSeriesShape(k, shapes.get(shapeIndex)); shapeIndex++; } } } customizeChart(panel); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.setEnabled(true); panel.invalidate(); panel.validate(); } }); } }); t.addTaskListener(new XYChartLoaderTaskListener()); RequestProcessor.getDefault().post(t); }
From source file:web.diva.server.unused.ProfilePlotGenerator.java
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings.// w w w .ja v a2 s .c o m * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ private JFreeChart createXYLineChart(String title, String[] columnIds, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } Font f = new Font("ARIAL", 1, 7); // NumberAxis xAxis = new NumberAxis(xAxisLabel); // xAxis.setAutoRangeIncludesZero(false); SymbolAxis xAxis = new SymbolAxis("", columnIds); xAxis.setAxisLineVisible(false); xAxis.setGridBandsVisible(false); xAxis.setVerticalTickLabels(true); xAxis.setVisible(true); xAxis.setTickLabelPaint(shadowColor); xAxis.setTickLabelFont(f); xAxis.setFixedDimension(51.0); boolean auto = xAxis.getAutoRangeIncludesZero(); xAxis.setAutoRangeIncludesZero(true ^ auto); xAxis.setTickUnit(new NumberTickUnit(1)); xAxis.setRange(0, columnIds.length); // NumberAxis yAxis = new NumberAxis(yAxisLabel); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(true ^ auto); yAxis.setAxisLineVisible(false); yAxis.setTickLabelFont(f); yAxis.setTickLabelPaint(Color.BLUE); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseShapesVisible(false); renderer.setPaint(shadowColor); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(shadowColor); plot.setRangeGridlinePaint(shadowColor); plot.setOutlinePaint(Color.BLUE); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // plot.setRenderer(renderer); plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); plot.setDomainAxis(xAxis); if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
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()); }/*ww w.j a v a2 s . c o m*/ 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.projectforge.plugins.liquidityplanning.LiquidityChartBuilder.java
/** * @param forecast/* w w w . j a v a 2 s. co m*/ * @param settings (next days) * @return */ public JFreeChart createBarChart(final LiquidityForecast forecast, final LiquidityForecastSettings settings) { Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500); final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays()); final TimeSeries accumulatedSeriesExpected = new TimeSeries( I18n.getString("plugins.liquidityplanning.forecast.expected")); final TimeSeries creditSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.common.credit")); final TimeSeries debitSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.common.debit")); double accumulatedExpected = settings.getStartAmount().doubleValue(); final DayHolder dh = new DayHolder(); final Date lower = dh.getDate(); for (int i = 0; i < settings.getNextDays(); i++) { final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); if (i > 0) { accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue(); } accumulatedSeriesExpected.add(day, accumulatedExpected); creditSeries.add(day, cashFlow.getCreditsExpected()[i].doubleValue()); debitSeries.add(day, cashFlow.getDebitsExpected()[i].doubleValue()); dh.add(Calendar.DATE, 1); } dh.add(Calendar.DATE, -1); final XYChartBuilder cb = new XYChartBuilder(ChartFactory.createXYBarChart(null, null, false, null, null, PlotOrientation.VERTICAL, false, false, false)); int counter = 0; final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection(); xyDataSeries.addSeries(accumulatedSeriesExpected); final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, true); lineRenderer.setSeriesPaint(0, cb.getRedMarker()); lineRenderer.setSeriesVisibleInLegend(0, true); cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries).setStrongStyle(lineRenderer, false, accumulatedSeriesExpected); final TimeSeriesCollection cashflowSet = new TimeSeriesCollection(); cashflowSet.addSeries(debitSeries); cashflowSet.addSeries(creditSeries); final XYBarRenderer barRenderer = new XYBarRenderer(.2); barRenderer.setSeriesPaint(0, cb.getGreenFill()); barRenderer.setSeriesPaint(1, cb.getRedFill()); barRenderer.setShadowVisible(false); cb.setRenderer(counter, barRenderer).setDataset(counter++, cashflowSet); cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null); return cb.getChart(); }
From source file:umontreal.iro.lecuyer.charts.YListSeriesCollection.java
/** * Creates a new <TT>YListSeriesCollection</TT> instance with default * parameters and given data series. The matrix <TT>data</TT> represents a * set of plotting data. More specifically, each row of <TT>data</TT> * represents a <SPAN CLASS="MATH"><I>y</I></SPAN>-coordinates set. * Position in the vector will form the <SPAN CLASS="MATH"><I>x</I></SPAN>-coordinates. Indeed, for each serie * <SPAN CLASS="MATH"><I>i</I></SPAN>, the value <TT>data</TT><SPAN CLASS="MATH">[<I>i</I>][<I>j</I>]</SPAN> corresponds to the point * // www . ja v a2 s . c o m * <SPAN CLASS="MATH">(<I>j</I> + 1,<TT>data</TT>[<I>j</I>])</SPAN> on the chart. * However, only <SPAN CLASS="textit">the first</SPAN> <TT>numPoints</TT> of <TT>data</TT> will * be considered for each series of points. * * @param data series of point sets. * * @param numPoints Number of points to plot * */ public YListSeriesCollection(double[][] data, int numPoints) { renderer = new XYLineAndShapeRenderer(true, false); seriesCollection = new XYSeriesCollection(); XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection; for (int i = 0; i < data.length; i++) { XYSeries serie = new XYSeries(" "); for (int j = 0; j < numPoints; j++) serie.add(j + 1, data[i][j]); tempSeriesCollection.addSeries(serie); } final int s = tempSeriesCollection.getSeriesCount(); // set default colors for (int i = 0; i < s; i++) { renderer.setSeriesPaint(i, getDefaultColor(i)); } // set default plot style plotStyle = new String[s]; marksType = new String[s]; dashPattern = new String[s]; for (int i = 0; i < s; i++) { marksType[i] = " "; plotStyle[i] = "smooth"; dashPattern[i] = "solid"; } }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
/***************************************** INDIVIDUAIS **************************************************/ public ChartPanel precisionrecall(int index) { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Precision Recall", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetprecision(index), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from w w w . j av a 2 s. c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:pisco.batch.visu.BatchingChartFactory.java
public static XYPlot createWFlowtimePlot(Batch[] batches) { ValueAxis timeAxis = new DateAxis(""); NumberAxis valueAxis = new NumberAxis("Cum. WFlow"); valueAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(createWFlowtimeDataset(batches), timeAxis, valueAxis, null); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); renderer.setBaseToolTipGenerator(new WFlowLabelToolTipGenerator(batches)); plot.setRenderer(renderer);/*from w ww . j ava 2 s. co m*/ return plot; }