List of usage examples for org.jfree.chart ChartFactory createStackedBarChart
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBar.java
/** * Inherited by IChart.//from w w w. ja v a 2 s.com * * @param chartTitle the chart title * @param dataset the dataset * * @return the j free chart */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); logger.debug("Taken Dataset"); logger.debug("Get plot orientaton"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; } logger.debug("Call Chart Creation"); JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // the plot orientation false, // legend true, // tooltips false // urls ); logger.debug("Chart Created"); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(color); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); logger.debug("set renderer"); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); if (percentageValue) renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%"))); else if (makePercentage) renderer.setRenderAsPercentages(true); /* else renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); */ renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } boolean document_composition = false; if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION)) document_composition = true; logger.debug("Calling Url Generation"); MyCategoryUrlGenerator mycatUrl = null; if (rootUrl != null) { logger.debug("Set MycatUrl"); mycatUrl = new MyCategoryUrlGenerator(rootUrl); mycatUrl.setDocument_composition(document_composition); mycatUrl.setCategoryUrlLabel(categoryUrlName); mycatUrl.setSerieUrlLabel(serieUrlname); } if (mycatUrl != null) renderer.setItemURLGenerator(mycatUrl); logger.debug("Text Title"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } logger.debug("Style Labels"); Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(color); logger.debug("Axis creation"); // set the range axis to display integers only... NumberFormat nf = NumberFormat.getNumberInstance(locale); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (makePercentage) rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); else rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setNumberFormatOverride(nf); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } renderer.setDrawBarOutline(false); logger.debug("Set series color"); int seriesN = dataset.getRowCount(); if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); // if serie has been rinominated I must search with the new name! String nameToSearchWith = (seriesLabelsMap != null && seriesLabelsMap.containsKey(serieName)) ? seriesLabelsMap.get(serieName).toString() : serieName; Color color = (Color) colorMap.get(nameToSearchWith); if (color != null) { renderer.setSeriesPaint(i, color); renderer.setSeriesItemLabelFont(i, new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); } } } logger.debug("If cumulative set series paint " + cumulative); if (cumulative) { int row = dataset.getRowIndex("CUMULATIVE"); if (row != -1) { if (color != null) renderer.setSeriesPaint(row, color); else renderer.setSeriesPaint(row, Color.WHITE); } } MyStandardCategoryItemLabelGenerator generator = null; logger.debug("Are there addition labels " + additionalLabels); logger.debug("Are there value labels " + showValueLabels); if (showValueLabels) { renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); if (valueLabelsPosition.equalsIgnoreCase("inside")) { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); } else { renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); } } else if (additionalLabels) { generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance()); logger.debug("generator set"); double orient = (-Math.PI / 2.0); logger.debug("add labels style"); if (styleValueLabels.getOrientation() != null && styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) { orient = 0.0; } renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); logger.debug("add labels style set"); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //vertical labels renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); renderer.setBaseNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient)); logger.debug("end of add labels "); } logger.debug("domain axis"); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); //opacizzazione colori if (!cumulative) plot.setForegroundAlpha(0.6f); if (legend == true) drawLegend(chart); logger.debug("OUT"); return chart; }
From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java
private JFreeChart createChart(HashSet<ComputeBean> resources, ChartType chartType, LoadType loadType) { JFreeChart chart = null;// www . j a v a 2s.c o m Plot plot; AbstractDataset dataset; if (loadType.equals(LoadType.SUMMARY)) { dataset = ChartDataset.createDataset(resources, chartType); } else { dataset = ChartDataset.createDataset(resources, chartType, loadType); } if (chartType.equals(ChartType.SUMMARY)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); renderBarChart(chart); } else if (chartType.equals(ChartType.PIE)) { chart = ChartFactory.createPieChart(createTitle(loadType), // chart title (DefaultPieDataset) dataset, // data false, // include legend true, // tooltips? false // URLs? ); } else if (chartType.equals(ChartType.BAR)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); renderBarChart(chart); } else if (chartType.equals(ChartType.LAYERED)) { plot = new CategoryPlot((CategoryDataset) dataset, new CategoryAxis("Resources"), new NumberAxis(createTitle(loadType)), new LayeredBarRenderer()); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); renderLayeredBarChart(chart); } else if (chartType.equals(ChartType.STACKED)) { chart = ChartFactory.createStackedBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); renderStackedBarChart(chart); } else if (chartType.equals(ChartType.BAR)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } return chart; }
From source file:org.bhavaya.ui.view.ChartView.java
private JFreeChart createStackedHorizontalBarChart() { JFreeChart chart;// ww w . j a v a2 s . c om chart = ChartFactory.createStackedBarChart(getName(), getDomainName(), getRangeName(), tableModelDataSet, PlotOrientation.HORIZONTAL, true, true, false); NumberAxis rangeAxis = (NumberAxis) chart.getCategoryPlot().getRangeAxis(); rangeAxis.setAutoTickUnitSelection(true); rangeAxis.setVerticalTickLabels(true); rangeAxis.setTickMarksVisible(true); CategoryAxis domainAxis = (CategoryAxis) chart.getCategoryPlot().getDomainAxis(); return chart; }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Stacked Bar Chart. <br> * // ww w. ja va2 s .c om * @param event * @throws IOException */ public void onClick$button_CustomerChart_StackedBar(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), key + " " + amount, key + " " + amount); } String title = "Monthly amount for year 2009"; PlotOrientation po = PlotOrientation.VERTICAL; JFreeChart chart = ChartFactory.createStackedBarChart(title, "Month", "Amount", dataset, po, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Stacked Bar Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a stacked bar graph representing test counts for each product area. * * @param builds List of builds/*from w w w . j a va 2 s. co m*/ * @param suites List of test suites * @param areas List of product areas * * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAreaTestCountChart(Vector<CMnDbBuildData> builds, Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) { JFreeChart chart = null; // Collect the total times for each build, organized by area // This hashtable maps a build to the area/time information for that build Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>(); // Generate placeholders for each build so the chart maintains a // format consistent with the other charts that display build information if (builds != null) { Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); // Create the empty area list buildTotals.put(new Integer(build.getId()), new Hashtable<String, Integer>()); } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if ((suites != null) && (suites.size() > 0)) { // Collect build test numbers for each of the builds in the list Enumeration suiteList = suites.elements(); while (suiteList.hasMoreElements()) { // Process the test summary for the current build CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement(); Integer buildId = new Integer(suite.getParentId()); Integer testCount = new Integer(suite.getTestCount()); // Parse the build information so we can track the time by build Hashtable<String, Integer> areaCount = null; if (buildTotals.containsKey(buildId)) { areaCount = (Hashtable) buildTotals.get(buildId); } else { areaCount = new Hashtable<String, Integer>(); buildTotals.put(buildId, areaCount); } // Iterate through each product area to determine who owns this suite CMnDbFeatureOwnerData area = null; Iterator iter = areas.iterator(); while (iter.hasNext()) { CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next(); if (currentArea.hasFeature(suite.getGroupName())) { area = currentArea; } } // Add the elapsed time for the current suite to the area total Integer totalValue = null; String areaName = area.getDisplayName(); if (areaCount.containsKey(areaName)) { Integer oldTotal = (Integer) areaCount.get(areaName); totalValue = oldTotal + testCount; } else { totalValue = testCount; } areaCount.put(areaName, totalValue); } // while list has elements // Make sure every area is represented in the build totals Enumeration bt = buildTotals.keys(); while (bt.hasMoreElements()) { // Get the build ID for the current build Integer bid = (Integer) bt.nextElement(); // Get the list of area totals for the current build Hashtable<String, Integer> ac = (Hashtable<String, Integer>) buildTotals.get(bid); Iterator a = areas.iterator(); while (a.hasNext()) { // Add a value of zero if no total was found for the current area CMnDbFeatureOwnerData area = (CMnDbFeatureOwnerData) a.next(); if (!ac.containsKey(area.getDisplayName())) { ac.put(area.getDisplayName(), new Integer(0)); } } } // Populate the data set with the area times for each build Collections.sort(builds, new CMnBuildIdComparator()); Enumeration bList = builds.elements(); while (bList.hasMoreElements()) { CMnDbBuildData build = (CMnDbBuildData) bList.nextElement(); Integer buildId = new Integer(build.getId()); Hashtable areaCount = (Hashtable) buildTotals.get(buildId); Enumeration areaKeys = areaCount.keys(); while (areaKeys.hasMoreElements()) { String area = (String) areaKeys.nextElement(); Integer count = (Integer) areaCount.get(area); dataset.addValue(count, area, buildId); } } } // if list has elements // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls) chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Test Count", dataset, PlotOrientation.VERTICAL, true, true, false); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); chartFormatter.formatAreaChart(plot, dataset); return chart; }
From source file:ispd.gui.auxiliar.Graficos.java
public ChartPanel criarGraficoPorTarefa(List<Tarefa> tarefas, int idTarefa) { DefaultCategoryDataset dadosMflopProcessados = new DefaultCategoryDataset(); Tarefa job = null;//from w ww . jav a 2 s. c o m int i; Double mflopProcessadoTotal = 0.0; for (i = 0; i < tarefas.size(); i++) { if (tarefas.get(i).getIdentificador() == idTarefa) { job = tarefas.get(i); break; } } if (job != null) { if (job.getEstado() != Tarefa.CANCELADO) { for (i = 0; i < job.getHistoricoProcessamento().size(); i++) { mflopProcessadoTotal += job.getHistoricoProcessamento().get(i) .getMflopsProcessados(job.getTempoFinal().get(i) - job.getTempoInicial().get(i)); } dadosMflopProcessados.addValue(((job.getTamProcessamento() / mflopProcessadoTotal) * 100.0), "Usefull processing", "Task size :" + job.getTamProcessamento() + " MFlop" + ", total executed for task: " + mflopProcessadoTotal + " MFlop"); dadosMflopProcessados.addValue(((job.getMflopsDesperdicados()) / mflopProcessadoTotal) * 100.0, "Wasted processing", "Task size :" + job.getTamProcessamento() + " MFlop" + ", total executed for task: " + mflopProcessadoTotal + " MFlop"); JFreeChart jfc = ChartFactory.createStackedBarChart("Units usage for task " + idTarefa, //Titulo "", // Eixo X "% of total Units executed for the task", //Eixo Y dadosMflopProcessados, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, true, false); // exibir: legendas, tooltips, url ChartPanel graficoPorTarefa = new ChartPanel(jfc); graficoPorTarefa.setPreferredSize(new Dimension(600, 300)); return graficoPorTarefa; } else { return null; } } else { return null; } }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createBarChart(boolean horizontal, boolean stacked, boolean isCombo) throws QueryException { barDataset = new DefaultCategoryDataset(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); Object[] charts;//from ww w . j ava 2 s .c o m List<String> legends; Object[] lineCharts = null; String lineLegend = null; if (isCombo) { lineCharts = new Object[1]; if (chart.getYColumnsLegends().size() < chart.getYColumns().size()) { lineLegend = ""; } else { lineLegend = chart.getYColumnsLegends().get(chart.getYColumns().size() - 1); } charts = new Object[chart.getYColumns().size() - 1]; legends = chart.getYColumnsLegends().subList(0, chart.getYColumns().size() - 1); } else { charts = new Object[chart.getYColumns().size()]; legends = chart.getYColumnsLegends(); } boolean hasLegend = false; for (int i = 0; i < charts.length; i++) { String legend = ""; try { legend = replaceParameters(legends.get(i)); legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language)); } catch (IndexOutOfBoundsException ex) { // no legend set } // Important : must have default different legends used in barDataset.addValue if ((legend == null) || "".equals(legend.trim())) { legend = DEFAULT_LEGEND_PREFIX + String.valueOf(i + 1); } else { hasLegend = true; } charts[i] = legend; } if (isCombo) { String leg = ""; if (lineLegend != null) { leg = replaceParameters(lineLegend); } lineCharts[0] = leg; } byte style = chart.getType().getStyle(); JFreeChart jfreechart; String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); PlotOrientation plotOrientation = horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL; if (stacked) { jfreechart = ChartFactory.createStackedBarChart(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); } else { switch (style) { case ChartType.STYLE_BAR_PARALLELIPIPED: case ChartType.STYLE_BAR_CYLINDER: jfreechart = ChartFactory.createBarChart3D(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); break; default: jfreechart = ChartFactory.createBarChart(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); break; } } if (style == ChartType.STYLE_BAR_CYLINDER) { ((CategoryPlot) jfreechart.getPlot()).setRenderer(new CylinderRenderer()); } // hide legend if necessary if (!hasLegend) { jfreechart.removeLegend(); } // hide border jfreechart.setBorderVisible(false); // title setTitle(jfreechart); // chart colors & values shown on bars boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); CategoryPlot plot = (CategoryPlot) jfreechart.getPlot(); plot.setForegroundAlpha(transparency); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } for (int i = 0; i < charts.length; i++) { renderer.setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { renderer.setSeriesItemLabelsVisible(i, true); renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator("{2}", decimalformat, percentageFormat)); } } if (showValues) { // increase a little bit the range axis to view all item label values over bars plot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { plot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { plot.setDomainGridlinePaint(chart.getXGridColor()); } else { plot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { plot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { plot.setRangeGridlinePaint(chart.getYGridColor()); } else { plot.setRangeGridlinePaint(Color.BLACK); } } // chart background plot.setBackgroundPaint(chart.getBackground()); // labels color plot.getDomainAxis().setTickLabelPaint(chart.getXColor()); plot.getRangeAxis().setTickLabelPaint(chart.getYColor()); // legend color plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // axis color plot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor()); plot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { plot.getDomainAxis().setTickLabelsVisible(false); plot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { plot.getRangeAxis().setTickLabelsVisible(false); plot.getRangeAxis().setTickMarksVisible(false); } if (chart.getType().getStyle() == ChartType.STYLE_NORMAL) { // no shadow renderer.setShadowVisible(false); // no gradient renderer.setBarPainter(new StandardBarPainter()); } // label orientation CategoryAxis domainAxis = plot.getDomainAxis(); if (chart.getXorientation() == Chart.VERTICAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2)); } else if (chart.getXorientation() == Chart.DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8)); } // labels fonts domainAxis.setTickLabelFont(chart.getXLabelFont()); plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); createChart(plot.getRangeAxis(), charts); if (isCombo) { addLineChartOverBar(jfreechart, lineCharts, lineLegend); } return jfreechart; }
From source file:org.bhavaya.ui.view.ChartView.java
private JFreeChart createStackedVerticalBarChart() { JFreeChart chart;/*from w w w.ja v a2 s. c o m*/ if (isPlot3D()) { chart = ChartFactory.createStackedBarChart3D(getName(), getDomainName(), getRangeName(), tableModelDataSet, PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createStackedBarChart(getName(), getDomainName(), getRangeName(), tableModelDataSet, PlotOrientation.VERTICAL, true, true, false); } NumberAxis rangeAxis = (NumberAxis) chart.getCategoryPlot().getRangeAxis(); rangeAxis.setAutoTickUnitSelection(true); CategoryAxis domainAxis = (CategoryAxis) chart.getCategoryPlot().getDomainAxis(); domainAxis.setTickMarksVisible(true); return chart; }
From source file:ispd.gui.auxiliar.Graficos.java
public ChartPanel criarGraficoAproveitamento(List<Tarefa> tarefas) { DefaultCategoryDataset dadosMflopProcessados = new DefaultCategoryDataset(); double mflopDesperdicado = 0.0, tamanhoTotal = 0.0; int i, j;/*from w ww . j a va 2 s . c o m*/ for (i = 0; i < tarefas.size(); i++) { if (tarefas.get(i).getEstado() != Tarefa.CANCELADO) { tamanhoTotal += tarefas.get(i).getTamProcessamento(); } mflopDesperdicado += tarefas.get(i).getMflopsDesperdicados(); } dadosMflopProcessados.addValue((tamanhoTotal / (mflopDesperdicado + tamanhoTotal)) * 100.0, "Usefull Processing", "Units Usage"); dadosMflopProcessados.addValue((mflopDesperdicado / (mflopDesperdicado + tamanhoTotal)) * 100.0, "Wasted Processing", "Units Usage"); JFreeChart jfc = ChartFactory.createStackedBarChart("Processing efficiency", //TituloUsage# "", // Eixo X "% of total Units executed", //Eixo Y dadosMflopProcessados, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, true, false); // exibir: legendas, tooltips, url ChartPanel graficoAproveitamentoPorcentagem = new ChartPanel(jfc); graficoAproveitamentoPorcentagem.setPreferredSize(new Dimension(600, 300)); return graficoAproveitamentoPorcentagem; }
From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java
private JFreeChart createChart(ComputeBean hpc, ChartType chartType, LoadType loadType) { JFreeChart chart = null;// w w w . j ava 2s . c om Plot plot; if (chartType.equals(ChartType.SUMMARY)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) ChartDataset.createDataset(hpc, chartType), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); renderBarChart(chart); } else if (chartType.equals(ChartType.PIE)) { chart = ChartFactory.createPieChart(createTitle(loadType), // chart title (DefaultPieDataset) ChartDataset.createDataset(hpc, chartType, loadType), // data false, // include legend true, // tooltips? false // URLs? ); } else if (chartType.equals(ChartType.METER)) { plot = new MeterPlot((ValueDataset) ChartDataset.createDataset(hpc, chartType, loadType)); chart = new JFreeChart(createTitle(loadType), JFreeChart.DEFAULT_TITLE_FONT, plot, false); renderMeterChart(chart, loadType, hpc); } else if (chartType.equals(ChartType.BAR)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) ChartDataset.createDataset(hpc, chartType), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); renderBarChart(chart); } else if (chartType.equals(ChartType.LAYERED)) { plot = new CategoryPlot((CategoryDataset) ChartDataset.createDataset(hpc, chartType), new CategoryAxis("Resources"), new NumberAxis(createTitle(loadType)), new LayeredBarRenderer()); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); renderLayeredBarChart(chart); } else if (chartType.equals(ChartType.STACKED)) { chart = ChartFactory.createStackedBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) ChartDataset.createDataset(hpc, chartType), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); renderStackedBarChart(chart); } else if (chartType.equals(ChartType.BAR)) { chart = ChartFactory.createBarChart("", // chart title "Resources", // domain axis label createTitle(loadType), // range axis label (CategoryDataset) ChartDataset.createDataset(hpc, chartType), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); renderBarChart(chart); } return chart; }