List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);/*from w w w . ja va 2 s . c o m*/ renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); FileOutputStream output; try { output = new FileOutputStream("successGlobalRates" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }
From source file:eu.choreos.vv.chart.YIntervalChart.java
private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // initial series PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*www. j a va2s. c o m*/ // set chart background chart.setBackgroundPaint(Color.white); // set a few custom plot features XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xffffe0)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the plot's axes to display integers TickUnitSource ticks = NumberAxis.createIntegerTickUnits(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setStandardTickUnits(ticks); domain.resizeRange(1.1); domain.setLowerBound(0.5); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setStandardTickUnits(ticks); range.setUpperBound(range.getUpperBound() * 1.1); // render shapes and lines DeviationRenderer renderer = new DeviationRenderer(true, true); plot.setRenderer(renderer); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); //TODO: render the deviation with the same color as the line // renderer.setBaseFillPaint(new Color(255, 200, 200)); // renderer.setUseOutlinePaint(flag); // renderer.setUseFillPaint(flag); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //TODO: fix the visible area to show the deviation return chart; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static JFreeChart createChart2(ArrayList<DataItems> _nor_model, ArrayList<DataItems> _abnor_model, DataItems nor, DataItems abnor, Map<String, ArrayList<LinePos>> mapAB, String chartname, String protocol1, String protocol2) { XYDataset xydataset = createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createXYLineChart(chartname, "", "", xydataset); jfreechart.getLegend().setVisible(false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??/*from w ww .j a va 2 s . com*/ xylineandshaperenderer.setSeriesLinesVisible(0, true); xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesShape(0, double1); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xylineandshaperenderer.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F)); // ? // xylineandshaperenderer.setBaseItemLabelGenerator(new // StandardXYItemLabelGenerator()); // xylineandshaperenderer.setBaseItemLabelsVisible(true); int datasetcount0 = xyplot.getDatasetCount(); XYDataset xydataset1 = createNormalDataset(abnor, protocol2); // xydataset1. XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset1); xyplot.setRenderer(datasetcount, xylineandshaperenderer1); // ??? xylineandshaperenderer1.setBaseShapesVisible(false); // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setSeriesShape(0, double1); // xylineandshaperenderer1.setSeriesPaint(0, Color.green); xylineandshaperenderer1.setSeriesFillPaint(0, Color.green); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer1.setUseFillPaint(true); xylineandshaperenderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // //? /* * for (int i = 0; i < _nor_model.size(); i++) { XYDataset xydataset2 = * createmodeDataset(_nor_model.get(i), "_nor_model" + i); * XYLineAndShapeRenderer xylineandshaperenderer2 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2, xydataset2); * xyplot.setRenderer(2 + i, xylineandshaperenderer2); // ??? * xylineandshaperenderer2.setBaseShapesVisible(false); // ?? * xylineandshaperenderer2.setSeriesLinesVisible(0, true); * xylineandshaperenderer2.setSeriesShape(0, double1); // * xylineandshaperenderer2.setSeriesPaint(0, Color.red); * xylineandshaperenderer2.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer2.setUseFillPaint(true); * xylineandshaperenderer2 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(2.5F)); * * } for (int i = 0; i < _abnor_model.size(); i++) { XYDataset * xydataset3 = createmodeDataset(_abnor_model.get(i), "_abnor_model" + * i); XYLineAndShapeRenderer xylineandshaperenderer3 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2 + * _nor_model.size(), xydataset3); xyplot.setRenderer(i + 2 + * _nor_model.size(), xylineandshaperenderer3); // ??? * xylineandshaperenderer3.setBaseShapesVisible(false); // ?? * xylineandshaperenderer3.setSeriesLinesVisible(0, true); * xylineandshaperenderer3.setSeriesShape(0, double1); // * xylineandshaperenderer3.setSeriesPaint(0, Color.red); * xylineandshaperenderer3.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer3.setUseFillPaint(true); * xylineandshaperenderer3 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer3.setSeriesStroke(0, new BasicStroke(2.5F)); * * } */ // ?? // // ///////////////////////////////// // ? XYDataset xydataset4 = createLineDataset(nor, abnor, mapAB, xyplot); // ??y=1 ValueMarker valuemarker = new ValueMarker(1); // valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); valuemarker.setPaint(Color.black); // ? valuemarker.setStroke(new BasicStroke(1.0F)); // // valuemarker.setLabel(""); //? valuemarker.setLabelFont(new Font("SansSerif", 0, 11)); // ? valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addRangeMarker(valuemarker); // // //jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static void setPieSectionColors(JFreeChart chart, ChartData chartData) { if (chartData.getColors() != null) { String[] colors = chartData.getColors().split(","); for (int i = 0; i < colors.length; i++) { //((PiePlot)chart.getPlot()).setSectionPaint(new Integer(i), ChartUtils.getColor(colors[i].trim())); does not work ((PiePlot) chart.getPlot()).setSectionPaint(i, ChartUtils.getColor(colors[i].trim())); }//w w w . j a va 2 s. com } }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Creates a JFreeChart based on the current query results produced by the * given chart.//from w w w . j a va 2 s.c o m * * @param c * The chart from which to produce a JFreeChart component. Must * not be null. * @return A chart based on the data and settings in the given chart, or * null if the given chart is not sufficiently configured (for * example, if its type is not set) or it is currently unable to * produce a result set. */ public static JFreeChart createChartFromQuery(Chart c) throws SQLException, QueryInitializationException, InterruptedException { logger.debug("Creating JFreeChart for Wabit chart " + c); ChartType chartType = c.getType(); if (chartType == null) { logger.debug("Returning null (chart's type is not set)"); return null; } final JFreeChart chart; if (chartType.getDatasetType().equals(DatasetType.CATEGORY)) { JFreeChart categoryChart = createCategoryChart(c); logger.debug("Made a new category chart: " + categoryChart); if (categoryChart != null && categoryChart.getPlot() instanceof CategoryPlot) { double rotationRads = Math.toRadians(c.getXAxisLabelRotation()); CategoryLabelPositions clp; if (Math.abs(rotationRads) < 0.05) { clp = CategoryLabelPositions.STANDARD; } else if (rotationRads < 0) { clp = CategoryLabelPositions.createUpRotationLabelPositions(-rotationRads); } else { clp = CategoryLabelPositions.createDownRotationLabelPositions(rotationRads); } CategoryAxis domainAxis = categoryChart.getCategoryPlot().getDomainAxis(); domainAxis.setMaximumCategoryLabelLines(5); domainAxis.setCategoryLabelPositions(clp); } chart = categoryChart; } else if (chartType.getDatasetType().equals(DatasetType.XY)) { JFreeChart xyChart = createXYChart(c); logger.debug("Made a new XY chart: " + xyChart); chart = xyChart; } else { throw new IllegalStateException("Unknown chart dataset type " + chartType.getDatasetType()); } if (chart != null) { makeChartNice(chart); } return chart; }
From source file:com.ouc.cpss.view.SupTradeChartBuilder.java
private static JFreeChart createJFreeChart(PieDataset dataset) { /**//from w w w . java 2 s . c o m * JFreeChart */ //? StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); // standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20)); // standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15)); //? standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15)); //? ChartFactory.setChartTheme(standardChartTheme); //?? //createPieChart 2D; createPieChart3D 3D JFreeChart chart = ChartFactory.createPieChart("", dataset, true, true, false); //,? chart.setTitle(new TextTitle("", new Font("", Font.ITALIC, 22))); //? LegendTitle legend = chart.getLegend(0); //,ture,? legend.setItemFont(new Font("", Font.BOLD, 20)); //?(??) PiePlot plot = (PiePlot) chart.getPlot(); //?==? plot.setLabelFont(new Font("", Font.BOLD, 22)); // plot.setBaseSectionOutlinePaint(Color.BLUE); // plot.setBaseSectionOutlineStroke(new BasicStroke(0.5f)); //?,??,?? plot.setDirection(Rotation.CLOCKWISE);//,Rotation.CLOCKWISE //() plot.setStartAngle(70); //??? //plot.setExplodePercent(1, 0.5D); //plot.setExplodePercent("One", 0.5D); //,3D? plot.setExplodePercent(dataset.getKey(0), 0.1d); // plot.setLabelLinkPaint(Color.BLUE); // plot.setLabelOutlinePaint(Color.black); // plot.setLabelShadowPaint(Color.RED); // plot.setSectionPaint(1, Color.BLACK); // :,{0},{1},{2}?,??? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}\r\n{2}", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={2}")); //:(true),(false) plot.setCircular(true); //? plot.setNoDataMessage("??..."); //??? plot.setToolTipGenerator(new StandardPieToolTipGenerator()); // //plot.setURLGenerator(new StandardPieURLGenerator("detail.jsp")); return chart; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
public static void decorateDuplicatePieChart(JFreeChart chart) { if (chart != null) { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { decoratePiePlot(chart);//from w ww . j a v a 2 s . co m // ADD msjian TDQ-8046 2013-10-17: add the color's control for pie chart PieDataset piedataset = ((PiePlot) plot).getDataset(); for (int i = 0; i < piedataset.getItemCount(); i++) { if (i >= DUPLICATE_PIE_COLOR_LIST.size()) { DUPLICATE_PIE_COLOR_LIST.add(generateRandomColor(DUPLICATE_PIE_COLOR_LIST)); } Comparable<?> key = piedataset.getKey(i); ((PiePlot) plot).setSectionPaint(key, DUPLICATE_PIE_COLOR_LIST.get(i)); } // TDQ-8046~ } } }
From source file:de.bfs.radon.omsimulation.gui.data.OMCharts.java
/** * Creates a chart displaying the radon concentration of a virtual campaign. * Uses red for normal rooms and blue for cellar rooms. * //w w w. j a v a 2 s . com * @param campaign * The campaign object containing all rooms and radon data. * @param preview * Will hide annotations, labels and headlines if true. * @return A chart displaying the radon concentration of a virtual campaign. */ public static JFreeChart createCampaignChart(OMCampaign campaign, boolean preview) { OMRoom[] rooms = new OMRoom[7]; OMRoom[] tmpRooms = campaign.getRooms(); OMRoom tmpCellar = campaign.getCellar(); String variation = campaign.getVariation(); char[] variationChar = variation.toCharArray(); int cellarPosition = 0; for (int i = 0; i < variationChar.length; i++) { if (variationChar[i] == 'C' || variationChar[i] == 'c') { cellarPosition = i / 2; } } int c = 0; for (int i = 0; i < rooms.length; i++) { if (i == cellarPosition) { rooms[i] = tmpCellar; c++; } else { rooms[i] = tmpRooms[i - c]; } } int start = campaign.getStart(); final int finalStart = start; String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + finalStart; int count = 168; double[] values = campaign.getValueChain(); XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries roomSeries1 = new XYSeries(" Radon Rooms"); XYSeries cellarSeries = new XYSeries("Radon Cellar"); XYSeries roomSeries2 = new XYSeries("Radon Rooms"); int cellarSeriesStart = cellarPosition * 24; int cellarSeriesEnd = cellarSeriesStart + 24; double cellarMaximum = campaign.getCellarMaximum(); double cellarMaximumKey = 0; double roomMaximum = campaign.getRoomMaximum(); double roomMaximumKey = 0; if (cellarSeriesStart > 0) { for (int i = 0; i < cellarSeriesStart; i++) { roomSeries1.add(finalStart + i, values[i]); if (values[i] == roomMaximum) { roomMaximumKey = i; } } } for (int i = cellarSeriesStart - 1; i < cellarSeriesEnd; i++) { if (i >= 0) { cellarSeries.add(finalStart + i, values[i]); if (values[i] == cellarMaximum) { cellarMaximumKey = i; } } } if (cellarSeriesEnd < count) { for (int i = cellarSeriesEnd - 1; i < count; i++) { roomSeries2.add(finalStart + i, values[i]); if (values[i] == roomMaximum) { roomMaximumKey = i; } } } dataSet.addSeries(roomSeries1); dataSet.addSeries(cellarSeries); dataSet.addSeries(roomSeries2); JFreeChart chart = ChartFactory.createXYLineChart(title, "T [h]", "Rn [Bq/m\u00B3]", dataSet, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); ValueMarker sepMarker; Color sepColor = Color.BLACK; float[] sepDash = { 1, 2 }; Stroke sepStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, sepDash, 0); RectangleInsets sepLabelInsets = new RectangleInsets(20, -20, 0, 0); Font sepLabelFont = new Font(Font.SANS_SERIF, Font.BOLD, 16); sepMarker = new ValueMarker(finalStart + 0, sepColor, sepStroke); sepMarker.setLabel(rooms[0].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); if (rooms[0].getId() != rooms[1].getId()) { sepMarker = new ValueMarker(finalStart + 23, sepColor, sepStroke); sepMarker.setLabel(rooms[1].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } if (rooms[1].getId() != rooms[2].getId()) { sepMarker = new ValueMarker(finalStart + 47, sepColor, sepStroke); sepMarker.setLabel(rooms[2].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } if (rooms[2].getId() != rooms[3].getId()) { sepMarker = new ValueMarker(finalStart + 71, sepColor, sepStroke); sepMarker.setLabel(rooms[3].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } if (rooms[3].getId() != rooms[4].getId()) { sepMarker = new ValueMarker(finalStart + 95, sepColor, sepStroke); sepMarker.setLabel(rooms[4].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } if (rooms[4].getId() != rooms[5].getId()) { sepMarker = new ValueMarker(finalStart + 119, sepColor, sepStroke); sepMarker.setLabel(rooms[5].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } if (rooms[5].getId() != rooms[6].getId()) { sepMarker = new ValueMarker(finalStart + 143, sepColor, sepStroke); sepMarker.setLabel(rooms[6].getId()); sepMarker.setLabelOffset(sepLabelInsets); sepMarker.setLabelFont(sepLabelFont); plot.addDomainMarker(sepMarker); } double positiveCellarDeviation = campaign.getCellarAverage() + campaign.getCellarDeviation(); double negativeCellarDeviation = campaign.getCellarAverage() - campaign.getCellarDeviation(); IntervalMarker cellarDeviation = new IntervalMarker(negativeCellarDeviation, positiveCellarDeviation); float[] dash = { 5, 3 }; cellarDeviation.setPaint(new Color(222, 222, 255, 128)); cellarDeviation.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(cellarDeviation, Layer.BACKGROUND); ValueMarker arithCellarMarker = new ValueMarker(campaign.getCellarAverage(), new Color(0, 0, 255, 128), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(arithCellarMarker); XYTextAnnotation amCellarLabel = new XYTextAnnotation("C_AM=" + (int) campaign.getCellarAverage(), finalStart + count, campaign.getCellarAverage() * 1.01); plot.addAnnotation(amCellarLabel); XYTextAnnotation sdCellarLabel = new XYTextAnnotation("C_SD=" + (int) campaign.getCellarDeviation(), finalStart + count, (campaign.getCellarAverage() + campaign.getCellarDeviation()) * 1.01); plot.addAnnotation(sdCellarLabel); ValueMarker maxiCellarMarker = new ValueMarker(cellarMaximum, new Color(0, 0, 255, 128), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(maxiCellarMarker); XYTextAnnotation maxCellarLabel = new XYTextAnnotation("C_MAX=" + (int) cellarMaximum, finalStart + count, cellarMaximum * 1.01); plot.addAnnotation(maxCellarLabel); XYPointerAnnotation maxCellarPointer = new XYPointerAnnotation("", finalStart + cellarMaximumKey, cellarMaximum, Math.PI * 1.1); plot.addAnnotation(maxCellarPointer); double positiveRoomDeviation = campaign.getRoomAverage() + campaign.getRoomDeviation(); double negativeRoomDeviation = campaign.getRoomAverage() - campaign.getRoomDeviation(); IntervalMarker roomDeviation = new IntervalMarker(negativeRoomDeviation, positiveRoomDeviation); roomDeviation.setPaint(new Color(255, 222, 222, 128)); roomDeviation.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(roomDeviation, Layer.BACKGROUND); ValueMarker arithRoomMarker = new ValueMarker(campaign.getRoomAverage(), new Color(255, 0, 0, 128), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(arithRoomMarker); XYTextAnnotation amRoomLabel = new XYTextAnnotation("R_AM=" + (int) campaign.getRoomAverage(), finalStart + count, campaign.getRoomAverage() * 1.01); plot.addAnnotation(amRoomLabel); XYTextAnnotation sdRoomLabel = new XYTextAnnotation("R_SD=" + (int) campaign.getRoomDeviation(), finalStart + count, (campaign.getRoomAverage() + campaign.getRoomDeviation()) * 1.01); plot.addAnnotation(sdRoomLabel); ValueMarker maxiRoomMarker = new ValueMarker(roomMaximum, new Color(255, 0, 0, 128), new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addRangeMarker(maxiRoomMarker); XYTextAnnotation maxRoomLabel = new XYTextAnnotation("R_MAX=" + (int) roomMaximum, finalStart + count, roomMaximum * 1.01); plot.addAnnotation(maxRoomLabel); XYPointerAnnotation maxRoomPointer = new XYPointerAnnotation("", finalStart + roomMaximumKey, roomMaximum, Math.PI * 1.1); plot.addAnnotation(maxRoomPointer); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(255, 0, 0, 128)); renderer.setSeriesPaint(1, new Color(0, 0, 255, 128)); renderer.setSeriesPaint(2, new Color(255, 0, 0, 128)); if (preview) { chart.setTitle(""); plot.clearAnnotations(); } return chart; }
From source file:MainUI.java
public static JFreeChart createChart(CategoryDataset dataset) //? { JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset, PlotOrientation.VERTICAL, true, true, false); //JFreeChart chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));//???hi? CategoryPlot plot = (CategoryPlot) chart.getPlot();//?plot CategoryAxis categoryAxis = plot.getDomainAxis();//?? categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));//?? return chart; }
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 ww. j a v a 2 s .co 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; }