List of usage examples for org.jfree.chart ChartFactory createAreaChart
public static JFreeChart createAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:org.javarebel.chart.generator.AreaChartGenerator.java
@Override public JFreeChart generateChart(ChartData data) { if (data instanceof AreaChartData) { CategoryDataset dataset = data.createDataset(); PlotOrientation pltOrd = PlotOrientation.VERTICAL; if ("HORIZONTAL".compareToIgnoreCase(data.getOrientation()) == 0) pltOrd = PlotOrientation.HORIZONTAL; final JFreeChart chart = ChartFactory.createAreaChart(data.getTitle(), data.getXaxisLabel(), data.getYaxisLabel(), dataset, pltOrd, true, true, false); super.configureChart(chart, data); return chart; } else/*ww w . ja v a 2 s .c o m*/ throw new IllegalArgumentException(); }
From source file:com.liferay.samplestrutsliferay.struts.action.ViewChartAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {// w w w . ja va 2 s . c o m if (_log.isInfoEnabled()) { _log.info("execute"); } String attrName = "chart_name"; // Application scoped session attributes can be fetched from the // servlet directly. Portlet scoped session attributes can be // fetched from Sun's PortletSessionUtil. HttpSession session = request.getSession(); String chartName = (String) session.getAttribute(attrName); //(String)_getAttribute(request, attrName); // Chart String chartType = request.getParameter("chart_type"); CategoryDataset dataset = _getDataset(); String xName = "Soda"; String yName = "Votes"; JFreeChart chart = null; if (chartType.equals("area")) { chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("horizontal_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL, true, false, false); } else if (chartType.equals("line")) { chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("vertical_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else { PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0); chart = ChartFactory.createPieChart(chartName, pieData, true, false, false); } response.setContentType("image/jpeg"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 400, 400); return mapping.findForward("/common/null.jsp"); } catch (Exception e) { request.setAttribute(PageContext.EXCEPTION, e); return mapping.findForward("/common/error.jsp"); } }
From source file:com.liferay.samplestruts.struts.action.ViewChartAction.java
@Override public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w w w .j ava 2 s . c om*/ if (_log.isInfoEnabled()) { _log.info("execute"); } String attrName = "chart_name"; // Application scoped session attributes can be fetched from the // servlet directly. Portlet scoped session attributes can be // fetched from Sun's PortletSessionUtil. HttpSession session = request.getSession(); String chartName = (String) session.getAttribute(attrName); //(String)_getAttribute(request, attrName); // Chart String chartType = request.getParameter("chart_type"); CategoryDataset dataset = _getDataset(); String xName = "Soda"; String yName = "Votes"; JFreeChart chart = null; if (chartType.equals("area")) { chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("horizontal_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL, true, false, false); } else if (chartType.equals("line")) { chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("vertical_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else { PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0); chart = ChartFactory.createPieChart(chartName, pieData, true, false, false); } response.setContentType("image/jpeg"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 400, 400); return actionMapping.findForward("/common/null.jsp"); } catch (Exception e) { request.setAttribute(PageContext.EXCEPTION, e); return actionMapping.findForward("/common/error.jsp"); } }
From source file:com.liferay.polls.web.internal.portlet.action.ViewChartMVCResourceCommand.java
@Override protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { try {/* www . jav a2 s . c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); long questionId = ParamUtil.getLong(resourceRequest, "questionId"); String chartType = ParamUtil.getString(resourceRequest, "chartType", "pie"); String chartName = themeDisplay.translate("vote-results"); String xName = themeDisplay.translate("choice"); String yName = themeDisplay.translate("votes"); CategoryDataset categoryDataset = PollsUtil.getVotesDataset(questionId); JFreeChart jFreeChat = null; if (chartType.equals("area")) { jFreeChat = ChartFactory.createAreaChart(chartName, xName, yName, categoryDataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("horizontal_bar")) { jFreeChat = ChartFactory.createBarChart(chartName, xName, yName, categoryDataset, PlotOrientation.HORIZONTAL, true, false, false); } else if (chartType.equals("line")) { jFreeChat = ChartFactory.createLineChart(chartName, xName, yName, categoryDataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("vertical_bar")) { jFreeChat = ChartFactory.createBarChart(chartName, xName, yName, categoryDataset, PlotOrientation.VERTICAL, true, false, false); } else { PieDataset pieDataset = DatasetUtilities.createPieDatasetForRow(categoryDataset, 0); jFreeChat = ChartFactory.createPieChart(chartName, pieDataset, true, false, false); } resourceResponse.setContentType(ContentTypes.IMAGE_JPEG); OutputStream outputStream = resourceResponse.getPortletOutputStream(); ChartUtilities.writeChartAsJPEG(outputStream, jFreeChat, 400, 400); } catch (Exception e) { PortletSession portletSession = resourceRequest.getPortletSession(); PortletContext portletContext = portletSession.getPortletContext(); PortletRequestDispatcher requestDispatcher = portletContext.getRequestDispatcher("/polls/error.jsp"); requestDispatcher.forward(resourceRequest, resourceResponse); } }
From source file:biz.ixnay.pivot.charts.skin.jfree.AreaChartViewSkin.java
@Override protected JFreeChart createChart() { AreaChartView chartView = (AreaChartView) getComponent(); String title = chartView.getTitle(); String horizontalAxisLabel = chartView.getHorizontalAxisLabel(); String verticalAxisLabel = chartView.getVerticalAxisLabel(); boolean showLegend = chartView.getShowLegend(); String seriesNameKey = chartView.getSeriesNameKey(); List<?> chartData = chartView.getChartData(); JFreeChart chart;//from ww w . j a va 2s . co m ChartView.CategorySequence categories = chartView.getCategories(); if (categories.getLength() > 0) { CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData); chart = ChartFactory.createAreaChart(title, horizontalAxisLabel, verticalAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions .createUpRotationLabelPositions(categoryLabelRotation); domainAxis.setCategoryLabelPositions(categoryLabelPositions); } else { chart = ChartFactory.createXYAreaChart(title, horizontalAxisLabel, verticalAxisLabel, new XYSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend, false, false); } return chart; }
From source file:com.swordlord.gozer.components.wicket.graph.GWAreaChartPanel.java
public GWAreaChartPanel(String id, IModel<?> model, GAreaChart child) { super(id, model); DataBindingMember dbMemberKey = child.getDataBindingMemberRowKey(); DataBindingMember dbMemberValue = child.getDataBindingMemberValue(); DataBindingManager dbManager = child.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> keyRows = dbManager.getRows(dbMemberKey); List<DataRowBase> valueRows = dbManager.getRows(dbMemberValue); String[] codes = new String[keyRows.size()]; int[] results = new int[keyRows.size()]; int i = 0;/*from w ww .j a va 2 s .co m*/ for (DataRowBase row : keyRows) { codes[i] = row.getPropertyAsString(dbMemberKey.getDataBindingFieldName()); i++; } i = 0; for (DataRowBase row : valueRows) { results[i] = row.getPropertyAsInt(dbMemberValue.getDataBindingFieldName()); i++; } for (Integer j = 0; j < keyRows.size(); j++) { dcd.setValue(results[j], codes[j], codes[j]); } JFreeChart chart = ChartFactory.createAreaChart(child.getTitle(), child.getCategoryAxisLabel(), child.getValueAxisLabel(), dcd, child.getOrientation(), child.getLegend(), false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDrawingSupplier(child.getDrawingSupplier()); add(new ChartImage("chart", chart, child.getWidth(200), child.getHeight(200))); }
From source file:com.swordlord.gozer.components.fop.graph.GFopAreaChart.java
public GFopAreaChart(IGozerFrameExtension gfe, GAreaChart chart) { super(gfe);//from ww w .ja va 2 s. com DataBindingMember dbMemberKey = chart.getDataBindingMemberRowKey(); DataBindingMember dbMemberValue = chart.getDataBindingMemberValue(); DataBindingManager dbManager = chart.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> keyRows = dbManager.getRows(dbMemberKey); List<DataRowBase> valueRows = dbManager.getRows(dbMemberValue); String[] codes = new String[keyRows.size()]; int[] results = new int[keyRows.size()]; int i = 0; for (DataRowBase row : keyRows) { codes[i] = row.getPropertyAsString(dbMemberKey.getDataBindingFieldName()); i++; } i = 0; for (DataRowBase row : valueRows) { results[i] = row.getPropertyAsInt(dbMemberValue.getDataBindingFieldName()); i++; } for (Integer j = 0; j < keyRows.size(); j++) { dcd.setValue(results[j], codes[j], codes[j]); } JFreeChart fc = ChartFactory.createAreaChart(chart.getTitle(), chart.getCategoryAxisLabel(), chart.getValueAxisLabel(), dcd, chart.getOrientation(), chart.getLegend(), false, false); fc.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) fc.getPlot(); plot.setDrawingSupplier(chart.getDrawingSupplier()); _image = new ChartImage("chart", fc, chart.getWidth(400), chart.getHeight(400)); }
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/*from w w w. jav a 2s . c om*/ * @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.pentaho.chart.plugin.jfreechart.chart.area.JFreeAreaChartGenerator.java
/** * Creates the JFree chart based on the chart document, data provided and * type of chart expected.// w ww .j a v a 2 s . c om * </p> * @param chartDocContext Chart documument context for the current chart. * @param data Data for the current chart. * @param chartType Area chart type (default, stacked, xy) * @return Returns the JFree chart object (created by the method) */ public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data, final CSSConstant chartType) { final ChartDocument chartDocument = chartDocContext.getChartDocument(); final String title = getTitle(chartDocument); final String valueCategoryLabel = getValueCategoryLabel(chartDocument); final String valueAxisLabel = getValueAxisLabel(chartDocument); final PlotOrientation orientation = getPlotOrientation(chartDocument); final boolean legend = getShowLegend(chartDocument); final boolean toolTips = getShowToolTips(chartDocument); final DefaultCategoryDataset categoryDataset = datasetGeneratorFactory .createDefaultCategoryDataset(chartDocContext, data); if (categoryDataset == null) { logger.error(Messages.getErrorString("JFreeChartFactoryEngine.ERROR_0001_DATASET_IS_NULL")); //$NON-NLS-1$ return null; } JFreeChart chart = null; if (ChartAreaStyle.STACKED.equals(chartType)) { chart = ChartFactory.createStackedAreaChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset, orientation, legend, toolTips, false); } else if (ChartAreaStyle.XY.equals(chartType)) { } else { chart = ChartFactory.createAreaChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset, orientation, legend, toolTips, false); } if (chart != null) { final ChartElement[] seriesElements = chartDocument.getRootElement() .findChildrenByName(ChartElement.TAG_NAME_SERIES); final CategoryPlot categoryPlot = chart.getCategoryPlot(); if (seriesElements != null && categoryPlot != null) { setSeriesAttributes(seriesElements, data, categoryPlot); } } return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
protected JFreeChart createLegend(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart( // JFreeChart chart = ChartFactory.createLineChart( chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );// w w w .j a v a 2 s. c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); return chart; }