final JFreeChart chart = ChartFactory.createLineChart(null, // chart title ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(3)); configureRenderer(renderer); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
protected void configureRenderer(LineAndShapeRenderer renderer) { renderer.setBaseStroke(new BasicStroke(3)); for (int i = 0; i < series.size(); i++) renderer.setSeriesPaint(i, series.get(i).color); }
ChartFactory.createLineChart( chartTitle, // chart title BaseMessages.getString( PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits( NumberAxis.createIntegerTickUnits() ); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelsVisible( false ); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible( true ); renderer.setDrawOutlines( true ); renderer.setUseFillPaint( true ); renderer.setBaseFillPaint( Color.white ); renderer.setSeriesStroke( 0, new BasicStroke( 1.5f ) ); renderer.setSeriesOutlineStroke( 0, new BasicStroke( 1.5f ) ); renderer.setSeriesStroke( 1, new BasicStroke( 2.5f ) ); renderer.setSeriesOutlineStroke( 1, new BasicStroke( 2.5f ) ); renderer.setSeriesShape( 0, new Ellipse2D.Double( -3.0, -3.0, 6.0, 6.0 ) ); BufferedImage bufferedImage = chart.createBufferedImage( bounds.width, bounds.height ); ImageData imageData = ImageUtil.convertToSWT( bufferedImage );
JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(100); rangeAxis.setLowerBound(0); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(4.0f)); renderer.setBaseShapesVisible(true); ColorPalette.apply(renderer);
final JFreeChart chart = ChartFactory.createAreaChart( ); final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); domainAxis.setCategoryMargin(-((double) dataset.getColumnCount() / 10.0)); ValueAxis axis = new NumberAxis(); plot.setDataset(1, workspaceDataset); LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(4f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setSeriesStroke(1, new BasicStroke(4f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)); plot.setRenderer(1, renderer); ValueAxis rangeAxis = new NumberAxis(Messages.ProjectDiskUsage() + " (" + workspaceUnit + ")"); plot.setRangeAxis(1, rangeAxis); plot.mapDatasetToRangeAxis(1, 1); setColorForArea(plot.getRenderer(), dataset.getRowCount()>2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); renderer.setSeriesPaint(1, new Color(255,204,0)); return chart;
this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean norm rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); final ValueAxis axis2 = new NumberAxis("Mean bias [veh/h]"); plot.setRangeAxis(1, axis2); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2);
final JFreeChart chart = ChartFactory.createBarChart( chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, lineDataset); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); final ValueAxis axis2 = new NumberAxis("# executions"); axis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(1, axis2); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
public void apply(JFreeChart chart, boolean onlyOneBuild) final CategoryPlot plot = chart.getCategoryPlot(); Map<Axis, Integer> axisIds = new HashMap<>(); int axisId = 0; for (Axis axis : axes) LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, onlyOneBuild); if (onlyOneBuild) renderer.setUseOutlinePaint(true); renderer.setBaseStroke(new BasicStroke(baseStroke)); plot.setRenderer(axisId, renderer); axisIds.put(axis, axisId); axisId++; int lineIdPerAxis = plot.getDataset(axisId).getRowIndex(p.getMessage()); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(axisId); renderer.setSeriesPaint(lineIdPerAxis, p.color); renderer.setSeriesItemLabelPaint(lineIdPerAxis, p.color); renderer.setSeriesFillPaint(lineIdPerAxis, p.color); chart.getLegend().setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.WHITE);
NumberAxis numberAxis = new NumberAxis("count"); numberAxis.setAutoRange(true); numberAxis.setAutoRangeIncludesZero(false); CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setCategoryMargin(0.0); CategoryPlot plot = new CategoryPlot(dataSet, domainAxis, numberAxis, new LineAndShapeRenderer(true, false)); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, hasLegend); if (hasLegend) { chart.getLegend().setItemFont(LEGEND_FONT); chart.setBackgroundPaint(Color.white);
CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(Plot.SUPPLIER); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) { if (hasYaxisMinimum()) { ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum()); ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum()); ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero()); LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; if ("lineSimple".equalsIgnoreCase(s)) { lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary } else { lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary
protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createLineChart( _graphTitle, // title "Build Number #", // category axis label _unit, // value axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint( Color.white ); final CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = new ShiftedCategoryAxis( null ); plot.setDomainAxis( domainAxis ); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_90 ); domainAxis.setLowerMargin( 0.0 ); domainAxis.setUpperMargin( 0.0 ); domainAxis.setCategoryMargin( 0.0 ); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke( new BasicStroke( 3.0f ) ); ColorPalette.apply( renderer ); return chart; } }
CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setTickLabelsVisible(false); domainAxis.setTickMarksVisible(false); domainAxis.setAxisLineVisible(true); domainAxis.setVisible(true); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setTickLabelsVisible(true); rangeAxis.setTickMarksVisible(false); renderer = new LineRenderer3D(); else renderer = new LineAndShapeRenderer(); Integer[] sorted = data.keySet().toArray(new Integer[0]); Arrays.sort(sorted); CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset); plot.setDomainAxis(domainAxis); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBorderVisible(true); image = chart.createBufferedImage(width, targMax);
} else if ( chartDefinition.isStacked() ) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineAndShapeRenderer(); lineRenderer.setPositiveItemLabelPosition( position1 ); ItemLabelPosition position2 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT ); barRenderer.setNegativeItemLabelPosition( position2 ); lineRenderer.setNegativeItemLabelPosition( position2 ); } else if ( orientation == PlotOrientation.VERTICAL ) { ItemLabelPosition position1 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER ); barRenderer.setPositiveItemLabelPosition( position1 ); lineRenderer.setPositiveItemLabelPosition( position1 ); ItemLabelPosition position2 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER ); barRenderer.setNegativeItemLabelPosition( position2 ); lineRenderer.setNegativeItemLabelPosition( position2 ); lineRenderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); lineRenderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); lineRenderer.setStroke( JFreeChartEngine.getLineStyleStroke( chartDefinition.getLineStyle(), chartDefinition .getLineWidth() ) ); lineRenderer.setShapesVisible( chartDefinition.isMarkersVisible() ); lineRenderer.setBaseShapesFilled( chartDefinition.isMarkersVisible() );
Color lineChartColor = new Color(40, 54, 67); CategoryPlot categoryPlotModifier = chart.getCategoryPlot(); categoryPlotModifier.setOutlineVisible(false); categoryPlotModifier.setBackgroundPaint(Color.WHITE); categoryPlotModifier.getRangeAxis().setVisible(false); categoryPlotModifier.getDomainAxis().setTickMarkInsideLength(10); categoryPlotModifier.getDomainAxis().setLabelFont(new Font("SansSerif", Font.PLAIN, 1)); LineAndShapeRenderer renderer = (LineAndShapeRenderer) categoryPlotModifier.getRenderer(); renderer.setSeriesShape(0,new Ellipse2D.Double(-3, -3, 6, 6), true); renderer.setBaseFillPaint(lineChartColor, true); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); CategoryItemLabelGenerator labelGenerator = new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.00")); renderer.setBaseItemLabelGenerator(labelGenerator); renderer.setBaseItemLabelsVisible(true, true); renderer.setSeriesPaint(0, lineChartColor, true); chart.removeLegend();
static protected void configureLineChart(JFreeChart chart) { CategoryPlot plot = chart.getCategoryPlot(); final DrawingSupplier supplier = new DefaultDrawingSupplier( DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, // Draw a small diamond new Shape[] { new Polygon(new int[] {3, 0, -3, 0}, new int[] {0, 3, 0, -3}, 4) } ); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDrawingSupplier(supplier); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setStroke(new BasicStroke(2.0f)); CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); }
//Mock data DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int[] times = new int[]{1,2,3,4,5,6,7,8,9}; for ( int i = 0; i < times.length; i++ ){ dataset.addValue(times[i], "Time", "Hour" + String.valueOf(i+1)); } //create the plot CategoryPlot plot = new CategoryPlot(); //add the first dataset, and render as bar values CategoryItemRenderer renderer = new BarRenderer(); plot.setDataset(0,dataset); plot.setRenderer(0,renderer); //add the second dataset, render as lines CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset); plot.setRenderer(1, renderer2); //set axis plot.setDomainAxis(new CategoryAxis("Time")); plot.setRangeAxis(new NumberAxis("Value"));
public class Example1 { public static void main(String args[]){ DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("8/4/2012" ,7.0); data.addValue("19/04/2012",5.0); CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Population", data); JFreeChart chart = ChartFactory.createBarChart("Population","Date","Population",dataset,PlotOrientation.VERTICAL,true,true,false); ChartFrame frame = new ChartFrame("Test", chart); //Switch from a Bar Rendered to a LineAndShapeRenderer so the chart looks like an XYChart LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setBaseLinesVisible(false); //TUrn of the lines CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(0, renderer); NumberAxis numberAxis = (NumberAxis)plot.getRangeAxis(); numberAxis.setRange(new Range(0,10)); frame.pack(); frame.setVisible(true); } }
protected JFreeChart createLineChart() throws JRException ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createLineChart( (String)evaluateExpression(getChart().getTitleExpression()), (String)evaluateExpression( ((JRLinePlot)getPlot()).getCategoryAxisLabelExpression()), CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot(); JRLinePlot linePlot = (JRLinePlot)getPlot(); LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer)categoryPlot.getRenderer(); boolean isShowShapes = linePlot.getShowShapes() == null ? true : linePlot.getShowShapes().booleanValue(); boolean isShowLines = linePlot.getShowLines() == null ? true : linePlot.getShowLines().booleanValue(); lineRenderer.setBaseShapesVisible( isShowShapes );//FIXMECHART check this lineRenderer.setBaseLinesVisible( isShowLines ); configureAxis(categoryPlot.getDomainAxis(), linePlot.getCategoryAxisLabelFont(), linePlot.getCategoryAxisLabelColor(), linePlot.getCategoryAxisTickLabelFont(), linePlot.getCategoryAxisTickLabelColor(), linePlot.getCategoryAxisTickLabelMask(), configureAxis(categoryPlot.getRangeAxis(), linePlot.getValueAxisLabelFont(), linePlot.getValueAxisLabelColor(), linePlot.getValueAxisTickLabelFont(), linePlot.getValueAxisTickLabelColor(), linePlot.getValueAxisTickLabelMask(),
throw new IllegalArgumentException("Null 'orientation' argument."); CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator()); renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart);
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); if (tooltips) { renderer.setDefaultToolTipGenerator( new StandardCategoryToolTipGenerator()); renderer.setDefaultItemURLGenerator( new StandardCategoryURLGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart);