List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setSeriesLinesVisible
public void setSeriesLinesVisible(int series, boolean visible)
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Modify a scatter plot to show lines instead or shapes or not. * @param scatterPlot Scatter plot to modify * @param enabled Indicates if lines have to be shown *///from ww w . j a va2 s . c o m public static void setScatterPlotLinesEnabled(final JFreeChart scatterPlot, final boolean enabled) { XYPlot plot = (XYPlot) scatterPlot.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); if (enabled) { renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); } else { renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); } renderer.setSeriesPaint(0, Color.RED); plot.setRenderer(0, renderer); }
From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java
public static void plotLineChart(Map<String, List<Double>> series, String filename, String title, String labelX, String labelY) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); for (String label : series.keySet()) { XYSeries data = new XYSeries(label); int t = 0; for (Double d : series.get(label)) { data.add(t, d);//from w w w. j av a 2 s . co m t++; } dataset.addSeries(data); } JFreeChart chart = ChartFactory.createXYLineChart(title, labelX, labelY, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768); }
From source file:y.graphs.ChartHelperELF.java
private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config, ArrayList<ConfigSerie> series) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"), Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend true, // tooltips false // urls );/*from w w w .j a va 2 s. c o m*/ chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 12)); lt.setBackgroundPaint(Color.white); lt.setFrame(new BlockBorder(Color.white)); lt.setVerticalAlignment(VerticalAlignment.CENTER); XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt, RectangleAnchor.TOP_RIGHT); ta.setMaxWidth(config.getLegendSize()); plot.addAnnotation(ta); chart.removeLegend(); plot.setBackgroundPaint(config.getColorBackgroundELF()); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF()); for (int si = 0; si < series.size(); si++) { final ConfigSerie cs = series.get(si); renderer.setSeriesLinesVisible(si, cs.isDrawLine()); final float size = cs.getShapeSize(); renderer.setSeriesShapesVisible(si, size > 0); if (size > 0) renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size)); renderer.setSeriesStroke(si, lineStroke); // renderer.setSeriesOutlineStroke(si, lineStroke); renderer.setSeriesPaint(si, cs.getColor()); } plot.setRenderer(renderer); // x axis final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to rangeAxis.setAutoRange(true); // rangeAxis.setRange(from, to); rangeAxis.setLowerMargin(0.01); rangeAxis.setUpperMargin(0.01); { final Font axisFont = config.getAxisFont(); if (axisFont != null) { rangeAxis.setLabelFont(axisFont); plot.getRangeAxis().setLabelFont(axisFont); } } final String xaxisFmt = config.getAxisFormat(); if (xaxisFmt == null || xaxisFmt.isEmpty()) { double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0); if (diffInDays < 2) rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance())); else rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance())); } else rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance())); final ValueAxis domain = plot.getRangeAxis(); if (config.getForceYmin() != 0 || config.getForceYmax() != 0) domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()), ElfValue.valueIntToDouble(config.getForceYmax())); // title final Font titleFont = config.getTitleFont(); if (titleFont != null) chart.getTitle().setFont(titleFont); return chart; }
From source file:y.graphs.ChartHelperSRB.java
private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config, ArrayList<ConfigSerie> series) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"), Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend true, // tooltips false // urls );//from www . ja v a2 s. c o m chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 12)); lt.setBackgroundPaint(Color.white); lt.setFrame(new BlockBorder(Color.white)); lt.setVerticalAlignment(VerticalAlignment.CENTER); XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt, RectangleAnchor.TOP_RIGHT); ta.setMaxWidth(config.getLegendSize()); plot.addAnnotation(ta); chart.removeLegend(); plot.setBackgroundPaint(config.getColorBackgroundSRB()); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB()); for (int si = 0; si < series.size(); si++) { final ConfigSerie cs = series.get(si); renderer.setSeriesLinesVisible(si, cs.isDrawLine()); final float size = cs.getShapeSize(); renderer.setSeriesShapesVisible(si, size > 0); if (size > 0) renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size)); renderer.setSeriesStroke(si, lineStroke); // renderer.setSeriesOutlineStroke(si, lineStroke); renderer.setSeriesPaint(si, cs.getColor()); } plot.setRenderer(renderer); // x axis final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to rangeAxis.setAutoRange(true); // rangeAxis.setRange(from, to); rangeAxis.setLowerMargin(0.01); rangeAxis.setUpperMargin(0.01); { final Font axisFont = config.getAxisFont(); if (axisFont != null) { rangeAxis.setLabelFont(axisFont); plot.getRangeAxis().setLabelFont(axisFont); } } final String xaxisFmt = config.getAxisFormat(); if (xaxisFmt == null || xaxisFmt.isEmpty()) { double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0); if (diffInDays < 2) rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance())); else rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance())); } else rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance())); final ValueAxis domain = plot.getRangeAxis(); if (config.getForceYmin() != 0 || config.getForceYmax() != 0) domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()), ElfValue.valueIntToDouble(config.getForceYmax())); // title final Font titleFont = config.getTitleFont(); if (titleFont != null) chart.getTitle().setFont(titleFont); return chart; }
From source file:Util.PacketGenerator.java
public static void GenerateGraph() { try {//from ww w .j a va 2s . c o m for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); XYSeries matrix = new XYSeries("Matriz", false, true); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Float valorSimu = Float.parseFloat(simuMatriz[i]); matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0); } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Referncia"); ; middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Superior 20%"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Inferior 20%"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart; if (k == 4) { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset); } else { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset); } chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13)); chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10)); chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getDomainAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getRangeAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0.1f }, 0.0f)); renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesPaint(1, Color.BLACK); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.BLACK); int width = (int) (192 * 1.5f); /* Width of the image */ int height = (int) (144 * 1.5f); /* Height of the image */ File XYChart = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java
public static JPanel createXYLineAndShapeRendererChart(XYDataset data, String x, String y, int w, int h) { //XYDataset data = new SampleXYDataset2(); JFreeChart chart = ChartFactory.createScatterPlot(null, // the title of the chart x, // the label for the X axis y, // the label for the Y axis data, // the dataset for the chart PlotOrientation.VERTICAL, // the orientation of the chart true, // a flag specifying whether or not a legend is required true, // a flag specifying whether or not tooltips should be generated false); // a flag specifying whether or not the chart should generate URLs XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(2, true); renderer.setSeriesShapesVisible(2, false); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setDefaultEntityRadius(6);//from ww w.j a v a 2 s . c om plot.setRenderer(renderer); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(w, h)); return chartPanel; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java
public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1, String protocol2) {//from www . ja v a2 s . co m // ? XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??1?1 NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); // ??? // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // ? XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2); /* XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10, Double.parseDouble(abnor.getElementAt(10).getData())); xyplot.addAnnotation(localXYTextAnnotation);*/ XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset2); xyplot.setRenderer(datasetcount, xylineandshaperenderer2); /* System.out.println("DatasetCount="+xyplot.getDatasetCount()); for(int c=0;c<xyplot.getDatasetCount();c++){ System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount()); System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0)); }*/ /* // ??? xylineandshaperenderer2.setBaseShapesVisible(false); // ?? xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setSeriesShape(0, double1); // xylineandshaperenderer2.setSeriesPaint(0, Color.green); xylineandshaperenderer2.setSeriesFillPaint(0, Color.green); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setUseFillPaint(true); xylineandshaperenderer2 .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); */ xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); jfreechart.getLegend().setVisible(true); return jfreechart; }
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(); // ??/* w ww. j a v a2s . 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:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static XYDataset createLineDataset(DataItems dataitems1, DataItems dataitems2, Map<String, ArrayList<LinePos>> mapAB, XYPlot xyplot) { // ????//from w ww.j a v a 2 s. c o m int modelcount = mapAB.keySet().size(); long off1 = dataitems1.getElementAt(0).getTime().getTime(); long off2 = dataitems2.getElementAt(0).getTime().getTime(); long unit = 0; if (dataitems1.getLength() > 0) { unit = dataitems1.getElementAt(1).getTime().getTime() - off1; } else { unit = 3600000; } XYSeriesCollection xyseriescollection = new XYSeriesCollection(); // ?? int colorindex = 0; int renderercount = 2; for (Object se : mapAB.keySet()) { ArrayList<LinePos> s = mapAB.get(se); int oneModelCount = s.size(); ArrayList<DataItems> dslist = new ArrayList<DataItems>(); Iterator it = s.iterator(); System.out.println("**************"); System.out.println("?=" + se + ":=" + oneModelCount); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); // ??? xylineandshaperenderer.setBaseShapesVisible(false); // ?? xylineandshaperenderer.setSeriesLinesVisible(0, true); // xylineandshaperenderer.setSeriesShape(0, double1); //? // xylineandshaperenderer.setSeriesPaint(0, getcolor(colorindex % 9)); xylineandshaperenderer.setSeriesFillPaint(0, getcolor(colorindex % 9)); xylineandshaperenderer.setSeriesOutlinePaint(0, getcolor(colorindex % 9)); colorindex++; xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.0F, 1, 1, 1.0F, new float[] { 15F, 12F }, 0.0F)); // xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer.setBaseItemLabelsVisible(false); while (it.hasNext()) { LinePos temp = (LinePos) it.next(); DataItem d1 = new DataItem(); d1 = dataitems1.getElementAt(temp.A_start); DataItem d2 = new DataItem(); d2 = dataitems2.getElementAt(temp.B_start); DataItems ds1 = new DataItems(); ds1.add1Data(d1); ds1.add1Data(d2); // dslist.add(ds1); XYDataset xydataset1 = createmodeDataset(ds1, off1, se.toString() + ":" + 1, unit); DataItem d3 = new DataItem(); d3 = dataitems1.getElementAt(temp.A_end); DataItem d4 = new DataItem(); d4 = dataitems2.getElementAt(temp.B_end); DataItems ds2 = new DataItems(); ds2.add1Data(d3); ds2.add1Data(d4); // dslist.add(ds2); XYDataset xydataset2 = createmodeDataset(ds2, off1, se.toString() + ":" + 2, unit); int datasetCount = xyplot.getDatasetCount(); XYTextAnnotation localXYTextAnnotation = null; int modelx = (temp.A_start + temp.B_end) / 2; double modely = (Double.parseDouble(dataitems2.getElementAt(temp.A_start).getData()) + Double.parseDouble(dataitems1.getElementAt(temp.B_end).getData())) / 2; /*System.out.println("se=" + se + "::" + "x=" + modelx + "y=" + modely);*/ localXYTextAnnotation = new XYTextAnnotation("" + se + ":" + oneModelCount, modelx, modely); xyplot.addAnnotation(localXYTextAnnotation); /*System.out.println("datasetCount=" + datasetCount);*/ xyplot.setDataset(datasetCount, xydataset1); xyplot.setRenderer(datasetCount, xylineandshaperenderer); xyplot.setDataset(datasetCount + 1, xydataset2); xyplot.setRenderer(datasetCount + 1, xylineandshaperenderer); } } return xyseriescollection; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC xqliu Comment method "createLineChart". * //w w w .j a va2 s. c om * @param title * @param dataset * @param showLegend * @return */ public static JFreeChart createLineChart(String title, XYDataset dataset, boolean showLegend) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ final JFreeChart chart = ChartFactory.createXYLineChart(null, title, Messages.getString("TopChartFactory.Percent"), dataset, PlotOrientation.VERTICAL, //$NON-NLS-1$ showLegend, false, false); final XYPlot plot = chart.getXYPlot(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }