List of usage examples for org.jfree.chart.plot CategoryPlot clearRangeMarkers
public void clearRangeMarkers()
From source file:org.jfree.chart.demo.SurveyResultsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset, PlotOrientation.HORIZONTAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources"); texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT); texttitle.setBackgroundPaint(Color.red); texttitle.setPaint(Color.white); jfreechart.setTitle(texttitle);/* w w w. java 2 s .c o m*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setOutlinePaint(null); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(Color.black); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.5D); categoryplot.getRangeAxis().setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setSeriesPaint(0, new Color(156, 164, 74)); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10)); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); barrenderer.setBasePositiveItemLabelPosition(itemlabelposition); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0D); categorytextannotation.setFont(new Font("SansSerif", 1, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation); CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation( "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D); categorytextannotation1.setFont(new Font("SansSerif", 0, 12)); categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation1.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation1); CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation( "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D); categorytextannotation2.setFont(new Font("SansSerif", 0, 12)); categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation2.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation2); CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation( "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D); categorytextannotation3.setFont(new Font("SansSerif", 0, 12)); categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation3.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation3); CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation( "5. Case studies are available.", "Category 5", 0.0D); categorytextannotation4.setFont(new Font("SansSerif", 1, 12)); categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation4.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation4); CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation( "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D); categorytextannotation5.setFont(new Font("SansSerif", 0, 12)); categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation5.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation5); CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation( "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D); categorytextannotation6.setFont(new Font("SansSerif", 0, 12)); categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation6.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation6); CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D); categorytextannotation7.setFont(new Font("SansSerif", 0, 12)); categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation7.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation7); CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation( "9. Case studies are available.", "Category 9", 0.0D); categorytextannotation8.setFont(new Font("SansSerif", 1, 12)); categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation8.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation8); CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation( "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D); categorytextannotation9.setFont(new Font("SansSerif", 0, 12)); categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation9.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation9); CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation( "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D); categorytextannotation10.setFont(new Font("SansSerif", 0, 12)); categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation10.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation10); CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D); categorytextannotation11.setFont(new Font("SansSerif", 0, 12)); categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation11.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation11); CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation( "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D); categorytextannotation12.setFont(new Font("SansSerif", 1, 12)); categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation12.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation12); CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant information.", "Category 14", 0.0D); categorytextannotation13.setFont(new Font("SansSerif", 1, 12)); categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation13.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation13); CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0D); categorytextannotation14.setFont(new Font("SansSerif", 1, 12)); categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation14.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation14); return jfreechart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createWaterfallChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); }/*w w w. j ava 2s. com*/ if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Waterfall Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 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)); // AbstractRenderer#setSeriesPaint(int, Paint) are ignored; // renderer.setSeriesPaint(0, gp0); // renderer.setSeriesPaint(1, gp1); // renderer.setSeriesPaint(2, gp2); //?? renderer.setFirstBarPaint(gp0); renderer.setLastBarPaint(gp2); renderer.setPositiveBarPaint(Color.orange); renderer.setNegativeBarPaint(Color.cyan); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
@SuppressWarnings("unchecked") public static JFreeChart createTopNBarChart2(String yAxisLabel, CategoryDataset dataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); categoryplot.setBackgroundPaint(null); categoryplot.setOutlinePaint(null);/*from w w w . jav a 2 s. c o m*/ categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(UIConstants.INTEL_BORDER_GRAY); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.75D); NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); axis.setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setShadowVisible(false); barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(UIConstants.H5_FONT); barrenderer.setBarPainter(new StandardBarPainter()); List<String> names = dataset.getColumnKeys(); for (String name : names) { CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation(name, name, 0.0D); categorytextannotation.setFont(UIConstants.H6_FONT); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.MIDDLE); categoryplot.addAnnotation(categorytextannotation); } return jfreechart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo.java
/** * Creates a chart.// ww w. j a va 2 s .c om * * @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.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); final TextTitle title = new TextTitle("Figure 7 | I. Resources - The site offers users relevant, " + "informative and educational resources"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOutlinePaint(null); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePosition(CategoryAnchor.END); plot.setDomainGridlineStroke(new BasicStroke(0.5f)); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinesVisible(false); plot.clearRangeMarkers(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.50); plot.getRangeAxis().setVisible(false); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setOutlineStroke(null); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.BOLD, 10)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); final CategoryTextAnnotation a1 = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0); a1.setFont(new Font("SansSerif", Font.BOLD, 12)); a1.setTextAnchor(TextAnchor.BOTTOM_LEFT); a1.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a1); final CategoryTextAnnotation a2 = new CategoryTextAnnotation( "2. White papers enhance users " + "understanding of the firm and its expertise.", "Category 2", 0.0); a2.setFont(new Font("SansSerif", Font.PLAIN, 12)); a2.setTextAnchor(TextAnchor.BOTTOM_LEFT); a2.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a2); final CategoryTextAnnotation a3 = new CategoryTextAnnotation( "3. White papers are relevant to " + "the firm's prospects and clients.", "Category 3", 0.0); a3.setFont(new Font("SansSerif", Font.PLAIN, 12)); a3.setTextAnchor(TextAnchor.BOTTOM_LEFT); a3.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a3); final CategoryTextAnnotation a4 = new CategoryTextAnnotation( "4. White papers are relevant to " + "the firm's positioning.", "Category 4", 0.0); a4.setFont(new Font("SansSerif", Font.PLAIN, 12)); a4.setTextAnchor(TextAnchor.BOTTOM_LEFT); a4.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a4); final CategoryTextAnnotation a5 = new CategoryTextAnnotation("5. Case studies are available.", "Category 5", 0.0); a5.setFont(new Font("SansSerif", Font.BOLD, 12)); a5.setTextAnchor(TextAnchor.BOTTOM_LEFT); a5.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a5); final CategoryTextAnnotation a6 = new CategoryTextAnnotation( "6. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 6", 0.0); a6.setFont(new Font("SansSerif", Font.PLAIN, 12)); a6.setTextAnchor(TextAnchor.BOTTOM_LEFT); a6.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a6); final CategoryTextAnnotation a7 = new CategoryTextAnnotation( "7. Case studies are relevant to " + "the firm's prospects and clients.", "Category 7", 0.0); a7.setFont(new Font("SansSerif", Font.PLAIN, 12)); a7.setTextAnchor(TextAnchor.BOTTOM_LEFT); a7.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a7); final CategoryTextAnnotation a8 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0); a8.setFont(new Font("SansSerif", Font.PLAIN, 12)); a8.setTextAnchor(TextAnchor.BOTTOM_LEFT); a8.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a8); final CategoryTextAnnotation a9 = new CategoryTextAnnotation("9. Case studies are available.", "Category 9", 0.0); a9.setFont(new Font("SansSerif", Font.BOLD, 12)); a9.setTextAnchor(TextAnchor.BOTTOM_LEFT); a9.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a9); final CategoryTextAnnotation a10 = new CategoryTextAnnotation( "10. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 10", 0.0); a10.setFont(new Font("SansSerif", Font.PLAIN, 12)); a10.setTextAnchor(TextAnchor.BOTTOM_LEFT); a10.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a10); final CategoryTextAnnotation a11 = new CategoryTextAnnotation( "11. Case studies are relevant " + "to the firm's prospects and clients.", "Category 11", 0.0); a11.setFont(new Font("SansSerif", Font.PLAIN, 12)); a11.setTextAnchor(TextAnchor.BOTTOM_LEFT); a11.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a11); final CategoryTextAnnotation a12 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0); a12.setFont(new Font("SansSerif", Font.PLAIN, 12)); a12.setTextAnchor(TextAnchor.BOTTOM_LEFT); a12.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a12); final CategoryTextAnnotation a13 = new CategoryTextAnnotation( "13. Users can easily access " + "resources based on viewer interest.", "Category 13", 0.0); a13.setFont(new Font("SansSerif", Font.BOLD, 12)); a13.setTextAnchor(TextAnchor.BOTTOM_LEFT); a13.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a13); final CategoryTextAnnotation a14 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant " + "information.", "Category 14", 0.0); a14.setFont(new Font("SansSerif", Font.BOLD, 12)); a14.setTextAnchor(TextAnchor.BOTTOM_LEFT); a14.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a14); final CategoryTextAnnotation a15 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0); a15.setFont(new Font("SansSerif", Font.BOLD, 12)); a15.setTextAnchor(TextAnchor.BOTTOM_LEFT); a15.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a15); return chart; }
From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java
@Override public void updateSelectedSamples() { PlotsByTraitInstance plotsByTraitInstance = selectedValueStore.getSyncedPlotsByTrait(); intervalMarker = null;// w w w . j a v a 2 s . co m CategoryPlot categoryPlot = ((CategoryPlot) getChart().getPlot()); categoryPlot.clearRangeMarkers(); double min = categoryPlot.getRangeAxis().getLowerBound(); double max = categoryPlot.getRangeAxis().getUpperBound(); for (TraitInstance ti : plotsByTraitInstance.getTraitInstances()) { if (traitInstances.contains(ti)) { String tiIdentifier = InstanceIdentifierUtil.getInstanceIdentifier(ti); // Set<Plot> plots = plotsByTraitInstance.getPlotSpecimens(ti).stream() // .map(pos -> plotInfoProvider.getPlotByPlotId(pos.getPlotId())) // .collect(Collectors.toSet()); for (PlotOrSpecimen pos : plotsByTraitInstance.getPlotSpecimens(ti)) { if (usedPlotSpecimens.isEmpty() || usedPlotSpecimens.contains(pos)) { Consumer<KdxSample> visitor = new Consumer<KdxSample>() { @Override public void accept(KdxSample sample) { if (InstanceIdentifierUtil.getInstanceIdentifier(sample).equals(tiIdentifier)) { if (checkIfSelected(sample, min, max) == AxisType.Y) { intervalMarker = new IntervalMarker( Double.parseDouble(sample.getTraitValue()) - 0.1, Double.parseDouble(sample.getTraitValue()) + 0.1); intervalMarker.setAlpha(0.3f); intervalMarker.setPaint(Color.RED); Stroke stroke = new BasicStroke(); intervalMarker.setOutlinePaint(Color.RED); intervalMarker.setOutlineStroke(stroke); addRangeMarker(intervalMarker); } } } }; plotInfoProvider.visitSamplesForPlotOrSpecimen(pos, visitor); } } } } getChartPanel().repaint(); if (null != curationControls) { curationControls.updateButtons(false); } }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a waterfall chart. 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 WaterfallBarRenderer} as the renderer. * /*from w w w . ja v a 2 s . c o m*/ * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (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 waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a waterfall chart. 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 WaterfallBarRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted).//from ww w .j av a 2 s .c o m * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (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 waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:app.RunApp.java
/** * Load dataset/*ww w . ja v a2 s . co m*/ * * @param arffFilename Arff filename * @param xmlFilename Xml filename */ private void loadDataset(String arffFilename, String xmlFilename) { try { export2.setVisible(true); if (tabsDependences.getSelectedIndex() == 0) { jLabelChiFiText.setVisible(true); } else { jLabelChiFiText.setVisible(false); } trainDataset = null; testDataset = null; //new Instances if (xmlFilename == null) { MekaToMulan m = new MekaToMulan(); m.convert(arffFilename, arffFilename + "_mulan"); dataset = new MultiLabelInstances(arffFilename + "_mulan.arff", arffFilename + "_mulan.xml"); File f2 = new File(arffFilename + "_mulan.xml"); f2.delete(); } else { dataset = new MultiLabelInstances(arffFilename, xmlFilename); } labelAppearances = MetricUtils.getImbalancedDataByAppearances(dataset); labelAppearances = MetricUtils.sortByFrequency(labelAppearances); imbalancedLabels = MetricUtils.getImbalancedDataByIRInterClass(dataset, labelAppearances); IRIntraClass = MetricUtils.getIRIntraClassValues(imbalancedLabels); HeapSort.sort(IRIntraClass); IRIntraClass = HeapSort.getSortedArray(); stat = new Statistics(); stat.calculateStats(dataset); printMainMetrics(dataset); labelsFreqSorted = MetricUtils.getImbalancedDataByAppearances(dataset); CategoryPlot temp1 = labelFrequencyChart.getChart().getCategoryPlot(); temp1.clearRangeMarkers(); ChartUtils.updateValuesBarChart(labelsFreqSorted, dataset.getNumInstances(), temp1); HashMap<Integer, Integer> labelsPerExample = DataInfoUtils.getLabelsetByValues(stat); ChartUtils.updateLineChart(dataset.getNumInstances(), labelsHistogramChart.getChart().getCategoryPlot(), labelsPerExample); temp1 = labelsetsFrequencyChart.getChart().getCategoryPlot(); temp1.clearRangeMarkers(); tmLabelsetFrequency = labelsetsFrequencyTableModel(tableImbalance, dataset, stat, temp1); tmIR = imbalancedTableModel(tableImbalance, dataset); tmLabelFrequency = frequencyTableModel(tableImbalance, dataset); tmAttributes = attributesTableModel(tableImbalance, dataset); tmBox = boxplotTableModel(tableImbalance); tmCoocurrences = labelFrequencyTableModel(tableCoOcurrenceLeft, dataset); tmHeatmap = labelFrequencyTableModel(tableCoOcurrenceLeft, dataset); tmLabelsHistogram = labelsPerExampleTableModel(tableImbalance, labelsPerExample); tmIRInterClass = irInterClassTableModel(tableImbalance); tmIRIntraClass = irIntraClassTableModel(tableImbalance); temp1 = IRLabelsetsChart.getChart().getCategoryPlot(); temp1.clearRangeMarkers(); tmIRLabelset = irLabelsetsTableModel(tableImbalance, stat, IRLabelsetsChart.getChart().getCategoryPlot()); temp1 = IRInterClassChart.getChart().getCategoryPlot(); temp1.clearRangeMarkers(); ChartUtils.updateIRBarChart(labelsFreqSorted, IRInterClass, temp1); temp1 = IRIntraClassChart.getChart().getCategoryPlot(); temp1.clearRangeMarkers(); ChartUtils.updateIRBarChart(labelsFreqSorted, IRIntraClass, temp1); if (tmLabelFrequency != null && tmLabelsetFrequency != null) { switch (tabsImbalance.getSelectedIndex()) { case 0: tableImbalance.setModel(tmLabelFrequency); panelImbalanceLeft.setBorder(javax.swing.BorderFactory.createTitledBorder("Label frequency")); tableImbalance.setDefaultRenderer(Object.class, new DefaultRender()); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 1: tableImbalance.setModel(tmLabelsetFrequency); panelImbalanceLeft .setBorder(javax.swing.BorderFactory.createTitledBorder("Labelset frequency")); tableImbalance.setDefaultRenderer(Object.class, new DefaultRender()); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 2: tableImbalance.setModel(tmLabelsHistogram); panelImbalanceLeft.setBorder(javax.swing.BorderFactory.createTitledBorder("Labels histogram")); tableImbalance.setDefaultRenderer(Object.class, new DefaultRender()); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 3: tableImbalance.setModel(tmIRIntraClass); panelImbalanceLeft .setBorder(javax.swing.BorderFactory.createTitledBorder("Imbalance Ratio intra class")); tableImbalance.setDefaultRenderer(Object.class, new IRRender(1)); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 4: tableImbalance.setModel(tmIRLabelset); panelImbalanceLeft .setBorder(javax.swing.BorderFactory.createTitledBorder("Labelsets Imbalance Ratio")); tableImbalance.setDefaultRenderer(Object.class, new IRRender(1)); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 5: tableImbalance.setModel(tmBox); panelImbalanceLeft.setBorder(javax.swing.BorderFactory.createTitledBorder("Box diagrams")); //tableImbalance.setDefaultRenderer(Object.class, new DefaultRender()); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; case 6: tableImbalance.setModel(tmIRInterClass); panelImbalanceLeft .setBorder(javax.swing.BorderFactory.createTitledBorder("Imbalance ratio inter class")); tableImbalance.setDefaultRenderer(Object.class, new IRRender(1)); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; default: tableImbalance.setModel(tmLabelsHistogram); panelImbalanceLeft.setBorder(javax.swing.BorderFactory.createTitledBorder("Labels histogram")); tableImbalance.setDefaultRenderer(Object.class, new DefaultRender()); panelImbalanceLeft.repaint(); panelImbalanceLeft.validate(); break; } tableImbalance.repaint(); tableImbalance.validate(); if (tabsAttributes.getSelectedIndex() == 0) { tableAttributesLeft.setModel(tmAttributes); panelAttributeLeft .setBorder(javax.swing.BorderFactory.createTitledBorder("Numeric attributes")); tableAttributesLeft.setDefaultRenderer(Object.class, new DefaultRender()); panelAttributeLeft.repaint(); panelAttributeLeft.validate(); } } fillTableChiPhiCoefficients(dataset); //Critical value for 99% confidence double critical_value = 6.635; jTableChiPhi.setDefaultRenderer(Object.class, new BaseRender("chi_fi", critical_value)); fixedTableChiPhi.setDefaultRenderer(Object.class, new BaseRender("chi_fi_fixed", critical_value)); panelChiPhi.repaint(); panelChiPhi.validate(); //tm_coocurrences pairs = AttributePairsUtils.getAttributePairs(dataset); fillTableCoefficients(dataset, "coocurrence"); jTableCoocurrences.setDefaultRenderer(Object.class, new BaseRender("estandar", Double.MAX_VALUE)); fixedTableCoocurrences.setDefaultRenderer(Object.class, new BaseRender("chi_fi_fixed", Double.MAX_VALUE)); panelCoOcurrenceValues.repaint(); panelCoOcurrenceValues.validate(); fillTableCoefficients(dataset, "heapmap"); jTableHeatmap.setDefaultRenderer(Object.class, new BaseRender("heatmap", Double.MAX_VALUE)); fixedTableHeatmap.setDefaultRenderer(Object.class, new BaseRender("chi_fi_fixed", Double.MAX_VALUE)); panelHeatmapValues.repaint(); panelHeatmapValues.validate(); tableCoOcurrenceLeft.setRowSelectionAllowed(true); tableCoOcurrenceLeft.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tableCoOcurrenceLeft.setModel(tmCoocurrences); tableHeatmapLeft.setModel(tmHeatmap); ArrayList<String> seleccionados = new ArrayList(); /* int firstSelected=10; if(firstSelected> dataset.getNumLabels()) { firstSelected = dataset.getNumLabels(); } String current; for(int i=0;i<firstSelected; i++) { current = (tableCoOcurrenceLeft.getValueAt(i, 0).toString()); if(current != null){ seleccionados.add(current); } else break; } */ seleccionados = selectTopCoocurrenceLabels(10, true); ArrayList<AttributesPair> selectedPairs = AttributePairsUtils.findSelectedAttributesPair(pairs, seleccionados); String[] labelname1 = Utils.listToArray(seleccionados); graphComponent = createJGraphX(panelCoOcurrenceRight, selectedPairs, labelname1, graphComponent); heatMap = createHeatmapGraph(panelHeatmap, getHeatMapCoefficients(), null, heatMap); // jpanel8 box diagram labelsBoxDiagram.getChart().getXYPlot().clearAnnotations(); labelsBoxDiagram.getChart().setTitle(""); attributesBoxDiagram2.getChart().getXYPlot().clearAnnotations(); attributesBoxDiagram2.getChart().setTitle(""); DefaultXYDataset xyseriescollection = new DefaultXYDataset(); DefaultXYDataset xyseriescollection1 = new DefaultXYDataset(); labelsBoxDiagram.getChart().getXYPlot().setDataset(xyseriescollection); labelsBoxDiagram.getChart().getXYPlot().setDataset(1, xyseriescollection1); attributesBoxDiagram2.getChart().getXYPlot().setDataset(xyseriescollection); attributesBoxDiagram2.getChart().getXYPlot().setDataset(1, xyseriescollection1); jButtonSaveDatasets.setEnabled(false); jComboBoxSaveFormat.setEnabled(false); } catch (InvalidDataFormatException ex) { Logger.getLogger(CrossValidationExperiment.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.INFORMATION_MESSAGE); Logger.getLogger(CrossValidationExperiment.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jfree.chart.ChartFactory.java
/** * Creates a waterfall chart. 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 WaterfallBarRenderer} as the renderer. * * @param title the chart title ({@code null} permitted). * @param categoryAxisLabel the label for the category axis * ({@code null} permitted). * @param valueAxisLabel the label for the value axis ({@code null} * permitted).//from w w w.ja va2 s. c o m * @param dataset the dataset for the chart ({@code null} permitted). * * @return A waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); // FIXME create a new method for the horizontal version // if (orientation == PlotOrientation.HORIZONTAL) { // ItemLabelPosition position = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, // TextAnchor.CENTER, Math.PI / 2.0); // renderer.setBasePositiveItemLabelPosition(position); // renderer.setBaseNegativeItemLabelPosition(position); // } ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setDefaultPositiveItemLabelPosition(position); renderer.setDefaultNegativeItemLabelPosition(position); StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setDefaultToolTipGenerator(generator); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.BLACK); plot.addRangeMarker(baseline, Layer.FOREGROUND); JFreeChart chart = new JFreeChart(title, plot); currentTheme.apply(chart); return chart; }