List of usage examples for org.jfree.chart ChartFactory createBarChart
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:net.sourceforge.subsonic.controller.UserChartController.java
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);//from w w w . jav a 2 s . com CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); renderer.setSeriesPaint(0, gp0); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
From source file:org.jfree.expdemo.SelectionDemo5Category.java
private static JFreeChart createChart(CategoryDataset dataset, DatasetSelectionExtension ext) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from ww w.ja v a 2 s. c o m CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.blue); // 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); // 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); renderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); //add selection specific rendering IRSUtilities.setSelectedItemPaint(renderer, ext, Color.WHITE); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:j2se.jfreechart.barchart.BarChartDemo5.java
/** * Creates a chart.//from www. j av a2s. c om * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart", // chart title "Category", // domain axis label "Score (%)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.getRenderer().setSeriesPaint(0, new Color(0, 0, 255)); plot.getRenderer().setSeriesPaint(1, new Color(75, 75, 255)); plot.getRenderer().setSeriesPaint(2, new Color(150, 150, 255)); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // NumberAxis hna = rangeAxis; // MarkerAxisBand band = new MarkerAxisBand(hna, 2.0, 2.0, 2.0, 2.0, // new Font("SansSerif", Font.PLAIN, 9)); // IntervalMarker m1 = new IntervalMarker(0.0, 33.0, "Low", Color.gray, // new BasicStroke(0.5f), Color.green, 0.75f); // IntervalMarker m2 = new IntervalMarker(33.0, 66.0, "Medium", Color.gray, // new BasicStroke(0.5f), Color.orange, 0.75f); // IntervalMarker m3 = new IntervalMarker(66.0, 100.0, "High", Color.gray, // new BasicStroke(0.5f), Color.red, 0.75f); // band.addMarker(m1); // band.addMarker(m2); // band.addMarker(m3); // hna.setMarkerBand(band); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.BulletGraph.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); Dataset dataset = (Dataset) datasets.getDatasets().get("1"); ValueDataset valDataSet = (ValueDataset) dataset; Number value = valDataSet.getValue(); DefaultCategoryDataset datasetC = new DefaultCategoryDataset(); datasetC.addValue(value, "", ""); // customize a bar chart JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL, false, false, false);//from w ww.j a v a2s . c o m chart.setBorderVisible(false); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(true); plot.setOutlinePaint(Color.BLACK); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setAnchorValue(value.doubleValue()); // add the target marker if (target != null) { ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f)); plot.addRangeMarker(marker, Layer.FOREGROUND); } //sets different marks for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); // add the marks IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor()); plot.addRangeMarker(marker, Layer.BACKGROUND); logger.debug("Added new interval to the plot"); } // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(true); // calculate the upper limit //double upperBound = target * upperFactor; rangeAxis.setRange(new Range(lower, upper)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // customize renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.18); renderer.setSeriesPaint(0, Color.BLACK); return chart; }
From source file:j2se.jfreechart.barchart.BarChartDemo1.java
/** * Creates a sample chart.// w w w . j a va 2s .com * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // 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); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.java
/** * Creates a sample chart./*from w ww . ja v a 2s . c o m*/ * * @param dataset a dataset. * * @return A sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, // title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // dataset PlotOrientation.HORIZONTAL, // orientation !legendPanelOn, // include legend true, // tooltips false // URLs ); chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC)); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f); plot.setRangeAxis(new DateAxis("Date")); CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); LineAndShapeRenderer renderer = new LineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); plot.setRenderer(renderer); // setCategorySummary(dataset); time return chart; }
From source file:org.jfree.chart.demo.ParetoChartDemo.java
/** * Creates a new demo instance./*from ww w. j ava 2 s. com*/ * * @param title the frame title. */ public ParetoChartDemo(final String title) { super(title); final DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Integer(4843)); data.addValue("C++", new Integer(2098)); data.addValue("C#", new Integer(26)); data.addValue("Java", new Integer(1901)); data.addValue("Perl", new Integer(2507)); data.addValue("PHP", new Integer(1689)); data.addValue("Python", new Integer(948)); data.addValue("Ruby", new Integer(100)); data.addValue("SQL", new Integer(263)); data.addValue("Unix Shell", new Integer(485)); data.sortByValues(SortOrder.DESCENDING); final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title "Language", // domain axis label "Projects", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.addSubtitle(new TextTitle("By Programming Language")); chart.addSubtitle(new TextTitle("As at 5 March 2003")); // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); final NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(550, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.SurveyResultsDemo2.java
/** * Creates a chart./*from w ww . j a v a 2s . c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 8.5 - Case studies are available"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 5.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }
From source file:org.kineticsystem.commons.data.demo.panels.AggregationChartPane.java
/** * Constructor.//from w ww .ja va2s . co m * @param source This is the source list being modified ate the same time * by many threads. */ public AggregationChartPane(ActiveList<RandomContact> source) { // Define aggregators. GroupAggregator[] aggregators = new GroupAggregator[] { new ContactsPerContinentAggr(), new AvgAgePerContinentAggr(), new MaxAgePerContinentAggr(), new MinAgePerContinentAggr() }; // Aggregator selector. DefaultComboBoxModel groupComboModel = new DefaultComboBoxModel(aggregators); final JComboBox groupCombo = new JComboBox(groupComboModel); groupCombo.setSelectedIndex(1); groupCombo.setToolTipText("Select an aggregation function."); // Create the dataset. dataset = new DefaultCategoryDataset(); List<Country> countries = RandomContactGenerator.getCountries(); Set<String> continents = new TreeSet<String>(); for (Country country : countries) { continents.add(country.getContinent()); } for (String continent : continents) { dataset.setValue(0, continent, ""); } // Define the aggregated list. groups = new GroupMapping<RandomContact>(source); groups.setAggregator(aggregators[0]); groups.getTarget().addActiveListListener(this); // Create the chart. JFreeChart chart = ChartFactory.createBarChart("", "Continent", groups.getAggregator().toString(), dataset, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); final ValueAxis axis = chart.getCategoryPlot().getRangeAxis(); axis.setAutoRange(true); axis.setRange(0, 250); ChartPanel chartPanel = new ChartPanel(chart); // Create the selector. ActionListener groupComboListener = new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); GroupAggregator aggr = (GroupAggregator) cb.getSelectedItem(); groups.setAggregator(aggr); axis.setLabel(aggr.toString()); } }; groupCombo.addActionListener(groupComboListener); // Layout the GUI. Cell cell = new Cell(); TetrisLayout groupTableLayout = new TetrisLayout(2, 1); groupTableLayout.setRowWeight(0, 0); groupTableLayout.setRowWeight(1, 100); setLayout(groupTableLayout); add(groupCombo, cell); add(chartPanel, cell); }
From source file:org.owasp.jbrofuzz.graph.canvas.ResponseTimeChart.java
public ChartPanel getPlotCanvas() { final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Response Time Bar Chart", // chart title "File Name", // domain axis label "Response Time (ms)", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? true // URLs? );/*from w w w. j a v a 2 s .c om*/ final Plot plot = chart.getPlot(); plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage()); plot.setBackgroundImageAlignment(Align.TOP_RIGHT); final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); return new ChartPanel(chart); }