List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java
/** * Creates a sample chart./*ww w .j a v a 2 s.c o m*/ * * @param dataset the dataset. * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset, int typeOfChart) { String title = ""; if (typeOfChart == 1) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.compare.todayandyesterday", null); else if (typeOfChart == 2) title = VCTTracUtil.getMessage("vcttrac.year", null) + " : " + (new Date().getYear() + 1900); else if (typeOfChart == 3) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.years", null); // create the chart... JFreeChart chart = ChartFactory.createBarChart(title, null, null, // chart title dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); Paint[] colors = createPaint(); CustomBarRenderer renderer = new CustomBarRenderer(colors); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(renderer); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.15); // CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 12)); if (typeOfChart < 2) domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); else domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo5.java
/** * Creates a sample chart.//w w w . ja v a 2s. c om * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); Shape[] shapes = new Shape[3]; int[] xpoints; int[] ypoints; // right-pointing triangle xpoints = new int[] { -3, 3, -3 }; ypoints = new int[] { -3, 0, 3 }; shapes[0] = new Polygon(xpoints, ypoints, 3); // vertical rectangle shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6); // left-pointing triangle xpoints = new int[] { -3, 3, 3 }; ypoints = new int[] { 0, -3, 3 }; shapes[2] = new Polygon(xpoints, ypoints, 3); DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes); CategoryPlot plot = chart.getCategoryPlot(); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDrawingSupplier(supplier); // set the stroke for each series... plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.12); setCategorySummary(dataset); return chart; }
From source file:wsattacker.plugin.dos.dosExtension.chart.ChartObject.java
public JFreeChart createOverlaidChart() { // ---------------------------- // Data and X-Y-Axis - Response Time Testprobes // - Y-Achse 0 final DateAxis yAxis = new DateAxis("Time"); yAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // - X-Achse 0 final NumberAxis xAxis0 = new NumberAxis("Response Time in ms"); xAxis0.setStandardTickUnits(NumberAxis.createStandardTickUnits()); // xAxis0.setTickUnit( new NumberTickUnit(1) ); // - dataset//from w ww . j av a 2 s.co m // - renderer final XYDataset dataResponseTimeProbes = createDatasetResponseTime("testprobe"); final XYLineAndShapeRenderer rendererResponseTimeProbes = new XYLineAndShapeRenderer(); // StandardXYItemRenderer(); // -> // should // not // be // used rendererResponseTimeProbes.setSeriesPaint(0, Color.blue); rendererResponseTimeProbes.setSeriesShape(0, new Ellipse2D.Double(-1.5, -1.5, 3.0, 3.0)); rendererResponseTimeProbes.setSeriesLinesVisible(0, true); rendererResponseTimeProbes.setSeriesShapesVisible(0, true); rendererResponseTimeProbes.setUseOutlinePaint(false); rendererResponseTimeProbes.setSeriesOutlinePaint(0, Color.black); rendererResponseTimeProbes.setUseFillPaint(true); rendererResponseTimeProbes.setSeriesFillPaint(0, Color.blue); // ---------------------------- // NEW XYPlot (new "Data and X-Y-Axis" from above added as default) final XYPlot plot = new XYPlot(dataResponseTimeProbes, yAxis, xAxis0, rendererResponseTimeProbes); // ---------------------------- // Data and Axis 1 - Response time UNtampered // - Dataset // - Renderer. // - Dataset zu X-Axis 0 mappen final XYDataset dataResponseTimeUntampered = createDatasetResponseTime("untampered"); final XYLineAndShapeRenderer rendererResponseTimeUntampered = new XYLineAndShapeRenderer(); // StandardXYItemRenderer(); // -> // should // not // be // used rendererResponseTimeUntampered.setSeriesPaint(0, new Color(0, 161, 4)); rendererResponseTimeUntampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0)); rendererResponseTimeUntampered.setUseFillPaint(true); rendererResponseTimeUntampered.setSeriesFillPaint(0, Color.white); rendererResponseTimeUntampered.setUseOutlinePaint(false); rendererResponseTimeUntampered.setSeriesOutlinePaint(0, Color.black); rendererResponseTimeUntampered.setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); plot.setDataset(2, dataResponseTimeUntampered); plot.setRenderer(2, rendererResponseTimeUntampered); // plot.mapDatasetToRangeAxis(0, 1); // ---------------------------- // Data and Axis - Response time tampered // - Dataset // - Renderer // - Dataset zu X-Axis 2 mappen final XYDataset dataResponseTimeTampered = createDatasetResponseTime("tampered"); XYLineAndShapeRenderer rendererResponseTimeTampered = new XYLineAndShapeRenderer(); // XYSplineRenderer(); rendererResponseTimeTampered.setSeriesPaint(0, new Color(189, 0, 0)); rendererResponseTimeTampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));// (-2.5, -2.5, 6.0, // 6.0) ); rendererResponseTimeTampered.setUseFillPaint(true); rendererResponseTimeTampered.setSeriesFillPaint(0, Color.white); rendererResponseTimeTampered.setUseOutlinePaint(false); rendererResponseTimeTampered.setSeriesOutlinePaint(0, Color.black); plot.setDataset(3, dataResponseTimeTampered); plot.setRenderer(3, rendererResponseTimeTampered); // plot.mapDatasetToRangeAxis(0, 2); // ---------------------------- // Data and X-Axis - Number Requests UNtampered // - X-Axis Number Requests final NumberAxis xAxis1 = new NumberAxis( "Number Requests Per Interval (" + (model.getIntervalLengthReport() / 1000) + " sec)"); xAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // xAxis1.setTickUnit( new NumberTickUnit(2) ); plot.setRangeAxis(1, xAxis1); // - Dataset // - Renderer final IntervalXYDataset dataNumberRequestsUntampered = createDatasetNumberRequestsUntampered(); final XYBarRenderer rendererNumberRequestsUntampered = new XYBarRenderer(0.2); rendererNumberRequestsUntampered.setShadowVisible(false); rendererNumberRequestsUntampered.setBarPainter(new StandardXYBarPainter()); rendererNumberRequestsUntampered.setSeriesPaint(0, new Color(128, 255, 128)); plot.setDataset(4, dataNumberRequestsUntampered); plot.setRenderer(4, rendererNumberRequestsUntampered); plot.mapDatasetToRangeAxis(4, 1); // ------------------------------- // Data - Number Requests tampered // - Dataset // - Renderer final IntervalXYDataset dataNumberRequestsTampered = createDatasetNumberRequestsTampered(); final XYBarRenderer rendererBarNumberRequestsTampered = new XYBarRenderer(0.2); rendererBarNumberRequestsTampered.setShadowVisible(false); rendererBarNumberRequestsTampered.setBarPainter(new StandardXYBarPainter()); rendererBarNumberRequestsTampered.setSeriesPaint(0, new Color(255, 148, 148)); plot.setDataset(5, dataNumberRequestsTampered); plot.setRenderer(5, rendererBarNumberRequestsTampered); plot.mapDatasetToRangeAxis(5, 1); // ------------------------- // Other formating stuff // - add annotations // final double x = new Day(9, SerialDate.MARCH, // 2002).getMiddleMillisecond(); // final XYTextAnnotation annotation = new // XYTextAnnotation("Anmerkung zu Datenpunkt", x, 1000.0); // annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); // plot.addAnnotation(annotation); // ------------------------- // Create custom LegendTitles // Legend Row 1 LegendTitle legendL1 = new LegendTitle(plot.getRenderer(0)); legendL1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL1.setBorder(0, 0, 0, 0); LegendTitle legendR1 = new LegendTitle(plot.getRenderer(4)); legendR1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendR1.setBorder(0, 0, 0, 0); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.setBorder(0, 0, 0, 0); blockcontainer.add(legendL1, RectangleEdge.LEFT); blockcontainer.add(legendR1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle1 = new CompositeTitle(blockcontainer); compositetitle1.setPosition(RectangleEdge.BOTTOM); // Legend Row 2 LegendTitle legendL2 = new LegendTitle(plot.getRenderer(2)); legendL2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL2.setBorder(0, 0, 0, 0); LegendTitle legendR2 = new LegendTitle(plot.getRenderer(5)); legendR2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendR2.setBorder(0, 0, 0, 0); BlockContainer blockcontainer2 = new BlockContainer(new BorderArrangement()); blockcontainer2.setBorder(0, 0, 0, 0); blockcontainer2.add(legendL2, RectangleEdge.LEFT); blockcontainer2.add(legendR2, RectangleEdge.RIGHT); blockcontainer2.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle2 = new CompositeTitle(blockcontainer2); compositetitle2.setPosition(RectangleEdge.BOTTOM); // Legend Row 3 LegendTitle legendL3 = new LegendTitle(plot.getRenderer(3)); legendL3.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL3.setBorder(0, 0, 0, 0); BlockContainer blockcontainer3 = new BlockContainer(new BorderArrangement()); blockcontainer3.setBorder(0, 0, 0, 0); blockcontainer3.add(legendL3, RectangleEdge.LEFT); blockcontainer3.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle3 = new CompositeTitle(blockcontainer3); compositetitle3.setPosition(RectangleEdge.BOTTOM); // ------------------------- // create Chart // - return a new chart containing the overlaid plot... plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart jFreeChart = new JFreeChart(model.getAttackName() + " - Response Time Plot", // Roundtrip Time Plot JFreeChart.DEFAULT_TITLE_FONT, plot, true); // Add new legend boxes + format jFreeChart.addSubtitle(compositetitle1); jFreeChart.addSubtitle(compositetitle2); jFreeChart.addSubtitle(compositetitle3); // Surpress old Legends LegendTitle legendee2 = jFreeChart.getLegend(0); legendee2.setVisible(false); return jFreeChart; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
/***************************************** INDIVIDUAIS **************************************************/ public ChartPanel precisionrecall(int index) { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Precision Recall", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetprecision(index), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from w w w .j ava 2 s .c o m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.DistributionChart.java
private void initCharts() { boxDataSet = new DefaultBoxAndWhiskerCategoryDataset(); sizeDataSet = new DefaultCategoryDataset(); // Box:/*from www . j a v a 2s .co m*/ NumberAxis yAxis = new NumberAxis("Values"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); boxPlot = new CategoryPlot(boxDataSet, null, yAxis, renderer); drawingSupplier = boxPlot.getDrawingSupplier(); // Bar. NumberAxis rangeAxis2 = new NumberAxis("Values"); rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer2 = new BarRenderer(); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); sizePlot = new CategoryPlot(sizeDataSet, null, rangeAxis2, renderer2); sizePlot.setDomainGridlinesVisible(true); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java
/** * Creates a chart for the specified dataset. * /*from ww w.j a v a2 s . c o m*/ * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); //Creates the xAxis with its label and style NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setLabel(xLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } //Creates the yAxis with its label and style NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setTickLabelsVisible(true); yAxis.setLabel(yLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); Color outboundCol = new Color(Integer.decode(outboundColor).intValue()); //Sets the graph paint scale and the legend paintscale LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(), outboundCol); LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol); for (int ke = 0; ke <= (zvalues.length - 1); ke++) { Double key = (new Double(zvalues[ke])); Color temp = (Color) colorRangeMap.get(key); paintScale.add(zvalues[ke], temp); legendPaintScale.add(0.5 + ke, temp); } //Configures the renderer XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setPaintScale(paintScale); double blockHeight = (new Double(blockH)).doubleValue(); double blockWidth = (new Double(blockW)).doubleValue(); renderer.setBlockWidth(blockWidth); renderer.setBlockHeight(blockHeight); //configures the plot with title, subtitle, axis ecc. XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairPaint(Color.black); plot.setForegroundAlpha(0.66f); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); //Sets legend labels SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels); scaleAxis.setRange(0.5, 0.5 + zvalues.length); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); scaleAxis.setLabel(zLabel); //scaleAxis.setLabelAngle(3.14/2); scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); //draws legend as chart subtitle PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis); psl.setAxisOffset(2.0); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(new RectangleInsets(5, 1, 5, 1)); chart.addSubtitle(psl); if (yLabels != null) { //Sets y legend labels LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white); for (int ke = 0; ke < yLabels.length; ke++) { Color temp = Color.white; legendPaintScale2.add(1 + ke, temp); } SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels); scaleAxis2.setRange(0, (yLabels.length - 1)); scaleAxis2.setPlot(new PiePlot()); scaleAxis2.setGridBandsVisible(false); //draws legend as chart subtitle PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2); psl2.setAxisOffset(5.0); psl2.setPosition(RectangleEdge.LEFT); psl2.setMargin(new RectangleInsets(8, 1, 40, 1)); psl2.setStripWidth(0); psl2.setStripOutlineVisible(false); chart.addSubtitle(psl2); } return chart; }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
public final String chartJobCount() throws Exception { final Calendar calendarToday = CalendarUtils.getCalendarWithoutTime(); final Calendar calendar30 = CalendarUtils.getCalendarWithoutTime(); calendar30.add(Calendar.MONTH, -36); final List<JobCountPerDay> jobCountPerDayList = jobService.getJobCountPerDayAndPeriod(calendar30.getTime(), calendarToday.getTime());/*from w w w . j a v a2s . c om*/ final TimeSeries hitsPerDayData = new TimeSeries("Hits", Day.class); final XYDataset hitsPerDayDataset = new TimeSeriesCollection(hitsPerDayData); this.chart = ChartFactory.createTimeSeriesChart("", super.getText("class.ShowStatisticsAcion.chart.job.count.caption"), "", hitsPerDayDataset, false, true, false); final XYPlot xyplot = (XYPlot) this.chart.getPlot(); for (JobCountPerDay jobCountPerDay : jobCountPerDayList) { final Day day = new Day(jobCountPerDay.getJobDate()); if (jobCountPerDay.getAutomaticallyCleaned()) { final Marker originalEnd = new ValueMarker(day.getFirstMillisecond()); originalEnd.setPaint(new Color(0, 80, 138, 150)); float[] dashPattern = { 6, 2 }; originalEnd.setStroke( new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); originalEnd.setLabel("C"); originalEnd.setAlpha(0.1F); xyplot.addDomainMarker(originalEnd); } hitsPerDayData.add(day, jobCountPerDay.getTotalNumberOfJobs()); } chart.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(false); xyitemrenderer.setSeriesPaint(0, new Color(244, 66, 0)); } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setAutoRange(true); dateaxis.setAutoTickUnitSelection(true); NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return SUCCESS; }
From source file:org.simbrain.plot.histogram.HistogramPanel.java
/** * Create the histogram panel based on the data. *//* w w w . j a v a2 s. com*/ public void createHistogram() { try { if (this.getModel().getData() != null) { mainChart = ChartFactory.createHistogram(title, xAxisName, yAxisName, model.getDataSet(), PlotOrientation.VERTICAL, true, true, false); mainChart.setBackgroundPaint(UIManager.getColor("this.Background")); XYPlot plot = (XYPlot) mainChart.getPlot(); plot.setForegroundAlpha(0.75F); // Sets y-axis ticks to integers. NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); Iterator<ColoredDataSeries> series = model.getSeriesData().iterator(); for (int i = 0; i < model.getData().size(); i++) { if (i < colorPallet.length) { ColoredDataSeries s = series.next(); Color c = s.color; if (c == null) { c = assignColor(); s.color = c; } renderer.setSeriesPaint(i, c, true); } } } else { mainChart = ChartFactory.createHistogram(title, xAxisName, yAxisName, model.getDataSet(), PlotOrientation.VERTICAL, true, true, false); mainChart.setBackgroundPaint(UIManager.getColor("this.Background")); } } catch (IllegalArgumentException iaEx) { iaEx.printStackTrace(); JOptionPane.showMessageDialog(null, iaEx.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (IllegalStateException isEx) { isEx.printStackTrace(); JOptionPane.showMessageDialog(null, isEx.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } mainPanel = new ChartPanel(mainChart); }
From source file:org.metacsp.utility.UI.PlotBoxTLSmall.java
/** * Creates a chart for the PlotBoxBehavior * // w ww. ja v a2 s . com * @param dataset A dataset for the chart. * * @return A chart where the PlotBoxBehavior will be plotted. */ @SuppressWarnings("deprecation") private JFreeChart createChart(CategoryDataset dataset) { // String s = name; String s = null; String tit = null; String ax = null; // if (first) // tit = title + " (EST)"; // else if (last) // ax = "Time"; tit = this.name; chart = ChartFactory.createStackedBarChart(tit, // chart title s, // domain axis label ax, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation false, // legend false, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); chart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); //plot.getCategories(); //CategoryItemRenderer renderer = plot.getRenderer(); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setItemLabelsVisible(true); renderer.setItemLabelGenerator(new LabelGenerator(true)); ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.TOP_RIGHT); renderer.setPositiveItemLabelPositionFallback(pos); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesPositiveItemLabelPosition(i, pos); } /* if (values.elementAt(0) instanceof ResourceLevel) { renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(true)); } else renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(false)); */ renderer.setToolTipGenerator(new PlotBoxTooltip()); plot.setRenderer(renderer); // renderer.getSeriesStroke(0). plot.setForegroundAlpha(0.8f); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(2.0); rangeAxis.setUpperMargin(2.0); //long origin = stl.getSerializableSimpleTimeline().getEarliestStartTime(); //long horizon = stl.getSerializableSimpleTimeline().getLatestEndTime(); long origin = stl.getPulses()[0].longValue(); NumberFormat nf = new DecimalFormat(); rangeAxis.setNumberFormatOverride(nf); if (this.range != null) rangeAxis.setRange(range); //rangeAxis.setRange((new Double(origin)).doubleValue(), (new Double(horizon)).doubleValue()); ///// 0 should be replaced by the start of the horizon renderer.setBase(origin); //renderer.setBase(); for (int i = 0; i < durations.length; i++) { if (stl.isInconsistent(values[i])) renderer.setSeriesPaint(i, new Color(198, 30, 69)); else if (stl.isCritical(values[i])) renderer.setSeriesPaint(i, new Color(238, 234, 111)); else if (stl.isUndetermined(values[i])) renderer.setSeriesPaint(i, new Color(255, 255, 255)); else renderer.setSeriesPaint(i, new Color(111, 180, 238)); renderer.setSeriesOutlinePaint(i, Color.black); } renderer.setBaseSeriesVisibleInLegend(false, false); renderer.setSeriesStroke(0, new BasicStroke(40f)); return chart; }
From source file:org.patientview.radar.service.impl.UtilityManagerImpl.java
public JFreeChart getPatientCountPerUnitChart() { // create dataset String srnsSeries = "SRNS"; String mpgnSeries = "MPGN"; DiagnosisCode srnsCode = new DiagnosisCode(); srnsCode.setId(DiagnosisCode.SRNS_ID); DiagnosisCode mpgnCode = new DiagnosisCode(); mpgnCode.setId(DiagnosisCode.MPGN_ID); Map<Long, Integer> srnsPatientCountMap = getPatientCountPerUnitByDiagnosisCode(srnsCode); Map<Long, Integer> mpgnPatientCountMap = getPatientCountPerUnitByDiagnosisCode(mpgnCode); java.util.List<Centre> centreList = getCentres(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Centre centre : centreList) { String centreCategory = centre.getAbbreviation() != null ? centre.getAbbreviation() : centre.getName(); Integer srnsCount = srnsPatientCountMap.containsKey(centre.getId()) ? srnsPatientCountMap.get(centre.getId()) : null;// w ww. j a v a 2 s. c o m if (srnsCount != null && srnsCount > 0) { dataset.addValue(srnsCount, srnsSeries, centreCategory); } Integer mpgnCount = mpgnPatientCountMap.containsKey(centre.getId()) ? mpgnPatientCountMap.get(centre.getId()) : null; if (mpgnCount != null && mpgnCount > 0) { dataset.addValue(mpgnCount, mpgnSeries, centreCategory); } } // create chart JFreeChart chart = ChartFactory.createBarChart("Total number of registered patients by unit", // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // 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(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); DecimalFormat decimalformat1 = new DecimalFormat("##,###"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); renderer.setItemLabelsVisible(true); renderer.setBaseItemLabelsVisible(true); // 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)); 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)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(new Font("Times New Roman", Font.PLAIN, 12)); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }