List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:support.TradingVolumeGui.java
private CategoryPlot createChartFrame(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Trading Volume", "Stock", "Volume, USD", dataset, PlotOrientation.HORIZONTAL, true, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.getRenderer().setSeriesPaint(0, Color.BLUE); JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Hazelcast Jet Source Builder Sample"); frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLayout(new BorderLayout()); frame.add(new ChartPanel(chart)); frame.setVisible(true);/*from w w w. ja v a2 s.c o m*/ frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { hzMap.removeEntryListener(entryListenerId); } }); return plot; }
From source file:net.sf.dynamicreports.test.jasper.chart.ChartSeriesColorsByNameTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);/*w ww . ja v a 2 s . c om*/ chartCountTest("summary.chart1", 1); JFreeChart chart = getChart("summary.chart1", 0); CategoryItemRenderer renderer1 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset1 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset1.getRowCount(); i++) { String key = (String) dataset1.getRowKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer1.getSeriesPaint(i)); } chartCountTest("summary.chart2", 1); chart = getChart("summary.chart2", 0); CategoryItemRenderer renderer2 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset2 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset2.getRowCount(); i++) { String key = (String) dataset2.getRowKey(i); key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer2.getSeriesPaint(i)); } for (int i = 0; i < chart.getCategoryPlot().getFixedLegendItems().getItemCount(); i++) { LegendItem legendItem = chart.getCategoryPlot().getFixedLegendItems().get(i); Assert.assertNotNull("null series color", colors.get(legendItem.getLabel())); Assert.assertEquals("series color", colors.get(legendItem.getLabel()), legendItem.getFillPaint()); } chartCountTest("summary.chart3", 1); chart = getChart("summary.chart3", 0); PiePlot plot3 = (PiePlot) chart.getPlot(); PieDataset dataset3 = plot3.getDataset(); for (int i = 0; i < dataset3.getItemCount(); i++) { String key = (String) dataset3.getKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), plot3.getSectionPaint(key)); } chartCountTest("summary.chart4", 1); chart = getChart("summary.chart4", 0); XYItemRenderer renderer4 = chart.getXYPlot().getRenderer(); XYDataset dataset4 = chart.getXYPlot().getDataset(); for (int i = 0; i < dataset4.getSeriesCount(); i++) { String key = (String) dataset4.getSeriesKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer4.getSeriesPaint(i)); } }
From source file:bbank.QuantityTimeGraphWindow.java
public QuantityTimeGraphWindow() { initComponents();//from w ww .j a v a 2 s . co m DefaultCategoryDataset dataset = new DefaultCategoryDataset(); BloodStock.collectGraphData(SelectedItem); String title = "Quantity vs Time Graph"; switch (SelectedItem) { case 0: title = "Quantity vs Time Graph for Blood type A"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; case 1: title = "Quantity vs Time Graph for Blood type B"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; case 2: title = "Quantity vs Time Graph for Blood type O"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; } JFreeChart chart = ChartFactory.createLineChart(title, "Date", "Amount (litres)", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); ChartPanel chartpanel = new ChartPanel(chart); jPanel1.removeAll(); jPanel1.add(chartpanel); jPanel1.validate(); }
From source file:graficos.GenerarGraficoInventario.java
public void crear() { try {//www . ja v a2 s .co m Dba db = new Dba(pathdb); db.conectar(); String sql = "select Nombre, CantidadDisponibles, CantidadEnUso from Activos"; db.prepare(sql); db.query.execute(); ResultSet rs = db.query.getResultSet(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); while (rs.next()) { int total = rs.getInt(2) + rs.getInt(3); dataset.setValue(total, "Cantidad", rs.getString(1)); } JFreeChart chart = ChartFactory.createBarChart3D("Inventario de Activos del Hotel", "Activo", "Cantidad", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph p.setBackgroundPaint(Color.black); ((BarRenderer) p.getRenderer()).setBarPainter(new StandardBarPainter()); BarRenderer r = (BarRenderer) chart.getCategoryPlot().getRenderer(); r.setSeriesPaint(0, Color.BLUE); try { ChartUtilities.saveChartAsJPEG(new File(path), chart, 500, 300); } catch (Exception ee) { System.err.println(ee.toString()); System.err.println("Problem occurred creating chart."); } db.desconectar(); } catch (Exception e) { } }
From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeStacked100PercentBarChartGenerator.java
/** * Creates stacked 100 percent bar chart and creates range axis for it. * </p>// w w w . j a v a 2s. co m * @param chartDocContext Current chart's document context. * @param data Current chart data. * @return Returns JFree stacked 100 percent bar chart. */ public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) { final JFreeChart chart = super.createChart(chartDocContext, data); /* * Doing all the render stuff and then off to create range axis. * NOTE: The chart object will be updated. */ ((StackedBarRenderer) chart.getCategoryPlot().getRenderer()).setRenderAsPercentages(true); final NumberAxis rangeAxis = (NumberAxis) chart.getCategoryPlot().getRangeAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); createRangeAxis(chartDocContext, data, chart); return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.chart.line.JFree3DLineChartGenerator.java
protected JFreeChart doCreateChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) { 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); final JFreeChart chart = ChartFactory.createLineChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset, orientation, legend, toolTips, toolTips); final CategoryPlot categoryPlot = chart.getCategoryPlot(); categoryPlot.setRenderer(new LineRenderer3D()); final ChartElement[] seriesElements = chartDocument.getRootElement() .findChildrenByName(ChartElement.TAG_NAME_SERIES); if (categoryPlot != null && seriesElements != null) { setSeriesAttributes(seriesElements, data, categoryPlot); }//from ww w .j a v a 2 s.c om return chart; }
From source file:org.endeavour.mgmt.controller.servlet.CreateProjectPlan.java
private void createReportPage(Document aDocument, TaskSeries aTaskSeries, Date aStartDate, Date aEndDate, String aDescription) throws Exception { TaskSeriesCollection theDataset = new TaskSeriesCollection(); theDataset.add(aTaskSeries);/* w w w . j a va2 s .c o m*/ DateAxis theDateRange = new DateAxis(TIMELINE); theDateRange.setMinimumDate(aStartDate); theDateRange.setMaximumDate(aEndDate); JFreeChart theChart = ChartFactory.createGanttChart(aDescription, ARTIFACTS, null, theDataset, true, false, false); CategoryPlot theCategoryPlot = theChart.getCategoryPlot(); theCategoryPlot.setRangeAxis(theDateRange); BufferedImage theChartImage = theChart.createBufferedImage(780, 520); ByteArrayOutputStream theOutputStream = new ByteArrayOutputStream(); ImageIO.write(theChartImage, "png", theOutputStream); Image theDocumentImage = Image.getInstance(theOutputStream.toByteArray()); aDocument.add(theDocumentImage); }
From source file:gchisto.gui.panels.gcstats.BreakdownChartPanelMulti.java
/** * It creates a chart for the given dataset and adds the chart to the panel. * * @param dataset The dataset that will provide the values for the chart. *//*from w w w. jav a2s.c o m*/ private void addChart() { JFreeChart chart = ChartFactory.createStackedBarChart3D(getTitle(), null, "Breakdown" + unitSuffix(), dataset, PlotOrientation.VERTICAL, true, true, false); CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chart.addProgressListener(locker); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator(dataset); mainPanel().add(BorderLayout.CENTER, new ChartPanel(chart)); }
From source file:pidev.gui.FrameStat.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(80, "Marks", "Student1"); dataset.setValue(50, "Marks", "Student2"); dataset.setValue(75, "Marks", "Student3"); dataset.setValue(95, "Marks", "Student4"); JFreeChart chart = ChartFactory.createBarChart("Student score", "Student Name", "Marks", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame("Bar Chart for student", chart); frame.setVisible(true);//from w w w . j a v a2 s .com frame.setSize(450, 350); }
From source file:muh.GrafikDeneme.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed DefaultCategoryDataset dcd = new DefaultCategoryDataset(); dcd.setValue(78.80, "Marks", "Ganesh"); dcd.setValue(68.80, "Marks", "Dinesh"); dcd.setValue(88.80, "Marks", "John"); dcd.setValue(98.80, "Marks", "Ali"); dcd.setValue(58.80, "Marks", "Sachin"); JFreeChart jchart = ChartFactory.createBarChart3D("Student Record", "Student Name", "Student Marks", dcd, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = jchart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.black); ChartFrame chartFrm = new ChartFrame("Student Record", jchart, true); chartFrm.setVisible(true);//from w ww .j a v a2s .c om chartFrm.setSize(500, 400); //SMD PENCERENN NE KOYACAAAAAAAAAAAAAAAAK ChartPanel chartPanel = new ChartPanel(jchart); // DESGNDEN PANELN ADINI DETRD pnlReport ,,set layout=box pnlReport.removeAll(); pnlReport.add(chartPanel); pnlReport.updateUI(); }