List of usage examples for org.jfree.chart.plot CategoryPlot setRenderer
public void setRenderer(CategoryItemRenderer renderer)
From source file:org.jfree.chart.demo.StackedBarChartDemo5.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 5", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer(); KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1"); keytogroupmap.mapKeyToGroup("S1", "G1"); keytogroupmap.mapKeyToGroup("S2", "G1"); keytogroupmap.mapKeyToGroup("S3", "G2"); keytogroupmap.mapKeyToGroup("S4", "G3"); groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap); groupedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); groupedstackedbarrenderer.setBaseItemLabelsVisible(true); groupedstackedbarrenderer.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); groupedstackedbarrenderer.setItemMargin(0.10000000000000001D); SubCategoryAxis subcategoryaxis = new SubCategoryAxis("Category / Group"); subcategoryaxis.setCategoryMargin(0.050000000000000003D); subcategoryaxis.addSubCategory("G1"); subcategoryaxis.addSubCategory("G2"); subcategoryaxis.addSubCategory("G3"); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainAxis(subcategoryaxis); categoryplot.setRenderer(groupedstackedbarrenderer); return jfreechart; }
From source file:userinterface.CyberSecurity.ChartFactory.java
public static ChartPanel createChart(UserAccount account) { Map<String, LoginDetails> loginDetails = account.getLoginDetails(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); Collection<LoginDetails> values = loginDetails.values(); for (LoginDetails details : values) { dataset1.addValue(TimeUnit.MILLISECONDS.toHours(details.getLogoutTime() - details.getLoginTime()), HOURS_WORKED_BY_USER, details.getLoginDate()); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, details.getLoginDate()); }//from w ww . java2 s .c o m dataset1.addValue(2, HOURS_WORKED_BY_USER, "4-19-2016"); dataset1.addValue(3, HOURS_WORKED_BY_USER, "4-20-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-19-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-20-2016"); final CategoryItemRenderer renderer = new BarRenderer(); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer); plot.setDomainAxis(new CategoryAxis("Date")); plot.setRangeAxis(new NumberAxis("Hours")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); // now create the second dataset and renderer... final CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); final JFreeChart chart = new JFreeChart(plot); chart.setTitle("Employee work hours"); chart.setBackgroundPaint(Color.WHITE); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); return chartPanel; }
From source file:org.jfree.chart.demo.OverlaidBarChartDemo1.java
public static JFreeChart createChart() { DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(1.0D, "S1", "Category 1"); dataset1.addValue(4D, "S1", "Category 2"); dataset1.addValue(3D, "S1", "Category 3"); dataset1.addValue(5D, "S1", "Category 4"); dataset1.addValue(5D, "S1", "Category 5"); dataset1.addValue(7D, "S1", "Category 6"); dataset1.addValue(7D, "S1", "Category 7"); dataset1.addValue(8D, "S1", "Category 8"); dataset1.addValue(5D, "S2", "Category 1"); dataset1.addValue(7D, "S2", "Category 2"); dataset1.addValue(6D, "S2", "Category 3"); dataset1.addValue(8D, "S2", "Category 4"); dataset1.addValue(4D, "S2", "Category 5"); dataset1.addValue(4D, "S2", "Category 6"); dataset1.addValue(2D, "S2", "Category 7"); dataset1.addValue(1.0D, "S2", "Category 8"); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.addValue(9D, "T1", "Category 1"); dataset2.addValue(7D, "T1", "Category 2"); dataset2.addValue(2D, "T1", "Category 3"); dataset2.addValue(6D, "T1", "Category 4"); dataset2.addValue(6D, "T1", "Category 5"); dataset2.addValue(9D, "T1", "Category 6"); dataset2.addValue(5D, "T1", "Category 7"); dataset2.addValue(4D, "T1", "Category 8"); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); dataset3.addValue(94D, "R1", "Category 1"); dataset3.addValue(75D, "R1", "Category 2"); dataset3.addValue(22D, "R1", "Category 3"); dataset3.addValue(74D, "R1", "Category 4"); dataset3.addValue(83D, "R1", "Category 5"); dataset3.addValue(9D, "R1", "Category 6"); dataset3.addValue(23D, "R1", "Category 7"); dataset3.addValue(98D, "R1", "Category 8"); ///*from ww w.j a va2 s .c o m*/ StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); BarRenderer renderer1 = new BarRenderer(); renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); renderer1.setBaseItemLabelsVisible(true); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); LineAndShapeRenderer renderer3 = new LineAndShapeRenderer(); //plot CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer1); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDataset(2, dataset3); plot.setRenderer(2, renderer3); plot.setDomainAxis(new CategoryAxis("Category")); //more rangeAxis plot.setRangeAxis(new NumberAxis("Value")); plot.setRangeAxis(1, new NumberAxis("Axis 2")); plot.mapDatasetToRangeAxis(2, 1); // plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //chart JFreeChart chart = new JFreeChart(plot); chart.setTitle("Overlaid Bar Chart"); return chart; }
From source file:org.jfree.chart.demo.ItemLabelDemo5.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Item Label Demo 5", null, null, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(new Color(255, 255, 255)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); MyStackedBarRenderer mystackedbarrenderer = new MyStackedBarRenderer(); categoryplot.setRenderer(mystackedbarrenderer); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0D);/*from w w w .ja va2s . c o m*/ mystackedbarrenderer.setPositiveItemLabelPositionFallback(itemlabelposition); mystackedbarrenderer.setNegativeItemLabelPositionFallback(itemlabelposition); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator( "{0}", NumberFormat.getInstance()); mystackedbarrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); mystackedbarrenderer.setBaseItemLabelsVisible(true); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperBound(100D); return jfreechart; }
From source file:org.fhaes.fhrecorder.view.ColorBarGraph.java
/** * Creates the chart with the data from the given data set. * // w w w. jav a 2 s. c o m * @param dataset the data to plot. * @return the chart. */ private static JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.VERTICAL, false, true, false); StackedBarRenderer renderer = new StackedBarRenderer(true); renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); // Remove shine renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot plot = chart.getCategoryPlot(); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(new Color(192, 192, 192)); plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setLowerMargin(.025); plot.getDomainAxis().setUpperMargin(.025); chart.setBackgroundPaint(new Color(214, 217, 233, 30)); return chart; }
From source file:org.fhaes.fhrecorder.util.ColorBar.java
/** * Creates a chart when given a data set. * /*from w ww . j av a 2 s . co m*/ * @param dataset to be plotted. * @return the created chart. */ private static JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL, false, true, false); chart.setPadding(RectangleInsets.ZERO_INSETS); chart.setBorderVisible(false); StackedBarRenderer renderer = new StackedBarRenderer(); renderer.setBarPainter(new StandardBarPainter()); // Remove shine renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setShadowVisible(false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRenderer(renderer); // plot.setBackgroundAlpha(0.0f); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.getRangeAxis().setVisible(false); plot.getRangeAxis().setLowerMargin(0); plot.getRangeAxis().setUpperMargin(0); plot.getDomainAxis().setVisible(false); plot.getDomainAxis().setLowerMargin(0); plot.getDomainAxis().setUpperMargin(0); return chart; }
From source file:org.jfree.chart.demo.MinMaxCategoryPlotDemo1.java
public static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Min/Max Category Plot", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); MinMaxCategoryRenderer minmaxcategoryrenderer = new MinMaxCategoryRenderer(); minmaxcategoryrenderer.setDrawLines(false); categoryplot.setRenderer(minmaxcategoryrenderer); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:cl.apr.pdf.chart.BarChartAviso.java
public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) { BufferedImage bi = null;/*from www .j a v a 2 s . c o m*/ try { ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme()); /* Step - 1: Define the data for the bar chart */ DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset(); int i = 0; for (BarChartItem barChartItem : barChartItems) { if (barChartItem.getNombre().equals("-")) { my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + ""); } else my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre()); } // my_bar_chart_dataset.addValue(34, "mes", "Ene"); // my_bar_chart_dataset.addValue(25, "mes", "Feb"); // my_bar_chart_dataset.addValue(22, "mes", "Mar"); // my_bar_chart_dataset.addValue(12, "mes", "Abr"); // my_bar_chart_dataset.addValue(40, "mes", "May"); // my_bar_chart_dataset.addValue(30, "mes", "jun"); // my_bar_chart_dataset.addValue(2, "mes", "Jul"); // my_bar_chart_dataset.addValue(15, "mes", "Ago"); /* Step -2:Define the JFreeChart object to create bar chart */ //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false); JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset, PlotOrientation.VERTICAL, true, true, false); //chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBackgroundPaint(Color.white); chart.setBorderStroke(null); chart.getLegend().visible = false; /* Step -3: Write the output as PNG file with bar chart information */ int width = 480; /* Width of the image */ int height = 250; /* Height of the image */ bi = chart.createBufferedImage(width, height); /* File BarChart=new File("output_chart.png"); ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); */ } catch (Exception i) { System.out.println(i); } return bi; }
From source file:eu.delving.sip.base.ReportChartHelper.java
private static JPanel finishBarChart(JFreeChart chart, Color... colors) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangePannable(true);// www .j a v a2 s .com if (colors.length > 0) plot.setRenderer(new CustomRenderer(colors)); BarRenderer bar = (BarRenderer) plot.getRenderer(); bar.setItemLabelAnchorOffset(9D); bar.setBaseItemLabelsVisible(true); bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); bar.setMaximumBarWidth(0.05); bar.setItemMargin(0.03D); bar.setBasePositiveItemLabelPosition( new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D)); bar.setPositiveItemLabelPositionFallback( new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D)); CategoryAxis x = plot.getDomainAxis(); x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); x.setCategoryMargin(0.25D); x.setUpperMargin(0.02D); x.setLowerMargin(0.02D); NumberAxis y = (NumberAxis) plot.getRangeAxis(); y.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); y.setUpperMargin(0.10000000000000001D); ChartUtilities.applyCurrentTheme(chart); return new ChartPanel(chart); }
From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java
private static JFreeChart createChart() { ////ww w .ja v a2 s . c o m DefaultCategoryDataset Pactual = jFreeChartDataSets.get(CoreConfiguration.PACTUAL_LABEL); DefaultCategoryDataset Ppredicted = jFreeChartDataSets.get(CoreConfiguration.PPREDICTED_LABEL); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); /*renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); renderer1.setBaseItemLabelsVisible(true);*/ StackedAreaRenderer renderer2 = new StackedAreaRenderer(); //plot CategoryPlot plot = new CategoryPlot(); plot.setDataset(Ppredicted); plot.setRenderer(renderer2); plot.setDataset(1, Pactual); plot.setRenderer(1, renderer1); CategoryAxis axis = new CategoryAxis("Sample"); axis.setTickLabelsVisible(false); axis.setCategoryMargin(0.0); plot.setDomainAxis(axis); //more rangeAxis plot.setRangeAxis(new NumberAxis("Power (Watts)")); plot.mapDatasetToRangeAxis(2, 1); // plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //chart JFreeChart chart = new JFreeChart(plot); chart.setTitle(NAME); return chart; }