List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates and returns a time series chart. A time series chart is an * {@link XYPlot} with a {@link DateAxis} for the x-axis and a * {@link NumberAxis} for the y-axis. The default renderer is an * {@link XYLineAndShapeRenderer}. /*from ww w.j av a2 s.c om*/ * <P> * A convenient dataset to use with this chart is a * {@link org.jfree.data.time.TimeSeriesCollection}. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> 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 time series chart. */ public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java
private void generateGraph(Why why) { overallMinMax[0] = null;//from ww w. ja v a2s . co m overallMinMax[1] = null; if (chartPanel != null) { for (EventListener cml : chartPanel.getListeners(ChartMouseListener.class)) { chartPanel.removeChartMouseListener((ChartMouseListener) cml); } } Bag<String> missingOrBad = new TreeBag<>(); Bag<String> suppressed = new TreeBag<>(); final BoxAndWhiskerCategoryDataset dataset = createSampleDataSet(missingOrBad, suppressed, overallMinMax); final CategoryAxis xAxis = new CategoryAxis(Msg.AXIS_LABEL_TRAIT_INSTANCE()); final NumberAxis yAxis = new NumberAxis(Msg.AXIS_LABEL_SAMPLE_VALUE()); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMaximumBarWidth(.35); // renderer.setItemMargin(.1); renderer.setFillBox(true); renderer.setUseOutlinePaintForWhiskers(true); renderer.setOutliersVisible(showOutliers.isSelected()); renderer.setMeanVisible(showMean.isSelected()); renderer.setMedianVisible(showMedian.isSelected()); // renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot boxplot = new CategoryPlot(dataset, xAxis, yAxis, renderer); chart = new JFreeChart(getTitle(), new Font(FONT_NAME_SANS_SERIF, Font.BOLD, 14), boxplot, true); // dataMin = ((CategoryPlot) chart.getPlot()).getRangeAxis().getLowerBound(); // dataMax = ((CategoryPlot) chart.getPlot()).getRangeAxis().getUpperBound(); CategoryItemRenderer catr = ((CategoryPlot) chart.getPlot()).getRendererForDataset(dataset); TraitColorProvider traitColorProvider = colorProviderFactory.get(); for (TraitInstance ti : traitInstances) { ColorPair colorPair = traitColorProvider.getTraitInstanceColor(ti); if (colorPair != null) { String validName = traitNameStyle.makeTraitInstanceName(ti); if (seriesCountByTraitName.get(validName) != null) { catr.setSeriesPaint(seriesCountByTraitName.get(validName), colorPair.getBackground()); } } } // ((CategoryPlot) chart.getPlot()).setRenderer(catr); chartPanel = new KDXploreChartPanel(chart); chartPanel.addChartMouseListener(chartMouseListener); // TODO check if we should be checking syncedOption if (marker != null && syncedOption.getSyncWhat().isSync()) { ((CategoryPlot) getChart().getPlot()).addRangeMarker(marker); // curationControls.setSyncedState(true); } if (why.needsReport()) { String msg = VisToolData.createReportText(missingOrBad, suppressed); if (!Check.isEmpty(msg)) { if (why.needsLeadingNewline()) { reportTextArea.append("\n"); } reportTextArea.append("==== "); reportTextArea.append(why.displayValue); reportTextArea.append("\n"); reportTextArea.append(msg); } } splitPane.setRightComponent(chartPanel); this.updateUI(); this.repaint(); }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates and returns a default instance of an XY bar chart. * <P> //from w w w.j a v a2s .co m * The chart object returned by this method uses an {@link XYPlot} instance * as the plot, with a {@link DateAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the * renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param dateAxis make the domain axis display dates? * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the 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 An XY bar chart. */ public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } ValueAxis domainAxis = null; if (dateAxis) { domainAxis = new DateAxis(xAxisLabel); } else { NumberAxis axis = new NumberAxis(xAxisLabel); axis.setAutoRangeIncludesZero(false); domainAxis = axis; } ValueAxis valueAxis = new NumberAxis(yAxisLabel); XYBarRenderer renderer = new XYBarRenderer(); if (tooltips) { XYToolTipGenerator tt; if (dateAxis) { tt = StandardXYToolTipGenerator.getTimeSeriesInstance(); } else { tt = new StandardXYToolTipGenerator(); } renderer.setBaseToolTipGenerator(tt); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java
private JFreeChart createChart(XYDataset data) { ValueAxis timeAxis = new DateAxis("Date/Time"); timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis timeAxis.setUpperMargin(0.02);// w w w.jav a 2 s. c o m NumberAxis valueAxis = new NumberAxis("Value"); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null); plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null, null)); JFreeChart chart = new JFreeChart("Cookie values over time", JFreeChart.DEFAULT_TITLE_FONT, plot, false); return chart; }
From source file:cs.gui.stats.PerformanceStats.java
private ChartPanel createChart(String axisLabel, int type) { int width = (screenSize.width - (screenSize.width / 35)); int height = (int) (screenSize.height - (screenSize.height / (double) 4)); //int width = (screenSize.width - (screenSize.width / 35)) / 2; //int height = (int) (screenSize.height - (screenSize.height / (double) 4)) / 2; lastValue = new double[SUBPLOT_COUNT]; //================= visualise standard chart ========================== CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); lastValue[0] = 100D;/* w ww . j av a 2 s . c om*/ TimeSeries timeseries = null; XYPlot xyplot = null; //add new timeseries to modularity row datasets[type] = new TimeSeriesCollection(); NumberAxis numberaxis = new NumberAxis(axisLabel); numberaxis.setAutoRangeIncludesZero(true); //fast StandardXYItemRenderer xyItemRender = new StandardXYItemRenderer(); //original //xyItemRender = new StandardXYItemRenderer(); xyItemRender.setSeriesStroke(0, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(1, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(2, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(3, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); //TODO colours need to be defined statically before the renderer is created! xyplot = new XYPlot(datasets[type], null, numberaxis, xyItemRender); switch (type) { case 0: { xyItemRender.setSeriesPaint(0, Color.BLACK); timeseries = new TimeSeries("Number of existing threads", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); timeseries = new TimeSeries("Number of answered threads", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 1: { xyItemRender.setSeriesPaint(0, Color.YELLOW); timeseries = new TimeSeries("Mean thread answer time (per day)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 2: { xyItemRender.setSeriesPaint(0, Color.GRAY); timeseries = new TimeSeries("Number of thread replies", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 3: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("New thread arrival activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(1, Color.BLUE); timeseries = new TimeSeries("Thread reply activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 4: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("Mean thread aswer time (per month)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; } NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.add(xyplot); ChartPanel chart = null; switch (type) { case 0: { jfreechart1 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart1.getSubtitle(0); //set legend fonts jfreechart1.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart1.setBorderPaint(Color.black); jfreechart1.setBorderVisible(true); jfreechart1.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis1 = combineddomainxyplot.getDomainAxis(); dateAxis1 = (DateAxis) valueAxis1; if (scope1 == 0) { valueAxis1.setAutoRange(true); } else { valueAxis1.setFixedAutoRange(scope1); } chart = new ChartPanel(jfreechart1); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis1, dateAxis1, ddlScope1)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart1.setAntiAlias(false); } break; case 1: { jfreechart2 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart2.getSubtitle(0); //set legend fonts jfreechart2.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart2.setBorderPaint(Color.black); jfreechart2.setBorderVisible(true); jfreechart2.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis2 = combineddomainxyplot.getDomainAxis(); dateAxis2 = (DateAxis) valueAxis2; if (scope2 == 0) { valueAxis2.setAutoRange(true); } else { valueAxis2.setFixedAutoRange(scope2); } chart = new ChartPanel(jfreechart2); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis2, dateAxis2, ddlScope2)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart2.setAntiAlias(false); } break; case 2: { jfreechart3 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart3.getSubtitle(0); //set legend fonts jfreechart3.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart3.setBorderPaint(Color.black); jfreechart3.setBorderVisible(true); jfreechart3.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis3 = combineddomainxyplot.getDomainAxis(); dateAxis3 = (DateAxis) valueAxis3; if (scope3 == 0) { valueAxis3.setAutoRange(true); } else { valueAxis3.setFixedAutoRange(scope3); } chart = new ChartPanel(jfreechart3); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis3, dateAxis3, ddlScope3)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart3.setAntiAlias(false); } break; case 3: { jfreechart4 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart4.getSubtitle(0); //set legend fonts jfreechart4.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart4.setBorderPaint(Color.black); jfreechart4.setBorderVisible(true); jfreechart4.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis4 = combineddomainxyplot.getDomainAxis(); dateAxis4 = (DateAxis) valueAxis4; if (scope4 == 0) { valueAxis4.setAutoRange(true); } else { valueAxis4.setFixedAutoRange(scope4); } chart = new ChartPanel(jfreechart4); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis4, dateAxis4, ddlScope4)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart4.setAntiAlias(false); } break; case 4: { jfreechart5 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart5.getSubtitle(0); //set legend fonts jfreechart5.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart5.setBorderPaint(Color.black); jfreechart5.setBorderVisible(true); jfreechart5.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis5 = combineddomainxyplot.getDomainAxis(); dateAxis5 = (DateAxis) valueAxis5; if (scope5 == 0) { valueAxis5.setAutoRange(true); } else { valueAxis5.setFixedAutoRange(scope5); } chart = new ChartPanel(jfreechart5); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis5, dateAxis5, ddlScope5)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart5.setAntiAlias(false); } break; } return chart; }
From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java
private JFreeChart createChart(XYDataset dataset, boolean createLegend) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, createLegend, // include legend true, // tooltips false // urls );//from w w w. j av a2 s . c om chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); DeviationRenderer renderer = new DeviationRenderer(true, false); // colors if (dataset.getSeriesCount() == 1) { renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d)); } else { // special case needed for avoiding devision by zero for (int i = 0; i < dataset.getSeriesCount(); i++) { renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesPaint(i, getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1))); } } // background for bounds if (plotBounds) { float[] dashArray = new float[] { 7, 14 }; renderer.setSeriesStroke(boundsSeriesIndex, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0)); renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter()); renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY); } // alpha renderer.setAlpha(0.25f); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); if (axis[INDEX] < 0) { xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); xAxis.setLabel(SERIESINDEX_LABEL); Range range = getRangeForName(SERIESINDEX_LABEL); if (range == null) { xAxis.setAutoRange(true); xAxis.setAutoRangeStickyZero(false); xAxis.setAutoRangeIncludesZero(false); } else { xAxis.setRange(range, true, false); } } else { xAxis.setLabel(dataTable.getColumnName(axis[INDEX])); Range range = getRangeForDimension(axis[INDEX]); if (range == null) { xAxis.setAutoRange(true); xAxis.setAutoRangeStickyZero(false); xAxis.setAutoRangeIncludesZero(false); } else { xAxis.setRange(range, true, false); } } xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel(VALUEAXIS_LABEL); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); setYAxisRange(yAxis); yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); return chart; }
From source file:ec.util.chart.swing.JTimeSeriesChart.java
private void growSubPlots(int size) { for (int i = 0; i < size; i++) { XYPlot plot = new XYPlot(); for (int rendererIndex = 0; rendererIndex < supportedRendererTypes.size(); rendererIndex++) { SeriesIndexResolver resolver = SeriesIndexResolver.create(plot, rendererIndex); JTimeSeriesRendererSupport support = new RendererSupport(resolver); plot.setRenderer(rendererIndex, support.createRenderer(supportedRendererTypes.get(rendererIndex))); }//from www.j ava 2s . co m NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2)); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); plot.setRangeAxis(rangeAxis); mainPlot.add(plot); onDatasetChange(plot); onColorSchemeSupportChange(plot); onValueFormatChange(plot); onNoDataMessageChange(plot); onElementVisibleChange(plot); onFontSupportChange(plot); } }
From source file:org.oscarehr.web.OcanReportingAction.java
private JFreeChart generateChart(String title, String needType, String clientNeedType, List<IndividualNeedsOverTimeChartBean> chartBeanList) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (IndividualNeedsOverTimeChartBean chartBean : chartBeanList) { dataset.addValue(chartBean.getNeedsCountMap().get(needType), "Staff", chartBean.getLabel()); }/*from ww w . j a v a 2 s . c om*/ for (IndividualNeedsOverTimeChartBean chartBean : chartBeanList) { dataset.addValue(chartBean.getNeedsCountMap().get(clientNeedType), "Consumer", chartBean.getLabel()); } JFreeChart chart = ChartFactory.createLineChart(title, // chart title "OCANs", // x axis label "# of " + WordUtils.capitalize(needType) + " Needs", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); LineAndShapeRenderer renderer = new LineAndShapeRenderer(); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickMarksVisible(true); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected void configureRangeAxis(final CategoryPlot cpl, final Font labelFont) { final ValueAxis rangeAxis = cpl.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero()); numberAxis.setAutoRangeStickyZero(isRangeStickyZero()); if (getRangePeriodCount() > 0) { if (getRangeTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat())); } else if (getRangeTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount())); }//from w ww . ja v a2 s. c o m } else { if (getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(getRangeTickFormat()); } else if (getRangeTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); standardTickUnitsApplyFormat(numberAxis, formatter); } } } else if (rangeAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) rangeAxis; if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit( new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (rangeAxis != null) { rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); if (getRangeTitleFont() != null) { rangeAxis.setLabelFont(getRangeTitleFont()); } if (getRangeTickFont() != null) { rangeAxis.setTickLabelFont(getRangeTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { rangeAxis.setLowerBound(getRangeMinimum()); } if (getRangeMaximum() != 1) { rangeAxis.setUpperBound(getRangeMaximum()); } if (getRangeMinimum() == 0 && getRangeMaximum() == 0) { rangeAxis.setAutoRange(true); } } else { if (isAutoRange()) { rangeAxis.setAutoRange(isAutoRange()); } else { double factor = getScaleFactor(); if (factor > DEFAULT_SCALE_FACTOR) { // PRD-5340 hack // this method is invoked after all series were populated // hence the axis already has the graph's max and min values; double lower = rangeAxis.getLowerBound(); if (lower < 0) { lower *= factor; } else if (lower > 0) { lower /= factor; } double upper = rangeAxis.getUpperBound(); if (upper > 0) { upper *= factor; } else if (upper < 0) { upper /= factor; } rangeAxis.setRange(lower, upper); } else { // the 'scaleFactor' property is left intact or has an incorrect value rangeAxis.setUpperBound(getRangeMaximum()); rangeAxis.setLowerBound(getRangeMinimum()); } } } } }
From source file:KIDLYFactory.java
/** * Creates and returns a default instance of a box and whisker chart. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted)./*from w w w. ja v a 2s.co m*/ * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. */ public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel, BoxAndWhiskerXYDataset dataset, boolean legend) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }