List of usage examples for org.jfree.chart ChartFactory createLineChart3D
public static JFreeChart createLineChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:com.vectorprint.report.jfree.ChartBuilder.java
private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException { switch (type) { case AREA:/*from w w w .j av a 2s . c o m*/ chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case LINE: if (chart == null) { chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case LINE3D: if (chart == null) { chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR: if (chart == null) { chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR3D: if (chart == null) { chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof CategoryDataset) { CategoryDataset cd = (CategoryDataset) data; chart.getCategoryPlot().setDataset(cd); } else { throw new VectorPrintException("you should use CategoryDataset for this chart"); } break; case PIE: chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls); case PIE3D: if (chart == null) { chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls); } if (data instanceof PieDataset) { PieDataset pd = (PieDataset) data; PiePlot pp = (PiePlot) chart.getPlot(); pp.setDataset(pd); } else { throw new VectorPrintException("you should use PieDataset for this chart"); } break; case XYLINE: chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case XYAREA: if (chart == null) { chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof XYDataset) { XYDataset xy = (XYDataset) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use XYDataset for this chart"); } break; case TIME: chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips, urls); if (data instanceof TimeSeriesCollection) { TimeSeriesCollection xy = (TimeSeriesCollection) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use TimeSeriesCollection for this chart"); } break; default: throw new VectorPrintException("unsupported chart"); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); }
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
/** * Create JFreeChart graph using the supplied parameters. * * @param chartType One of the many chart types. * @param conf Chart configuration// w w w . j a v a 2 s . c o m * @param is Inputstream containing chart data * @return Initialized chart or NULL in case of issues. * @throws IOException Thrown when a problem is reported while parsing XML data. */ public static JFreeChart createJFreeChart(String chartType, Configuration conf, InputStream is) throws XPathException { logger.debug("Generating " + chartType); // Currently two dataset types supported CategoryDataset categoryDataset = null; PieDataset pieDataset = null; try { if ("PieChart".equals(chartType) || "PieChart3D".equals(chartType) || "RingChart".equals(chartType)) { logger.debug("Reading XML PieDataset"); pieDataset = DatasetReader.readPieDatasetFromXML(is); } else { logger.debug("Reading XML CategoryDataset"); categoryDataset = DatasetReader.readCategoryDatasetFromXML(is); } } catch (IOException ex) { throw new XPathException(ex.getMessage()); } finally { try { is.close(); } catch (IOException ex) { // } } // Return chart JFreeChart chart = null; // Big chart type switch if ("AreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("MultiplePieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("MultiplePieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart3D(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart3D(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("RingChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createRingChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("SpiderWebChart".equalsIgnoreCase(chartType)) { SpiderWebPlot plot = new SpiderWebPlot(categoryDataset); if (conf.isGenerateTooltips()) { plot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } chart = new JFreeChart(conf.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); if (conf.isGenerateLegend()) { LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); } else { TextTitle subTitle = new TextTitle(" "); subTitle.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(subTitle); } setCategoryChartParameters(chart, conf); } else if ("StackedAreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart(conf.getTitle(), conf.getDomainAxisLabel(), conf.getRangeAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("WaterfallChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createWaterfallChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else { logger.error("Illegal chartype. Choose one of " + "AreaChart BarChart BarChart3D LineChart LineChart3D " + "MultiplePieChart MultiplePieChart3D PieChart PieChart3D " + "RingChart SpiderWebChart StackedAreaChart StackedBarChart " + "StackedBarChart3D WaterfallChart"); } setCommonParameters(chart, conf); return chart; }
From source file:org.inbio.ait.web.controller.StatisticalController.java
/** * Gets the chart parameters, build the chart based on those parameters. * Then, the chart is passed as atribute trhow the session to another * view and finally the chart is shown to the user. * @throws java.lang.Exception/* w w w . jav a2 s. c o m*/ */ @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { //Getting query parameters ChartParameters parameters = (ChartParameters) command; //Arrays that contains the parameters data String[] xArray, yArray, xToShow, yToShow; //Validate if the user don't specify the x and y criteria if (parameters.getXdata().equals("") || parameters.getYdata().equals("")) { xArray = new String[0]; yArray = new String[0]; xToShow = new String[0]; yToShow = new String[0]; } else { xArray = parameters.getXdata().split("\\|"); yArray = parameters.getYdata().split("\\|"); xToShow = parameters.getXdatatoshow().split("\\|"); yToShow = parameters.getYdatatoshow().split("\\|"); } //Create the data set (value,row,colum) = (value,y,x) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //Getting x and y axis int values int x = 0, y = 0; try { x = Integer.parseInt(parameters.getXaxis()); y = Integer.parseInt(parameters.getYaxis()); } catch (Exception e) { } //Getting chart data from data base for (int i = 0; i < xArray.length; i++) { for (int j = 0; j < yArray.length; j++) { Long result = getQueryManager().countByCriteria(xArray[i], yArray[j], x, y); dataset.addValue(result, yToShow[j], xToShow[i]); //(value,y,x) } } //Create the chart JFreeChart chart; if (parameters.getType().equals(ChartType.BAR_CHART.getType())) { chart = ChartFactory.createBarChart3D(parameters.getTitle(), //title parameters.getXtitle(), // x axis label parameters.getYtitle(), // y axis label dataset, //dataset PlotOrientation.VERTICAL, true, // include legend true, // tooltips false); // urls } else { chart = ChartFactory.createLineChart3D(parameters.getTitle(), //title parameters.getXtitle(), // x axis label parameters.getYtitle(), // y axis label dataset, //dataset PlotOrientation.VERTICAL, true, // include legend true, // tooltips false); // urls } //Customize the chart chart.setBackgroundPaint(Color.WHITE); //Store te chart in the session. request.getSession(true).setAttribute("chart", chart); //Show the resultant chart boolean chartDisplay = true; ModelAndView mv = new ModelAndView(getSuccessView()); //Chart mv.addObject("chartDisplay", chartDisplay); //ChartParameters atributes mv.addObject("xdata", parameters.getXdata()); mv.addObject("ydata", parameters.getYdata()); mv.addObject("xaxis", parameters.getXaxis()); mv.addObject("yaxis", parameters.getYaxis()); mv.addObject("xdatatoshow", parameters.getXdatatoshow()); mv.addObject("ydatatoshow", parameters.getYdatatoshow()); mv.addObject("isgeo", parameters.getIsgeo()); mv.addObject("ldata", parameters.getLdata()); mv.addObject("ldatatoshow", parameters.getLdatatoshow()); return mv; }
From source file:org.adempiere.apps.graph.GraphBuilder.java
private JFreeChart createLineChart() { // create the chart... JFreeChart chart = ChartFactory.createLineChart3D(m_goal.getMeasure().getName(), // chart title m_X_AxisLabel, // domain axis label m_Y_AxisLabel, // range axis label linearDataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? true // URLs? );/*from w ww. j av a 2s. c o m*/ setupCategoryChart(chart); return chart; }
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 . c om*/ 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:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java
/** * //from w w w . j ava2 s .c o m * @param pieDataset * @return */ @SuppressWarnings("deprecation") private JFreeChart createJFreeBarChart(CategoryDataset barDataset) { if (this.model.isThreeDimensional() && this.model.isLineChart()) { return ChartFactory.createLineChart3D(this.model.getChartName(), "Category", "Value", barDataset, PlotOrientation.VERTICAL, true, true, false); } else if (this.model.isThreeDimensional() && !this.model.isLineChart()) { return ChartFactory.createBarChart3D(this.model.getChartName(), "Category", "Value", barDataset, PlotOrientation.VERTICAL, true, true, false); } else if (this.model.isLineChart()) { JFreeChart chart = ChartFactory.createLineChart(this.model.getChartName(), "Category", "Value", barDataset, PlotOrientation.VERTICAL, true, true, false); LineAndShapeRenderer renderer = (LineAndShapeRenderer) ((CategoryPlot) chart.getPlot()).getRenderer(); renderer.setShapesVisible(true); renderer.setShapesFilled(true); return chart; } return ChartFactory.createBarChart(this.model.getChartName(), "Category", "Value", barDataset, PlotOrientation.VERTICAL, true, true, false); }
From source file:edu.uara.wrappers.customcharts.CustomLineChart.java
/** * Generate 3D line chart with category dataset * @param dataset: CategoryDataset/*from w ww . ja va 2 s . co m*/ */ @Override public void generate3DLineChart(CategoryDataset dataset) { ds = dataset;//store dataset reference to do update try { if (dataset == null) throw new Exception("No dataset provided"); chart = ChartFactory.createLineChart3D(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 } }
From source file:org.deegree.graphics.charts.ChartsBuilder.java
/** * Creates a Line chart//from w ww.j a va2 s . co m * * @param title * @param keyedValues * key is the category name, value is a series tupels as follows for instance key1 = (arg1,4);(arg2,6) * key2 = (arg1,8); (arg2,11) * @param width * of the output image * @param height * height of the output image * @param is3D * is a 3D Chart * @param legend * for the output chart * @param tooltips * for the output de.latlon.charts * @param orientation * Horiyontal or vertical chart * @param imageType * of the output image * @param horizontalAxisName * Name of the Horizontal Axis * @param verticalAxisName * Name of the vertical Axis * @param chartConfigs * to configure the output chart, or null to use the default ChartConfig * @return BufferedImage representing the generated chart * @throws IncorrectFormatException */ public BufferedImage createLineChart(String title, QueuedMap<String, String> keyedValues, int width, int height, boolean is3D, boolean legend, boolean tooltips, int orientation, String imageType, String horizontalAxisName, String verticalAxisName, ChartConfig chartConfigs) throws IncorrectFormatException { CategoryDataset dataset = convertMapToCategoryDataSet(keyedValues); JFreeChart chart = null; if (is3D) { chart = ChartFactory.createLineChart3D(title, horizontalAxisName, verticalAxisName, dataset, translateToPlotOrientation(orientation), legend, tooltips, false); } else { chart = ChartFactory.createLineChart(title, horizontalAxisName, verticalAxisName, dataset, translateToPlotOrientation(orientation), legend, tooltips, false); } if (chartConfigs == null) { chartConfigs = this.chartConfigs; } return createBufferedImage(configChart(chart, chartConfigs), width, height, imageType); }
From source file:library.ChartGUI.java
private void btLine1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLine1ActionPerformed try {/*from w w w .jav a2s . co m*/ // TODO add your handling code here: JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql0); JFreeChart chart = ChartFactory.createLineChart3D("Sum Brought Books", "Month", "Count", dataset, PlotOrientation.VERTICAL, false, true, true); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame frame = new ChartFrame("Sum Brought Books Chart", chart); frame.setVisible(true); frame.setSize(1250, 700); frame.setResizable(false); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex); } }
From source file:library.ChartGUI.java
private void btLine2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLine2ActionPerformed // TODO add your handling code here: try {/*from w w w. j a v a 2 s .c o m*/ // TODO add your handling code here: JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql1); JFreeChart chart = ChartFactory.createLineChart3D("Sum New Readers", "Month", "Count", dataset, PlotOrientation.VERTICAL, false, true, true); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame frame = new ChartFrame("Sum New Readers Chart", chart); frame.setVisible(true); frame.setSize(1250, 700); frame.setResizable(false); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex); } }