List of usage examples for org.jfree.chart ChartFactory createLineChart
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java
public IntensityPlotWindow(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue() .getMatchingPeakLists()[0];// w w w. ja v a 2 s .c o m String title = "Intensity plot [" + peakList + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue(); boolean isCombo = (xAxisValueSource instanceof ParameterWrapper) && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter)); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } else { chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); } chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot plot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; if (plot instanceof CategoryPlot) yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis(); else yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis(); NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat(); if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT) yAxisFormat = MZmineCore.getConfiguration().getRTFormat(); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); // Add the Windows menu JMenuBar menuBar = new JMenuBar(); menuBar.add(new WindowsMenu()); setJMenuBar(menuBar); pack(); // get the window settings parameter ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class); WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings); // update the window and listen for changes settings.applySettingsToWindow(this); this.addComponentListener(settings); }
From source file:br.com.oncast.dev.lobo.report.JFreeChartReportPlotter.java
/** * Plot a graphic for the {@link MetricAndValues}. * @param metricAndValues The source for the graphic. * @param baseDir The base dir for plot the graphics. * @throws IOException in case of exception on writing the image. *//*from w w w .java 2 s . c o m*/ private void plotGraphic(final MetricAndValues metricAndValues, final File baseDir) throws IOException { final MergeMetric mergeMetric = metricAndValues.mergeMetric; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (final MetricValue metricValue : metricAndValues.metricValues) dataset.addValue(metricValue.getValue(), mergeMetric.getMetric(), metricValue.getBuildName()); final JFreeChart chart = ChartFactory.createLineChart(mergeMetric.getMetric(), TITLE_BUILD, TITLE_VALUE, dataset, PlotOrientation.VERTICAL, true, false, false); final BufferedImage bufferedImage = chart.createBufferedImage(GRAPHIC_WIDTH, GRAPHIC_HEIGHT); final String filePath = mergeMetric.getCase() + "/"; final String fileName = mergeMetric.getScenario() + "-" + mergeMetric.getMetric() + "." + GRAPHIC_FORMAT; final String fullFileName = filePath + fileName; final File outputFileImage = new File(baseDir, fullFileName); outputFileImage.getParentFile().mkdirs(); ImageIO.write(bufferedImage, GRAPHIC_FORMAT, outputFileImage); }
From source file:edu.ucla.stat.SOCR.chart.demo.StatisticalBarChartDemo1.java
/** * Creates a sample chart./*from ww w . ja v a2s . c om*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... 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); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setErrorIndicatorPaint(Color.black); // renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override public ViewBuilder buildView(Object o) { if (o == treeModel.getCentralWeightsNode()) { JFreeChart chart = null;/* w w w .j av a2 s. c o m*/ if (isChartDrawable()) { chart = ChartFactory.createLineChart("", "Criterion", "Central Weight", centralWeightsDataset, PlotOrientation.VERTICAL, true, true, false); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, true); chart.getCategoryPlot().setRenderer(renderer); } ResultsTable table = new ResultsTable(centralWeightsTM); table.setAutoCreateRowSorter(true); table.setDefaultRenderer(Object.class, new CentralWeightsCellRenderer(1.0)); table.getTableHeader().setToolTipText("CF = Confidence Factor"); return new ViewWithHeader("Central weight vectors", new ResultsView(parent, table, chart, FileNames.ICON_SCRIPT)); } else if (o == treeModel.getRankAcceptabilitiesNode()) { JFreeChart chart = null; if (isChartDrawable()) { chart = ChartFactory.createStackedBarChart("", "Alternative", "Rank Acceptability", rankAcceptabilitiesDataset, PlotOrientation.VERTICAL, true, true, false); chart.getCategoryPlot().getRangeAxis().setUpperBound(1.0); } ResultsTable table = new ResultsTable(rankAcceptabilitiesTM); table.setAutoCreateRowSorter(true); table.setDefaultRenderer(Object.class, new ResultsCellColorRenderer(1.0)); table.getTableHeader() .setToolTipText("Ranks in descending order, 1 is the best, 2 the second best, etc."); return new ViewWithHeader("Rank acceptability indices", new ResultsView(parent, table, chart, FileNames.ICON_SCRIPT)); } else { return super.buildView(o); } }
From source file:se.backede.jeconomix.forms.report.SingleTransactionReport.java
public void addLineChart(TransactionReportDto reports) { JFreeChart lineChart = ChartFactory.createLineChart("Total expenses", "Month", "Kronor", createDataset(reports), PlotOrientation.VERTICAL, false, true, false); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight())); lineChartPanel.setLayout(new BorderLayout()); lineChartPanel.add(chartPanel, BorderLayout.NORTH); }
From source file:org.jreserve.gui.calculations.factor.editor.AccidentFactorPlot.java
private Component createPlotComponent() { boolean legend = true; boolean tooltips = false; boolean urls = false; chart = ChartFactory.createLineChart(null, null, null, dataSet, PlotOrientation.VERTICAL, legend, tooltips, urls);/* w ww. j av a 2 s . co m*/ CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.GRAY); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.WHITE); plot.setDomainGridlinePaint(Color.WHITE); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeStickyZero(true); renderer = plot.getRenderer(); if (renderer instanceof LineAndShapeRenderer) { LineAndShapeRenderer lasr = (LineAndShapeRenderer) renderer; lasr.setBaseShapesVisible(true); lasr.setDrawOutlines(true); lasr.setUseFillPaint(true); lasr.setBaseStroke(new BasicStroke(2)); ColorGenerator colors = new DefaultColorGenerator(); int count = dataSet.getRowCount(); int r = 3; Shape circle = new Ellipse2D.Float(-r, -r, 2 * r, 2 * r); for (int i = 0; i < count; i++) { Paint color = colors.nextColor(); lasr.setSeriesPaint(i, color); lasr.setSeriesFillPaint(i, color); lasr.setSeriesShape(i, circle); } } return new ChartPanel(chart); }
From source file:edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo1.java
/** * Creates a sample chart.//from w w w . ja v a 2 s .c o m * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... 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 ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setUpperMargin(0.0); domainAxis.setLowerMargin(0.0); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph.java
/** * Creates a Cppcheck trend graph//ww w . j ava 2 s. c o m * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); applyColorPalette(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1a.java
/** * Creates a sample chart./*from ww w.jav a 2 s . c o m*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... 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); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:sipl.recursos.Graficar.java
public void Multas(int[] values, int[] fecha, int n, String direccion, String tiempo, String titulo) { try {/*from ww w .j ava2s . c o m*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int j = 0; j < n; j++) { dataset.addValue(values[j], "Cantidad de Multas", "" + fecha[j]); } JFreeChart chart = ChartFactory.createLineChart(titulo, tiempo, "Cantidad", dataset, PlotOrientation.VERTICAL, true, true, true); try { ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 700, 500); } catch (IOException e) { System.out.println("Error al abrir el archivo"); } } catch (Exception e) { System.out.println(e); } }