List of usage examples for org.jfree.chart.renderer.category StackedBarRenderer setBaseToolTipGenerator
@Override public void setBaseToolTipGenerator(CategoryToolTipGenerator generator)
From source file:org.fhaes.fhrecorder.util.ColorBar.java
/** * Creates a chart when given a data set. * //from w ww . j a va 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.fhaes.fhrecorder.view.ColorBarGraph.java
/** * Creates the chart with the data from the given data set. * // ww w . j ava 2s.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:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ??/*from w ww. j av a 2 s. c om*/ * * @param title * @param titleFont * @param domainAxisLabel * @param rangeAxisLabel * @param data ?? * @param orientation ? * @param legend * @param tooltips ???? * @param urls ??URL * @param urlGenerator * * @return ?? */ public static JFreeChart createStackedBarChart(String title, java.awt.Font titleFont, String domainAxisLabel, String rangeAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); // create the renderer... StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { // renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { // renderer.setItemURLGenerator(urlGenerator); renderer.setBaseItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createStackedBarChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); }/*from w ww.j a va2s. c o m*/ if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("StackedBar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setDrawBarOutline(false); 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); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.HoursChartMaker.java
/** * Create a chart from the provided category dataset * @return a Chart that can be rendered in a ChartPanel *//*from www.j a va2s . c o m*/ @Override protected JFreeChart createChart() { //Create a vertical stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false); //Get the font from the platform UI Font chartFont = UIManager.getFont("Label.font"); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Get the renderer from the plot StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer(); //Set the rendered to use a standard bar painter (nothing fancy) sbRenderer.setBarPainter(new StandardBarPainter()); //Set the colours for the bars sbRenderer.setSeriesPaint(0, PREPARATION_COLOR); sbRenderer.setSeriesPaint(1, SUPPORT_COLOR); //Set the tooltip to be series, category and value sbRenderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}, {1} ({2})", NumberFormat.getInstance())); //Get the category axis (that's the X-axis in this case) CategoryAxis categoryAxis = plot.getDomainAxis(); //Set the font for rendering the labels on the x-axis to be the platform default categoryAxis.setLabelFont(chartFont); //Get the number axis (that's the Y-axis in this case) NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //Use the same font as the x-axis numberAxis.setLabelFont(chartFont); return chart; }
From source file:com.googlecode.logVisualizer.chart.HorizontalStackedBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); plot.setNoDataMessage("No data available"); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); setBarShadowVisible(chart, false);/*from w ww . j a va 2 s. com*/ renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); categoryAxis.setCategoryMargin(0.02); categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberAxis.setUpperMargin(0.1); return chart; }
From source file:com.googlecode.logVisualizer.chart.perDayConsumption.ConsumptionBarChartBuilder.java
private JFreeChart createChart(final ConsumptionDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.VERTICAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); plot.setNoDataMessage("No data available"); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); setBarShadowVisible(chart, false);/*from w w w .j a v a2 s . c o m*/ setStackColors(dataset, renderer); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new ConsumptionLableGenerator()); renderer.setBaseToolTipGenerator(new ConsumptionToolTipGenerator()); categoryAxis.setCategoryMargin(0.07); categoryAxis.setUpperMargin(0.01); categoryAxis.setLowerMargin(0.01); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberAxis.setUpperMargin(0.1); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.LearningExperienceChartMaker.java
/** * Create a chart from the provide category dataset * @return a Chart that can be rendered in a ChartPanel *//*from w ww . j a v a 2s . co m*/ @Override protected JFreeChart createChart() { //Create a horizontal stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, true, true, false); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Remove offsets from the plot plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); //Hide the range lines plot.setRangeGridlinesVisible(false); //Get the renderer for the plot StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer(); //Set the painter for the renderer (nothing fancy) sbRenderer.setBarPainter(new StandardBarPainter()); //sbRenderer.setItemMargin(0.5); //Makes no difference //reduces width of bar as proportion of overall width sbRenderer.setMaximumBarWidth(0.5); //Render the bars as percentages sbRenderer.setRenderAsPercentages(true); //Set the colours for the bars sbRenderer.setSeriesPaint(0, PERSONALISED_COLOR); sbRenderer.setSeriesPaint(1, SOCIAL_COLOR); sbRenderer.setSeriesPaint(2, ONE_SIZE_FOR_ALL_COLOR); //Set the tooltips to render percentages sbRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset cd, int row, int column) { //Only interested in row, as there's only one column //TODO--really inefficient @SuppressWarnings("unchecked") List<Comparable> rows = cd.getRowKeys(); Comparable columnKey = cd.getColumnKey(column); //Sum running total int total = 0; for (Comparable comparable : rows) { total += cd.getValue(comparable, columnKey).intValue(); } //Get the value for the row (in our case the learning type) Comparable rowKey = cd.getRowKey(row); float value = cd.getValue(rowKey, columnKey).floatValue(); //The tooltip is the value of the learning type divided by the total, expressed as a percentage @SuppressWarnings("StringBufferWithoutInitialCapacity") StringBuilder builder = new StringBuilder(); builder.append("<html><center>"); builder.append(cd.getRowKey(row)); builder.append(" ("); builder.append(FORMATTER.format(value / total)); builder.append(")<br/>"); builder.append("Double-click for more"); return builder.toString(); } }); //Hide both axes CategoryAxis categoryAxis = plot.getDomainAxis(); //categoryAxis.setCategoryMargin(0.5D);//Makes no difference categoryAxis.setVisible(false); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setVisible(false); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a stacked bar chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} * as the renderer. /*from w ww .j a v a 2 s .c om*/ * * @param title the chart title (<code>null</code> permitted). * @param domainAxisLabel the label for the category axis * (<code>null</code> permitted). * @param rangeAxisLabel the label for the value axis * (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation of the chart (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 A stacked bar chart. */ public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { 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); return chart; }
From source file:KIDLYFactory.java
/** * Creates a stacked bar chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} * as the renderer.// w ww . j a v a2 s . co m * * @param title the chart title (<code>null</code> permitted). * @param domainAxisLabel the label for the category axis * (<code>null</code> permitted). * @param rangeAxisLabel the label for the value axis * (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation of the chart (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 A stacked bar chart. */ public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { 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); return chart; }