List of usage examples for org.jfree.chart.axis NumberAxis setNumberFormatOverride
public void setNumberFormatOverride(NumberFormat formatter)
From source file:org.jfree.chart.demo.StackedBarChartDemo7.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 7", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(); stackedbarrenderer.setRenderAsPercentages(true); stackedbarrenderer.setDrawBarOutline(false); stackedbarrenderer.setBaseItemLabelsVisible(true); stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); return jfreechart; }
From source file:org.jfree.chart.demo.StackedXYBarChartDemo3.java
private static JFreeChart createChart(TableXYDataset tablexydataset) { DateAxis dateaxis = new DateAxis("Year"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);//from w w w . j a va 2s .com dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Tonnes"); numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%")); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.29999999999999999D); stackedxybarrenderer.setRenderAsPercentages(true); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, new Color(64, 0, 0), 0.0F, 0.0F, Color.red); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, new Color(0, 64, 0), 0.0F, 0.0F, Color.green); stackedxybarrenderer.setSeriesPaint(0, gradientpaint); stackedxybarrenderer.setSeriesPaint(1, gradientpaint1); stackedxybarrenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2} tonnes", new SimpleDateFormat("yyyy"), new DecimalFormat("#,##0"))); XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); JFreeChart jfreechart = new JFreeChart("Waste Management", xyplot); jfreechart.setBackgroundPaint(Color.white); jfreechart.addSubtitle(new TextTitle("St Albans City and District Council")); return jfreechart; }
From source file:org.jfree.chart.demo.ParetoChartDemo1.java
public static JFreeChart createChart(CategoryDataset acategorydataset[]) { JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects", acategorydataset[0], PlotOrientation.VERTICAL, true, true, false); jfreechart.addSubtitle(new TextTitle("By Programming Language")); jfreechart.addSubtitle(new TextTitle("As at 5 March 2003")); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.02D);/*from ww w . ja v a 2 s . c o m*/ categoryaxis.setUpperMargin(0.02D); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); NumberAxis numberaxis1 = new NumberAxis("Percent"); numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance()); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setDataset(1, acategorydataset[1]); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.mapDatasetToRangeAxis(1, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return jfreechart; }
From source file:org.jfree.chart.demo.BarChart3DDemo4.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart3D("Student Grades", "Students", "Grade", categorydataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); CustomBarRenderer3D custombarrenderer3d = new CustomBarRenderer3D(); custombarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); custombarrenderer3d.setBaseItemLabelsVisible(true); custombarrenderer3d.setItemLabelAnchorOffset(10D); custombarrenderer3d.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); categoryplot.setRenderer(custombarrenderer3d); ValueMarker valuemarker = new ValueMarker(0.69999999999999996D, new Color(200, 200, 255), new BasicStroke(1.0F), new Color(200, 200, 255), new BasicStroke(1.0F), 1.0F); categoryplot.addRangeMarker(valuemarker, Layer.BACKGROUND); custombarrenderer3d.setBaseItemLabelsVisible(true); custombarrenderer3d.setMaximumBarWidth(0.050000000000000003D); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("Minimum grade to pass", "Robert", 0.70999999999999996D); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categorytextannotation.setFont(new Font("SansSerif", 0, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categoryplot.addAnnotation(categorytextannotation); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); numberaxis.setUpperMargin(0.10000000000000001D); return jfreechart; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static ValueAxis createNumberAxis(JFreeChart chart, ChartAxisData chartAxisData) { NumberAxis numberAxis = new NumberAxis(chartAxisData.getLabel()); if (chartAxisData.getFormat() != null) numberAxis.setNumberFormatOverride(new DecimalFormat(chartAxisData.getFormat())); return numberAxis; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java
private static JFreeChart createXYLineChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? );/*from w w w .ja v a 2 s . c o m*/ chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java
private static JFreeChart createXYAreaChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYAreaChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? );//from w w w. j a v a2 s . c o m chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java
private static JFreeChart createXYStepAreaChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYStepAreaChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? );//ww w . ja v a2 s. c o m chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java
private static JFreeChart createScatterChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? );/*from w w w. j av a2 s.c o m*/ chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:graph.jfreecharts.GraphFunction.java
/** * A custom xyerror renderer because jfreecharts does not * have it supported in the api.//from w w w . ja v a2 s. c o m * @param title the graph title * @param xAxisLabel the xaxis title * @param yAxisLabel the yaxis title * @param dataset the xydataset * @param orientation the plot orientation * @param legend true to turn on legend * @param tooltips true to turn on tooltips (the pop up when right click) * @param urls // no idea what this is for * @return */ private static JFreeChart createXYIntervalChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setDrawXError(true); renderer.setDrawYError(true); xAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }