List of usage examples for org.jfree.chart.labels StandardCategoryToolTipGenerator StandardCategoryToolTipGenerator
public StandardCategoryToolTipGenerator(String labelFormat, DateFormat formatter)
From source file:org.jfree.chart.demo.EventFrequencyDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Event Frequency Demo", "Category", "Value", categorydataset, PlotOrientation.HORIZONTAL, true, true, false); jfreechart.setBackgroundPaint(new Color(255, 255, 204)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F); categoryplot.setRangeAxis(new DateAxis("Date")); StandardCategoryToolTipGenerator standardcategorytooltipgenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(false, true); lineandshaperenderer.setBaseToolTipGenerator(standardcategorytooltipgenerator); categoryplot.setRenderer(lineandshaperenderer); return jfreechart; }
From source file:demo.BarChartDemo11.java
/** * Creates a sample chart./*from w w w . j ava 2 s. c o m*/ * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Open Source Projects By License", "License", "Percent", dataset); chart.removeLegend(); TextTitle source = new TextTitle( "Source: http://www.blackducksoftware.com/resources/data/top-20-licenses (as at 30 Aug 2013)", new Font("Dialog", Font.PLAIN, 9)); source.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(source); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setDomainGridlinesVisible(true); plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.8f); // 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); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator("{1}: {2} percent", new DecimalFormat("0")); renderer.setBaseToolTipGenerator(tt); // 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)); renderer.setSeriesPaint(0, gp0); return chart; }
From source file:org.gaixie.micrite.jfreechart.style.BarStyle.java
/** * ???//from ww w . j av a2 s . co m * @param chart JFreeChart */ public static void styleOne(JFreeChart chart) { CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); CategoryDataset dca = categoryplot.getDataset(); //? chart.setBackgroundPaint(null); if (dca != null) { BarRenderer categoryitemrenderer = (BarRenderer) categoryplot.getRenderer(); // ? categoryitemrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // categoryitemrenderer.setBaseItemLabelFont( // new Font("", Font.PLAIN, 15)); categoryitemrenderer.setBaseItemLabelsVisible(true); //tooltip categoryplot.getRenderer() .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{0}={2}", new DecimalFormat())); //? for (int i = 0; i < dca.getRowCount(); i++) { int colorIdx = i % colors.length; categoryitemrenderer.setSeriesPaint(i, colors[colorIdx]); } } else { //? categoryplot.setNoDataMessage("NO DATA"); } }
From source file:com.googlecode.logVisualizer.chart.HorizontalBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final BarRenderer renderer = (BarRenderer) 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);/* w w w.j a va2s . co m*/ 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.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 www . j av a 2 s . c o m 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.HorizontalIntervallBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final LayeredBarRenderer renderer = new LayeredBarRenderer(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.black); setBarShadowVisible(chart, false);//from w ww .j a v a 2s .com plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setLowerBound(-35); plot.getRangeAxis().setUpperBound(35); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.green); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER)); renderer.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER)); renderer.setItemLabelAnchorOffset(9.0); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); categoryAxis.setCategoryMargin(0.15); categoryAxis.setUpperMargin(0.0175); categoryAxis.setLowerMargin(0.0175); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.java
/** * Creates a sample chart./*w ww.java 2s . c om*/ * * @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.EventFrequencyDemo.java
/** * Creates a new demo.// ww w . j a v a2s. c om * * @param title the frame title. */ public EventFrequencyDemo(final String title) { super(title); // create a dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // initialise the data... final Day d1 = new Day(12, SerialDate.JUNE, 2002); final Day d2 = new Day(14, SerialDate.JUNE, 2002); final Day d3 = new Day(15, SerialDate.JUNE, 2002); final Day d4 = new Day(10, SerialDate.JULY, 2002); final Day d5 = new Day(20, SerialDate.JULY, 2002); final Day d6 = new Day(22, SerialDate.AUGUST, 2002); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 1"); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 2"); dataset.setValue(new Long(d2.getMiddleMillisecond()), "Series 1", "Requirement 3"); dataset.setValue(new Long(d3.getMiddleMillisecond()), "Series 2", "Requirement 1"); dataset.setValue(new Long(d4.getMiddleMillisecond()), "Series 2", "Requirement 3"); dataset.setValue(new Long(d5.getMiddleMillisecond()), "Series 3", "Requirement 2"); dataset.setValue(new Long(d6.getMiddleMillisecond()), "Series 1", "Requirement 4"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Event Frequency Demo", // title "Category", // domain axis label "Value", // range axis label dataset, // dataset PlotOrientation.HORIZONTAL, // 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(new Color(0xFF, 0xFF, 0xCC)); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f); plot.setRangeAxis(new DateAxis("Date")); final CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); // final CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); // renderer.setToolTipGenerator(toolTipGenerator); // plot.setRenderer(renderer); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.bdb.weather.display.day.DayRainPane.java
/** * Constructor.//from w w w.ja v a 2s . c o m */ public DayRainPane() { setPrefSize(400, 300); chart = ChartFactory.createBarChart("Water Cycle", "Hour", "", null, PlotOrientation.VERTICAL, true, true, false); chartViewer = new ChartViewer(chart); rainPlot = (CategoryPlot) chart.getPlot(); rainPlot.setNoDataMessage("There is no data for the specified day"); BarRenderer renderer = (BarRenderer) rainPlot.getRenderer(); renderer.setBasePaint(Color.BLUE); renderer.setSeriesPaint(0, Color.BLUE); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesItemLabelGenerator(0, new RainItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, Depth.getDefaultFormatter())); StandardCategoryToolTipGenerator ttgen = new StandardCategoryToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, Depth.getDefaultFormatter()); rainPlot.getRenderer().setSeriesToolTipGenerator(0, ttgen); NumberFormat etFormatter = (NumberFormat) Depth.getDefaultFormatter().clone(); etFormatter.setMaximumFractionDigits(etFormatter.getMaximumFractionDigits() + 1); renderer.setSeriesItemLabelGenerator(1, new RainItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, etFormatter)); ttgen = new StandardCategoryToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, etFormatter); rainPlot.getRenderer().setSeriesToolTipGenerator(1, ttgen); rainPlot.setRangeAxis(valueAxis); rainPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90); dataTable = new TableView(); TableColumn<RainItem, Integer> hourColumn = new TableColumn<>(HOUR_ROW_KEY); hourColumn.setCellValueFactory(new PropertyValueFactory(HOUR_ROW_KEY)); dataTable.getColumns().add(hourColumn); TableColumn<RainItem, Depth> rainfallColumn = new TableColumn<>("Rainfall"); rainfallColumn.setCellValueFactory(new PropertyValueFactory(RAIN_ROW_KEY)); dataTable.getColumns().add(rainfallColumn); TableColumn<RainItem, Depth> etColumn = new TableColumn<>(ET_ROW_KEY); etColumn.setCellValueFactory(new PropertyValueFactory(ET_ROW_KEY)); dataTable.getColumns().add(etColumn); this.setTabContents(chartViewer, dataTable); }
From source file:com.xilinx.ultrascale.gui.DMABarChart.java
private void makeChart() { dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart("", "Time Interval", "Throughput (Gbps)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(bg);//from w w w. j a va2 s.c o m TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15)); ttitle.setPaint(Color.WHITE); chart.setTitle(ttitle); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); ValueAxis axis = plot.getRangeAxis(); axis.setUpperBound(64.0); axis.setLowerBound(0.0); axis.setTickLabelPaint(new Color(185, 185, 185)); axis.setLabelPaint(new Color(185, 185, 185)); CategoryAxis caxis = plot.getDomainAxis(); caxis.setTickLabelPaint(new Color(185, 185, 185)); caxis.setLabelPaint(new Color(185, 185, 185)); renderer.setItemMargin(0); renderer.setSeriesPaint(0, new Color(0x2e, 0x90, 0x18));//(0x17, 0x7b, 0x7c)); renderer.setSeriesPaint(1, new Color(0x12, 0x45, 0x73));//(0xa2, 0x45, 0x73) renderer.setSeriesPaint(3, new Color(0xff, 0x80, 0x40)); renderer.setSeriesPaint(2, new Color(0x6f, 0x2c, 0x85)); renderer.setSeriesPaint(4, new Color(0xa1, 0x60, 0x98)); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000"))); //renderer.setMaximumBarWidth(0.05); // addDummy(); }