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:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, Dataset data) throws ChartValidationException { // first check the dynamically registered chart types CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType); if (factory != null) { // custom factory found, use it return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data); }/*from ww w.j a v a 2 s. c om*/ switch (getChartTypeConstant(chartType)) { case XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, true, true); case PIE: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true); case AREA_XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case SCATTER: check(data, XYDataset.class, chartType); return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case HORIZONTAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case LINE: check(data, CategoryDataset.class, chartType); return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case STACKED_VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case TIME_SERIES: check(data, XYDataset.class, chartType); return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false, false); case CANDLE_STICK: check(data, OHLCDataset.class, chartType); return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case HIGH_LOW: check(data, OHLCDataset.class, chartType); return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case GANTT: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data, true, false, false); case WIND: check(data, WindDataset.class, chartType); return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false, false); //case SIGNAL : // check(data, SignalsDataset.class, chartType); // return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true); case VERRTICAL_XY_BAR: check(data, IntervalXYDataset.class, chartType); return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false); case PIE_3D: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false); case METER: check(data, ValueDataset.class, chartType); MeterPlot plot = new MeterPlot((ValueDataset) data); JFreeChart chart = new JFreeChart(title, plot); return chart; case STACKED_AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case BUBBLE: check(data, XYZDataset.class, chartType); return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data, PlotOrientation.VERTICAL, true, false, false); case AUSTER_CICLOS: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data); default: throw new UnsupportedChartTypeException(chartType + " is not supported."); } }
From source file:sipl.recursos.Graficar.java
public void MultasY(int[][] values, int n, String direccion, String tiempo, String titulo) { try {//from w ww .j av a 2 s . c o m DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int j = 0; j < n; j++) { dataset.addValue(values[j][1], "Cantidad de Multas", "" + values[j][0]); } JFreeChart chart = ChartFactory.createLineChart(titulo, tiempo, "Cantidad", dataset, PlotOrientation.VERTICAL, true, true, true); try { ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 500, 500); } catch (IOException e) { System.out.println("Error al abrir el archivo"); } } catch (Exception e) { System.out.println(e); } }
From source file:com.sami.chart.util.LineChartDemo1.java
/** * Creates a sample chart.//from w ww . j a v a2s . c om * * @param dataset a dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title "Type", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // legend.setShapeScaleX(1.5); // legend.setShapeScaleY(1.5); //legend.setDisplaySeriesLines(true); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setSeriesStroke(0, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(1, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:virgil.meanback.HistoryInfo.java
public void printChart(Stock stock, List<String[]> list, int days) throws Exception { //?/* w w w. j a v a2 s . c om*/ StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); // standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20)); // standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12)); //? standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18)); //? ChartFactory.setChartTheme(standardChartTheme); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = list.size() - 1; i >= 0; i--) { String[] s = (String[]) list.get(i); dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]); dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]); float sub = Float.parseFloat(s[2]); float error = Float.parseFloat(s[3]); if (sub > error * 2) { dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]); } } //?????Legend //???? //??URL JFreeChart chart = ChartFactory.createLineChart( stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet, PlotOrientation.VERTICAL, true, true, false); CategoryPlot cp = chart.getCategoryPlot(); cp.setBackgroundPaint(ChartColor.WHITE); // CategoryAxis categoryAxis = cp.getDomainAxis(); // Lable 90 Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); categoryAxis.setTickLabelFont(labelFont);//X?? ValueAxis yAxis = cp.getRangeAxis(); yAxis.setAutoRange(true); double[] d = getAxiasThresold(stock, list); yAxis.setLowerBound(d[0] - 0.15); yAxis.setUpperBound(d[1] + 0.15); LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer(); lasp.setBaseFillPaint(ChartColor.RED); lasp.setDrawOutlines(true); lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//? DecimalFormat decimalformat1 = new DecimalFormat("##.##");//??? renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); //???? renderer.setItemLabelsVisible(true);// renderer.setBaseItemLabelsVisible(true);// //????? renderer.setShapesFilled(Boolean.TRUE);//?? renderer.setShapesVisible(true);//? ChartFrame chartFrame = new ChartFrame("??", chart, true); //chart?JavaChartFramejavaJframe???? chartFrame.pack(); //?? chartFrame.setVisible(true);//??? }
From source file:de.dekarlab.moneybuilder.view.AnalyticsView.java
/** * Create pie chart./*w w w .jav a 2s . com*/ * * @param dataset * @param title * @return */ protected JFreeChart createLineChart(final CategoryDataset dataset, final String title) { final JFreeChart chart = ChartFactory.createLineChart("", // chart title App.getGuiProp("report.period.lbl"), // domain axis label App.getGuiProp("report.value.lbl"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage(App.getGuiProp("report.nodata.msg")); plot.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.white); ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(false); ((CategoryAxis) plot.getDomainAxis()).setMaximumCategoryLabelLines(10); ((CategoryAxis) plot.getDomainAxis()).setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); plot.setRangeZeroBaselinePaint(Color.black); plot.setRangeZeroBaselineVisible(true); int color = 0; CategoryItemRenderer renderer = plot.getRenderer(); for (int ser = 0; ser < dataset.getColumnCount(); ser++) { renderer.setSeriesPaint(ser, COLORS[color]); renderer.setSeriesStroke(ser, new BasicStroke(4)); StandardCategoryItemLabelGenerator gen = new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance(Locale.GERMAN)) { private static final long serialVersionUID = 1L; public String generateLabel(CategoryDataset dataset, int series, int item) { if (item % 3 == 0) { return super.generateLabelString(dataset, series, item); } else { return null; } } }; renderer.setSeriesItemLabelGenerator(ser, gen); renderer.setSeriesItemLabelsVisible(ser, true); color++; if (COLORS.length == color) { color = 0; } } return chart; }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * This method generates an image of a chart of the evolution of the total * amount of money a book selection for a year in a monthly bases * /* w w w.j a va 2 s. co m*/ * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getBalanceChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.<Integer>absent()); Multimap<Integer, Annotation> yearToAnnotationMultimap = getYearToAnnotationMultimapFromAnnotations( anotations); CategoryDataset categoryModel = ChartDataModel.getBalance(monthlyReportYear, yearToAnnotationMultimap, bookSelection, true, Optional.<String>absent()); JFreeChart jfchart = ChartFactory.createLineChart("Saldo Total", "Fecha", "Euros", categoryModel, PlotOrientation.VERTICAL, true, true, false); PrepareChart.prepareBalanceChart(jfchart); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.Line2dChart.java
/** * * @param title//w w w . j av a 2 s.com * @param subTitle * @param fileName * @param domainAxis * @param rangeAxis * @param width * @param height */ private void buildFinalChart(String title, String subTitle, String fileName, String domainAxis, String rangeAxis, int width, int height) { CategoryDataset dataset = this.createDataset(); JFreeChart chart = ChartFactory.createLineChart(title, domainAxis, // domain // axis // label rangeAxis, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.addSubtitle(new TextTitle(subTitle)); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot c = chart.getCategoryPlot(); c.setRenderer(renderer); c.setRangeGridlinesVisible(true); try { ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(fileName + ".png"), chart, width, height); Utilities.saveChartAsSVG(chart, new Rectangle(width, height), XMLHelper.createFileWithDirs(fileName + ".svg")); } catch (java.io.IOException e) { System.err.println("Error writing image to file"); e.printStackTrace(); } }
From source file:forms.frDados.java
/** * Inicializa o grfico de velocidade.//from ww w. j a v a 2s. c o m */ private void initSatVelox() { dadosGraficoVelox.clear(); veloxPlot = ChartFactory.createLineChart("Velocidade", "Hora", "Velocidade KM/h", dadosGraficoVelox, PlotOrientation.VERTICAL, false, true, false); veloxPlot.getTitle().setFont(Font.decode("arial-16")); veloxPlot.getTitle().setPadding(5, 20, 5, 20); veloxPlot.setPadding(new RectangleInsets(10, 10, 0, 10)); ChartPanel cp = new ChartPanel(veloxPlot); cp.setBorder(LineBorder.createGrayLineBorder()); LineAndShapeRenderer br = (LineAndShapeRenderer) veloxPlot.getCategoryPlot().getRenderer(); br.setBaseItemLabelsVisible(true); br.setSeriesItemLabelFont(0, Font.decode("arial-12")); br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); br.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); veloxPlot.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //veloxPlot.getCategoryPlot().getRangeAxis().setRange(new Range(0,100), true,true); pnlChartSpeed.setLayout(new BorderLayout()); pnlChartSpeed.add(cp, BorderLayout.CENTER); }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) { JFreeChart chart = null;//from w w w . j a v a 2 s . co m PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation()); CategoryDataset dataset = (CategoryDataset) chartData.getDatasource(); String type = chartData.getType(); String xAxis = chartData.getXlabel(); String yAxis = chartData.getYlabel(); boolean is3d = chartData.isChart3d(); boolean legend = chartData.isLegend(); if (type.equalsIgnoreCase("bar")) { if (is3d == true) { chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else { chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } setBarOutline(chart, chartData); } else if (type.equalsIgnoreCase("stackedbar")) { if (is3d == true) { chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else { chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } setBarOutline(chart, chartData); } else if (type.equalsIgnoreCase("line")) { if (is3d == true) chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); else chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("area")) { chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("stackedarea")) { chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("waterfall")) { chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("gantt")) { chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true, false); } CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot(); plot.setDomainGridlinesVisible(chartData.isDomainGridLines()); plot.setRangeGridlinesVisible(chartData.isRangeGridLines()); if (chartData.getGenerateMap() != null) plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator("")); int seriesCount = plot.getDataset().getColumnCount(); if (chartData.getLineStokeWidth() > 0) { for (int index = 0; index <= seriesCount; index++) plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth())); } setCategorySeriesColors(chart, chartData); setCategoryExtensions(chart, chartData); return chart; }
From source file:edu.uara.wrappers.customcharts.CustomLineChart.java
/** * Generate regular line chart with category dataset * @param dataset: CategoryDataset/*from w w w . j a v a 2 s . c o m*/ */ @Override public void generateLineChart(CategoryDataset dataset) { ds = dataset;//store dataset reference to do update try { if (dataset == null) throw new Exception("No dataset provided"); chart = ChartFactory.createLineChart(title, // chart title domainAxisLabel, // domain axis label rangeAxisLabel, // range axis label dataset, // data orientation, // orientation legend, // include legend false, // no tooltips false // URLs? ); this.currentDatasetType = DatasetTypes.CategoryDataset; } catch (Exception ex) { //handle exception } }