List of usage examples for org.jfree.chart ChartFactory createBarChart
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:userinterface.AdministratorWorkArea.TopMedicineJPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); int i = 1;//w w w .j ava2 s . c om for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) { dataSet.setValue(((MedicineWorkRequest) request).getQuantityOrdered(), "Number Of Medicines Ordered", ((MedicineWorkRequest) request).getMedicineName()); i++; } JFreeChart chart = ChartFactory.createBarChart("Popular Medicines in Hospital Graph", "Medicine Name", "Quantity", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart for Patient", chart); frame.setVisible(true); frame.setSize(800, 550); }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) { JFreeChart chart = null;//from ww w . j a va2 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:UserInterface.StoreManager.StoreReportsPanel.java
private void productReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productReportButtonActionPerformed // TODO add your handling code here: ArrayList<Comparison> cmp1 = new ArrayList<>(); for (Product p : enterprise.getProductCatalog().getProductList()) { Comparison c = new Comparison(p.getName(), p.getSearchCount()); cmp1.add(c);// w ww. j ava 2 s. c o m } Collections.sort(cmp1); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(cmp1.get(0).getNumber(), "SearchCount", cmp1.get(0).getString()); dataset.setValue(cmp1.get(1).getNumber(), "SearchCount", cmp1.get(1).getString()); dataset.setValue(cmp1.get(2).getNumber(), "SearchCount", cmp1.get(2).getString()); JFreeChart chart = ChartFactory.createBarChart("Top 3 Searched Products", "Products", "SearchCounts", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Search Report", chart); frame.setVisible(true); frame.setSize(600, 400); }
From source file:org.eobjects.datacleaner.widgets.result.AbstractCrosstabResultSwingRenderer.java
protected void addDefaultBarChart(final DCTable table, final DisplayChartCallback displayChartCallback, final int row, final String measureName) { final ActionListener action = new ActionListener() { @Override// w ww . j ava 2 s . co m public void actionPerformed(ActionEvent e) { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final int columnCount = table.getColumnCount(); for (int j = 1; j < columnCount; j++) { String textValue = table.getTextValueAt(row, j); final Number value = NumberUtils.createNumber(textValue); dataset.setValue(value, table.getColumnName(j), ""); } final JFreeChart chart = ChartFactory.createBarChart("", "", measureName, dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtils.applyStyles(chart); final ChartPanel chartPanel = new ChartPanel(chart); displayChartCallback.displayChart(chartPanel); } }; final DCPanel panel = createActionableValuePanel(measureName, Alignment.LEFT, action, IMAGE_PATH_BAR_CHART); table.setValueAt(panel, row, 0); }
From source file:org.eobjects.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java
public JSplitPane renderGroupResult(final ValueCountingAnalyzerResult result) { final Integer distinctCount = result.getDistinctCount(); final Integer unexpectedValueCount = result.getUnexpectedValueCount(); final int totalCount = result.getTotalCount(); _valueCounts = result.getReducedValueFrequencies(_preferredSlices); for (ValueFrequency valueCount : _valueCounts) { setDataSetValue(valueCount.getName(), valueCount.getCount()); }// w w w. j a v a2 s . c o m logger.info("Rendering with {} slices", getDataSetItemCount()); drillToOverview(result); // chart for display of the dataset String title = "Value distribution of " + _groupOrColumnName; final JFreeChart chart = ChartFactory.createBarChart(title, "Value", "Count", _dataset, PlotOrientation.HORIZONTAL, true, true, false); List<Title> titles = new ArrayList<Title>(); titles.add(new ShortTextTitle("Total count: " + totalCount)); if (distinctCount != null) { titles.add(new ShortTextTitle("Distinct count: " + distinctCount)); } if (unexpectedValueCount != null) { titles.add(new ShortTextTitle("Unexpected value count: " + unexpectedValueCount)); } chart.setSubtitles(titles); ChartUtils.applyStyles(chart); // code-block for tweaking style and coloring of chart { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setVisible(false); int colorIndex = 0; for (int i = 0; i < getDataSetItemCount(); i++) { final String key = getDataSetKey(i); final Color color; final String upperCaseKey = key.toUpperCase(); if (_valueColorMap.containsKey(upperCaseKey)) { color = _valueColorMap.get(upperCaseKey); } else { if (i == getDataSetItemCount() - 1) { // the last color should not be the same as the first if (colorIndex == 0) { colorIndex++; } } Color colorCandidate = SLICE_COLORS[colorIndex]; int darkAmount = i / SLICE_COLORS.length; for (int j = 0; j < darkAmount; j++) { colorCandidate = WidgetUtils.slightlyDarker(colorCandidate); } color = colorCandidate; colorIndex++; if (colorIndex >= SLICE_COLORS.length) { colorIndex = 0; } } plot.getRenderer().setSeriesPaint(i, color); } } final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.addChartMouseListener(new ChartMouseListener() { // // @Override // public void chartMouseMoved(ChartMouseEvent event) { // ChartEntity entity = event.getEntity(); // if (entity instanceof PieSectionEntity) { // PieSectionEntity pieSectionEntity = (PieSectionEntity) entity; // String sectionKey = (String) pieSectionEntity.getSectionKey(); // if (_groups.containsKey(sectionKey)) { // chartPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // } else { // chartPanel.setCursor(Cursor.getDefaultCursor()); // } // } else { // chartPanel.setCursor(Cursor.getDefaultCursor()); // } // } // // @Override // public void chartMouseClicked(ChartMouseEvent event) { // ChartEntity entity = event.getEntity(); // if (entity instanceof PieSectionEntity) { // PieSectionEntity pieSectionEntity = (PieSectionEntity) entity; // String sectionKey = (String) pieSectionEntity.getSectionKey(); // if (_groups.containsKey(sectionKey)) { // drillToGroup(result, sectionKey, true); // } // } // } // }); final DCPanel leftPanel = new DCPanel(); leftPanel.setLayout(new VerticalLayout()); leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel, true, 4)); _backButton.setMargin(new Insets(0, 0, 0, 0)); _backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { drillToOverview(result); } }); final DCPanel rightPanel = new DCPanel(); rightPanel.setLayout(new BorderLayout()); rightPanel.add(_backButton, BorderLayout.NORTH); rightPanel.add(_table.toPanel(), BorderLayout.CENTER); final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setOpaque(false); split.add(leftPanel); split.add(rightPanel); split.setDividerLocation(550); return split; }
From source file:uk.ac.lkl.cram.ui.chart.FeedbackChartMaker.java
/** * Create a chart from the provided category dataset * @return a Chart that can be rendered in a ChartPanel *//*w w w . java2 s. c o m*/ @Override protected JFreeChart createChart() { //Create a vertical bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false); //Get the font from the platform UI Font chartFont = UIManager.getFont("Label.font"); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Get the renderer from the plot BarRenderer barRenderer = (BarRenderer) plot.getRenderer(); //Set the rendered to use a standard bar painter (nothing fancy) barRenderer.setBarPainter(new StandardBarPainter()); //Set the colours for the bars barRenderer.setSeriesPaint(0, PEER_ONLY_COLOR); barRenderer.setSeriesPaint(1, TEL_COLOR); barRenderer.setSeriesPaint(2, TUTOR_COLOR); //Set the tooltip to be series, category and value barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator( "<html><center>{0} ({2} hours)<br/>Double-click for more</center></html>", NumberFormat.getInstance())); //Get the category axis (that's the X-axis in this case) CategoryAxis categoryAxis = plot.getDomainAxis(); //Set the font for rendering the labels on the x-axis to be the platform default categoryAxis.setLabelFont(chartFont); //Hide the tick marks and labels for the x-axis categoryAxis.setTickMarksVisible(false); categoryAxis.setTickLabelsVisible(false); //Set the label for the x-axis categoryAxis.setLabel("Feedback to individuals or group"); //Get the number axis (that's the Y-axis in this case) NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //Use the same font as the x-axis numberAxis.setLabelFont(chartFont); //Set the label for the vertical axis numberAxis.setLabel("Hours"); return chart; }
From source file:org.jfree.chart.demo.ItemLabelDemo2.java
/** * Creates a sample chart.//from w ww . j ava 2s . co m * * @param dataset * the dataset. * @return the chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Item Label Demo 2", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.25); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); // use one or the other of the following lines to see the different modes for // the label generator... renderer.setLabelGenerator(new LabelGenerator(null)); // renderer.setLabelGenerator(new LabelGenerator(0)); return chart; }
From source file:control.JGeraGraficos.java
public ChartPanel GetGraficoParcial(ArrayList<DadosEstatisticos> listaParcial, String Titulo) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int i = 0;/*from w ww .j a v a2s.com*/ dataset.clear(); for (DadosEstatisticos dados : listaParcial) { i++; if (listaParcial.indexOf(dados) < 2) { dataset.setValue(dados.getTempoGasto(), "C" + i + " - " + dados.getDescricao(), "C" + i); } else { dataset.setValue(dados.getTempoGasto(), "C" + i + " - " + dados.getDimensoes(), "C" + i); } } JFreeChart chart = ChartFactory.createBarChart(Titulo, null, "Tempo(ms)", dataset, PlotOrientation.HORIZONTAL, true, true, true); ChartPanel CP = new ChartPanel(chart); CP.setBounds(5, 15, 180, 470); return CP; }
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java
/** * Creates a sample chart.//www . j a v a2 s .c o m * * @param dataset the dataset. * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset, int typeOfChart) { String title = ""; if (typeOfChart == 1) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.compare.todayandyesterday", null); else if (typeOfChart == 2) title = VCTTracUtil.getMessage("vcttrac.year", null) + " : " + (new Date().getYear() + 1900); else if (typeOfChart == 3) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.years", null); // create the chart... JFreeChart chart = ChartFactory.createBarChart(title, null, null, // chart title dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); Paint[] colors = createPaint(); CustomBarRenderer renderer = new CustomBarRenderer(colors); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(renderer); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.15); // CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 12)); if (typeOfChart < 2) domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); else domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo1.java
protected JFreeChart createLegend(CategoryDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );//from w ww. j av a2 s.c o m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); // renderer.setDrawOutlines(true); // renderer.setUseFillPaint(true); // renderer.setFillPaint(Color.white); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); return chart; }