List of usage examples for org.jfree.chart.plot XYPlot setRenderer
public void setRenderer(XYItemRenderer renderer)
From source file:userinterface.patientRole.LineChart.java
public LineChart(String applicationTitle, String chartTitle, XYSeries bR, XYSeries pR, XYSeries bS, XYSeries bP, JFrame parent) {/*w w w . jav a 2s .c o m*/ // super(applicationTitle); this.bR = bR; this.pR = pR; this.bS = bS; this.bP = bP; this.parent = parent; dataset = createDataset(); JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "Category", "Vital Signs", createDataset(), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(xylineChart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot plot = xylineChart.getXYPlot(); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.YELLOW); renderer.setSeriesPaint(3, Color.BLUE); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); renderer.setSeriesStroke(1, new BasicStroke(1.0f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f)); plot.setRenderer(renderer); setContentPane(chartPanel); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); }
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 w ww . jav 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: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 v a 2s.c om*/ 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:ac.kaist.ccs.presentation.CCSHubSelectionCost.java
/** * Creates a chart./*from w w w. jav a 2 s.c o m*/ * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title "Number of Hubs", // x axis label "Cost for pipeline transportation \nfrom CO2 emission source node to hubs", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); //renderer.setSeriesLinesVisible(0, false); //renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(minVal - (maxVal - minVal) * 0.05, maxVal + (maxVal - minVal) * 0.05); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:view.App.java
private void renderChart(SpreadObject obj) { try {//from www .ja v a 2s . c o m jPanel3.removeAll(); jPanel3.revalidate(); chart = ChartFactory.createTimeSeriesChart( obj.getBaseStock().getTicker() + " : " + obj.getSecondStock().getTicker(), "date", "spread ratio", createDataset(obj), true, true, false); } catch (ParseException e) { System.out.println(" " + e.toString()); } final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 0, 0)); renderer.setSeriesPaint(0, Color.RED); plot.setRenderer(renderer); axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(false); Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder()); chartPanel.setBorder(border); jPanel3.add(chartPanel); jPanel3.revalidate(); }
From source file:chart.XYChart.java
public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic, double[] YDataNumerical1, double[] YDataNumerical2) { super(applicationTitle); JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "", createDatasetForThree(xData, YDataAnalitic, YDataNumerical1, YDataNumerical2), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(xylineChart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.YELLOW); renderer.setSeriesPaint(3, Color.BLUE); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); renderer.setSeriesStroke(1, new BasicStroke(1.0f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f)); plot.setRenderer(renderer); setContentPane(chartPanel);/* ww w .j av a2 s . c o m*/ // panel.removeAll(); // panel.add(chartPanel); // panel.validate(); }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
public static JFreeChart createBlockingBarChart(String title, HistogramDataset dataset) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = ChartFactory.createHistogram(null, title, "Key frequency", dataset, //$NON-NLS-1$ PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setUpperMargin(0.08); // plot.getRangeAxis().setLowerBound(-0.08); decorateCategoryPlot(chart);/*w w w . j a va2s. c o m*/ plot.setRangeGridlinesVisible(true); XYBarRenderer renderer = new XYBarRenderer() { private static final long serialVersionUID = 4168794048090452033L; @Override public Paint getItemPaint(int row, int column) { return ChartDecorator.COLOR_LIST.get(0); } }; renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setShadowVisible(Boolean.FALSE); plot.setRenderer(renderer); return chart; }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
/** * Creates a sample chart.//from w ww . j a v a 2 s. c o m * * @param dataset a dataset for the chart. * * @return A sample chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setLowerMargin(0.2); xAxis.setUpperMargin(0.2); xAxis.setStandardTickUnits(createStandardDateTickUnits()); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLowerMargin(0.2); yAxis.setUpperMargin(0.2); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseLinesVisible(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0)); renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0)); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f, new float[] { 10.0f, 5.0f }, 0.0f)); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesFillPaint(1, Color.white); renderer.setUseFillPaint(true); renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setDefaultEntityRadius(6); renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100, 3.0, createPieChart())); renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100, 2.0, createBarChart())); plot.setRenderer(renderer); return chart; }
From source file:com.bt.aloha.batchtest.Chart.java
private JFreeChart createChart(XYDataset xydataset, String title, String xLabel, String yLabel) { JFreeChart jfreechart = ChartFactory.createXYLineChart(title, xLabel, yLabel, xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); if (xydataset instanceof IntervalXYDataset) { DeviationRenderer deviationrenderer = new DeviationRenderer(true, true); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200)); xyplot.setRenderer(deviationrenderer); }//www . j a v a 2 s . c o m NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setAutoRange(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:playground.yu.utils.charts.TimeScatterChart.java
private JFreeChart createChart(String title, String timeAxisLabel, String valueAxisLabel, final TimeTableXYDataset dataset) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);//from ww w . ja v a 2 s.c o m NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; boolean tooltips = false; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; boolean urls = false; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); boolean legend = true; JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; // return ChartFactory.createTimeSeriesChart(title, timeAxisLabel, // valueAxisLabel, dataset, true, // legend? // false, // tooltips? // false // URLs? // ); }