List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis
public CategoryAxis(String label)
From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java
/** * Plots Data for Chart//from w ww .j av a 2 s . com */ private void boxWhiskerPlot() { BoxAndWhiskerCategoryDataset dataset = createDataset(); CategoryAxis xAxis = new CategoryAxis("Model"); NumberAxis yAxis = new NumberAxis("Fitness"); yAxis.setRange(0.0, 1.0); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.2); renderer.setItemMargin(0.5); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); chart = new JFreeChart("Model comparison", new Font("Palatino", Font.BOLD, 14), plot, true); chart.removeLegend(); // boxWhiskerPane.setCenter(viewer); }
From source file:org.jfree.chart.demo.OverlaidCategoryChartDemo.java
/** * Creates a new demo.//from ww w. ja va2s . c om * * @param title the frame title. */ public OverlaidCategoryChartDemo(String title) { super(title); DefaultIntervalCategoryDataset barData = null; double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } }; double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } }; barData = new DefaultIntervalCategoryDataset(lows, highs); double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } }; CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals); double[][] lineVals = new double[4][5]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { lineVals[i][j] = (Math.random() * 0.56) - 0.18; } } CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals); String ctitle = "Strategie Sicherheit"; String xTitle = "Zeitraum (in Jahren)"; String yTitle = "Performance"; CategoryAxis xAxis = new CategoryAxis(xTitle); xAxis.setLabelFont(titleFont); xAxis.setTickLabelFont(labelFont); xAxis.setTickMarksVisible(false); NumberAxis yAxis = new NumberAxis(yTitle); yAxis.setLabelFont(titleFont); yAxis.setTickLabelFont(labelFont); yAxis.setRange(-0.2, 0.4); DecimalFormat formatter = new DecimalFormat("0.##%"); yAxis.setTickUnit(new NumberTickUnit(0.05, formatter)); IntervalBarRenderer barRenderer = new IntervalBarRenderer(); barRenderer.setItemLabelsVisible(Boolean.TRUE); CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setBackgroundPaint(Color.lightGray); plot.setOutlinePaint(Color.black); LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); dotRenderer.setItemLabelsVisible(Boolean.TRUE); plot.setSecondaryDataset(0, dotData); plot.setSecondaryRenderer(0, dotRenderer); LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES); plot.setSecondaryDataset(1, lineData); plot.setSecondaryRenderer(1, lineRenderer); this.chart = new JFreeChart(ctitle, titleFont, plot, false); this.chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupBoxPlot.java
public List<JFreeChart> createChart() { List<JFreeChart> charts = new ArrayList<>(); LinkedHashSet<ITreatmentGroupDescriptor> treatmentGroups = new LinkedHashSet<>( project.getTreatmentGroups()); List<CategoryPlot> plots = new LinkedList<>(); for (IPeakGroupDescriptor pgd : pgdl) { LinkedHashMap<ITreatmentGroupDescriptor, HashSet<IPeakAnnotationDescriptor>> map = new LinkedHashMap<>(); for (ITreatmentGroupDescriptor itgd : treatmentGroups) { map.put(itgd, new LinkedHashSet<IPeakAnnotationDescriptor>()); }//ww w.j av a 2 s . com List<IPeakAnnotationDescriptor> descriptors = pgd.getPeakAnnotationDescriptors(); DefaultBoxAndWhiskerCategoryDataset baw = new DefaultBoxAndWhiskerCategoryDataset(); for (IPeakAnnotationDescriptor ipad : descriptors) { ITreatmentGroupDescriptor treatmentGroup = ipad.getChromatogramDescriptor().getTreatmentGroup(); HashSet<IPeakAnnotationDescriptor> descr = map.get(treatmentGroup); if (descr == null) { descr = new HashSet<>(); map.put(treatmentGroup, descr); } descr.add(ipad); } List<Color> colors = new LinkedList<>(); for (ITreatmentGroupDescriptor tgd : map.keySet()) { String name = getPeakName(pgd); baw.add(createBoxAndWhiskerItem(map.get(tgd)), tgd.getName() + " (" + map.get(tgd).size() + ")", name); colors.add(tgd.getColor()); } BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setMeanVisible(false); renderer.setMedianVisible(true); renderer.setArtifactPaint(new Color(0, 0, 0, 128)); renderer.setMaximumBarWidth(0.1); renderer.setUseOutlinePaintForWhiskers(false); // renderer.setAutoPopulateSeriesFillPaint(true); // renderer.setAutoPopulateSeriesPaint(true); // renderer.setAutoPopulateSeriesOutlinePaint(true); CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"), new NumberAxis("Normalized Peak Area"), renderer); Logger.getLogger(getClass().getName()).log(Level.INFO, "Setting {0} colors!", colors.size()); ChartCustomizer.setSeriesColors(cp, 0.6f, colors); // ChartCustomizer.setSeriesColors(cp, 0.9f,colors); plots.add(cp); JFreeChart chart = new JFreeChart(cp); chart.setTitle( "Peak group " + pgd.getDisplayName() + " size: " + pgd.getPeakAnnotationDescriptors().size()); charts.add(chart); } // CategoryAxis ca = new CategoryAxis("Treatment Groups"); // NumberAxis va = new NumberAxis("Normalized Peak Area"); // CombinedDomainCategoryPlot cdcp = new CombinedDomainCategoryPlot(ca); // for (CategoryPlot cp : plots) { // cp.setRangeAxis(va); // cdcp.add(cp); // break; // } // return new JFreeChart(cdcp); return charts; }
From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java
protected void buildChart() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); // we build the chart manually rather than using ChartFactory // because we need to customize the getDataRange method below CategoryAxis categoryAxis = new CategoryAxis(""); NumberAxis valueAxis = new NumberAxis("Untitled Y Axis"); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) { // Customizing this method in order to provide a bit of // vertical buffer. Otherwise the bar chart box gets drawn // slightly off-chart, which looks really bad. public Range getDataRange(ValueAxis axis) { Range range = super.getDataRange(axis); if (range == null) { return null; }//from www .j a v a 2 s . co m final double EXTRA_PERCENTAGE = 0.02; return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE); } }; chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); ChartFactory.getChartTheme().apply(chart); chart.setAntiAlias(true); chartPanel = buildChartPanel(chart); setChartPanel(chartPanel); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupRtBoxPlot.java
public List<JFreeChart> createChart() { List<JFreeChart> charts = new ArrayList<>(); LinkedHashSet<ITreatmentGroupDescriptor> treatmentGroups = new LinkedHashSet<>( project.getTreatmentGroups()); List<CategoryPlot> plots = new LinkedList<>(); for (IPeakGroupDescriptor pgd : pgdl) { LinkedHashMap<ITreatmentGroupDescriptor, HashSet<IPeakAnnotationDescriptor>> map = new LinkedHashMap<>(); for (ITreatmentGroupDescriptor itgd : treatmentGroups) { map.put(itgd, new LinkedHashSet<IPeakAnnotationDescriptor>()); }/*from ww w . j a v a2 s . com*/ List<IPeakAnnotationDescriptor> descriptors = pgd.getPeakAnnotationDescriptors(); DefaultBoxAndWhiskerCategoryDataset baw = new DefaultBoxAndWhiskerCategoryDataset(); for (IPeakAnnotationDescriptor ipad : descriptors) { ITreatmentGroupDescriptor treatmentGroup = ipad.getChromatogramDescriptor().getTreatmentGroup(); HashSet<IPeakAnnotationDescriptor> descr = map.get(treatmentGroup); if (descr == null) { descr = new HashSet<>(); map.put(treatmentGroup, descr); } descr.add(ipad); } List<Color> colors = new LinkedList<>(); for (ITreatmentGroupDescriptor tgd : map.keySet()) { String name = getPeakName(pgd); baw.add(createBoxAndWhiskerItem(map.get(tgd)), tgd.getName() + " (" + map.get(tgd).size() + ")", name); colors.add(tgd.getColor()); } BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setMeanVisible(false); renderer.setMedianVisible(true); renderer.setArtifactPaint(new Color(0, 0, 0, 128)); renderer.setMaximumBarWidth(0.1); renderer.setUseOutlinePaintForWhiskers(false); // renderer.setAutoPopulateSeriesFillPaint(true); // renderer.setAutoPopulateSeriesPaint(true); // renderer.setAutoPopulateSeriesOutlinePaint(true); NumberAxis yAxis = new NumberAxis("Peak Apex Retention Time"); yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(false); CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"), yAxis, renderer); Logger.getLogger(getClass().getName()).log(Level.INFO, "Setting {0} colors!", colors.size()); ChartCustomizer.setSeriesColors(cp, 0.6f, colors); // ChartCustomizer.setSeriesColors(cp, 0.9f,colors); plots.add(cp); JFreeChart chart = new JFreeChart(cp); chart.setTitle( "Peak group " + pgd.getDisplayName() + " size: " + pgd.getPeakAnnotationDescriptors().size()); charts.add(chart); } // CategoryAxis ca = new CategoryAxis("Treatment Groups"); // NumberAxis va = new NumberAxis("Normalized Peak Area"); // CombinedDomainCategoryPlot cdcp = new CombinedDomainCategoryPlot(ca); // for (CategoryPlot cp : plots) { // cp.setRangeAxis(va); // cdcp.add(cp); // break; // } // return new JFreeChart(cdcp); return charts; }
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ?// ww w.j ava 2 s. co m * * @param title * @param titleFont * @param categoryAxisLabel * @param valueAxisLabel * @param data ?? * @param orientation ? * @param legend * @param tooltips ???? * @param urls ??URL * @param urlGenerator * * @return ? */ public static JFreeChart createBarChart(String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); 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:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java
private static JFreeChart createChart() { ///*from ww w . j av a 2 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; }
From source file:org.fhaes.jsea.JSEABarChart.java
/** * Creates a demo chart.//from w w w . j a v a2 s.com * * @return A chart. */ @SuppressWarnings("deprecation") public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow, int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim, String outputFilePrefix, int alphaLevel, int segmentIndex) { JSEABarChart.meanByWindow = meanByWindow; JSEABarChart.lengthOfWindow = lengthOfWindow; JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent; JSEABarChart.leftEndPointSim = leftEndPointSim; JSEABarChart.rightEndPointSim = rightEndPointSim; JSEABarChart.alphaLevel = alphaLevel; CategoryPlot plot = new CategoryPlot(); plot.setDataset(0, createDataset()); plot.setOrientation(PlotOrientation.VERTICAL); CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray)); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); renderer.setOutlinePaint(Color.yellow); renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(0, renderer); Color allcolors[] = { Color.red, Color.green, Color.blue }; System.out.println("here is the alphlevel " + alphaLevel); // for (int k = 0; k <= 5; k++) { // if (k <= 2) { // / plot.setDataset(k + 1, createEndDataset(k, true)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k)); // } else { // plot.setDataset(k + 1, createEndDataset(k - 3, false)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3)); // } // } // for (int k = 0; k <1; k++) { // if (k <= 2) { plot.setDataset(1, createEndDataset(alphaLevel, true)); plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } else { plot.setDataset(4, createEndDataset(alphaLevel, false)); plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } // } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // plot.setBackgroundPaint(Color.WHITE); plot.setDomainAxis(new CategoryAxis("LAG")); plot.addRangeMarker(new ValueMarker(0)); plot.setRangeAxis(new NumberAxis(outputFilePrefix)); plot.setRangeGridlinesVisible(true); JFreeChart chart = new JFreeChart(plot); chart.setTitle(title); chart.removeLegend(); chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:ChartUsingJava.CombinedCategoryPlotDemo1.java
/** * Creates a chart.//www .j a v a 2 s . c o m * * @return A chart. */ private static JFreeChart createChart() { CategoryDataset dataset1 = createDataset1(); NumberAxis rangeAxis1 = new NumberAxis("Value"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1); subplot1.setDomainGridlinesVisible(true); CategoryDataset dataset2 = createDataset2(); NumberAxis rangeAxis2 = new NumberAxis("Value"); rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer2 = new BarRenderer(); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2); subplot2.setDomainGridlinesVisible(true); CategoryAxis domainAxis = new CategoryAxis("Category"); CombinedCategoryPlot plot = new CombinedCategoryPlot(domainAxis, new NumberAxis("Range")); plot.add(subplot1, 2); plot.add(subplot2, 1); JFreeChart result = new JFreeChart("Combined Domain Category Plot Demo", new Font("SansSerif", Font.BOLD, 12), plot, true); return result; }
From source file:com.tonbeller.jpivot.chart.ChartFactory.java
/** * Creates a vertical bar chart with default settings. * * @param title the chart title./*w w w . j av a 2 s .com*/ * @param categoryAxisLabel the label for the category axis. * @param valueAxisLabel the label for the value axis. * @param data the dataset for the chart. * @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 vertical bar chart. */ public static JFreeChart createBarChart(String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (tooltips) { renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }