protected CategoryAxis configureDomainAxis(CategoryPlot plot) { final CategoryAxis domainAxis = new NoOverlapCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); domainAxis.setLabelFont(CHART_FONT); domainAxis.setTickLabelFont(CHART_FONT); return domainAxis; }
@Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart( null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); 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.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
/** * Creates a sample chart. * * @param dataset the dataset. * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart( "SubCategoryAxis Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); SubCategoryAxis axis = new SubCategoryAxis(null); axis.addSubCategory("S1"); axis.addSubCategory("S2"); axis.addSubCategory("S3"); plot.setDomainAxis(axis); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ChartUtilities.applyCurrentTheme(chart); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); return chart; }
/** Creates a trend chart. */ public JFreeChart createChart(CategoryDataset ds) { final JFreeChart chart = ChartFactory.createLineChart( null, // chart title null, // unused null, // range axis label ds, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); 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); final CategoryAxis domainAxis = new NoOverlapCategoryAxis(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()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
@Override public JFreeChart createChart(int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); // DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); bias for (Tuple<String, double[]> tuple : this.mreDblFileList) { for (int h = 0; h < 24; h++) { dataset0.addValue(tuple.getSecond()[h], tuple.getFirst(), Integer.toString(h + 1)); } } this.chart_ = ChartFactory.createLineChart( "", "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.BLUE); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); Color transparent = new Color(0, 0, 255, 0); this.chart_.setBackgroundPaint( transparent); // pink : Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93) plot.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); final CategoryAxis axisX = new CategoryAxis("Hour"); axisX.setTickLabelFont(new Font("SansSerif", Font.BOLD, 15)); plot.setDomainAxis(axisX); // final ValueAxis axis2 = new NumberAxis("Mean abs bias [agent/h]"); // plot.setRangeAxis(1, axis2); final ValueAxis axisY = plot.getRangeAxis(0); axisY.setRange(0.0, 100.0); axisY.setTickLabelFont(new Font("SansSerif", Font.BOLD, 21)); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); this.chart_.getLegend().setItemFont(new Font("SansSerif", Font.BOLD, 17)); this.chart_.getLegend().setVisible(false); return this.chart_; }
public static JFreeChart createChart() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); defaultcategorydataset.addValue(1.0D, "S1", "Category 1"); defaultcategorydataset.addValue(4D, "S1", "Category 2"); defaultcategorydataset.addValue(3D, "S1", "Category 3"); defaultcategorydataset.addValue(5D, "S1", "Category 4"); defaultcategorydataset.addValue(5D, "S1", "Category 5"); defaultcategorydataset.addValue(7D, "S1", "Category 6"); defaultcategorydataset.addValue(7D, "S1", "Category 7"); defaultcategorydataset.addValue(8D, "S1", "Category 8"); defaultcategorydataset.addValue(5D, "S2", "Category 1"); defaultcategorydataset.addValue(7D, "S2", "Category 2"); defaultcategorydataset.addValue(6D, "S2", "Category 3"); defaultcategorydataset.addValue(8D, "S2", "Category 4"); defaultcategorydataset.addValue(4D, "S2", "Category 5"); defaultcategorydataset.addValue(4D, "S2", "Category 6"); defaultcategorydataset.addValue(2D, "S2", "Category 7"); defaultcategorydataset.addValue(1.0D, "S2", "Category 8"); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); BarRenderer barrenderer = new BarRenderer(); barrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); barrenderer.setBaseItemLabelsVisible(true); CategoryPlot categoryplot = new CategoryPlot(); categoryplot.setDataset(defaultcategorydataset); categoryplot.setRenderer(barrenderer); categoryplot.setDomainAxis(new CategoryAxis("Category")); categoryplot.setRangeAxis(new NumberAxis("Value")); categoryplot.setOrientation(PlotOrientation.VERTICAL); categoryplot.setRangeGridlinesVisible(true); categoryplot.setDomainGridlinesVisible(true); DefaultCategoryDataset defaultcategorydataset1 = new DefaultCategoryDataset(); defaultcategorydataset1.addValue(9D, "T1", "Category 1"); defaultcategorydataset1.addValue(7D, "T1", "Category 2"); defaultcategorydataset1.addValue(2D, "T1", "Category 3"); defaultcategorydataset1.addValue(6D, "T1", "Category 4"); defaultcategorydataset1.addValue(6D, "T1", "Category 5"); defaultcategorydataset1.addValue(9D, "T1", "Category 6"); defaultcategorydataset1.addValue(5D, "T1", "Category 7"); defaultcategorydataset1.addValue(4D, "T1", "Category 8"); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); categoryplot.setDataset(1, defaultcategorydataset1); categoryplot.setRenderer(1, lineandshaperenderer); NumberAxis numberaxis = new NumberAxis("Axis 2"); categoryplot.setRangeAxis(1, numberaxis); DefaultCategoryDataset defaultcategorydataset2 = new DefaultCategoryDataset(); defaultcategorydataset2.addValue(94D, "R1", "Category 1"); defaultcategorydataset2.addValue(75D, "R1", "Category 2"); defaultcategorydataset2.addValue(22D, "R1", "Category 3"); defaultcategorydataset2.addValue(74D, "R1", "Category 4"); defaultcategorydataset2.addValue(83D, "R1", "Category 5"); defaultcategorydataset2.addValue(9D, "R1", "Category 6"); defaultcategorydataset2.addValue(23D, "R1", "Category 7"); defaultcategorydataset2.addValue(98D, "R1", "Category 8"); categoryplot.setDataset(2, defaultcategorydataset2); LineAndShapeRenderer lineandshaperenderer1 = new LineAndShapeRenderer(); categoryplot.setRenderer(2, lineandshaperenderer1); categoryplot.mapDatasetToRangeAxis(2, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); categoryplot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart jfreechart = new JFreeChart(categoryplot); jfreechart.setTitle("Overlaid Bar Chart"); return jfreechart; }