List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo2.java
/** * Creates a sample chart.// w w w. j a v a 2s.co m * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation !legendPanelOn, // include legend true, // tooltips? false // URLs? ); 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); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... LayeredBarRenderer renderer = new LayeredBarRenderer(); renderer.setDrawBarOutline(false); plot.setRenderer(renderer); // for this renderer, we need to draw the first series last... plot.setRowRenderingOrder(SortOrder.DESCENDING); // set up gradient paints for series... 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.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo2.java
/** * Creates a sample chart./*from ww w.j ava 2s. c om*/ * * @param dataset the dataset. * * @return a sample chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createStackedBarChart(chartTitle, domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation !legendPanelOn, // include legend true, // tooltips false // urls ); /* CategoryPlot plot = (CategoryPlot) chart.getPlot(); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setItemLabelsVisible(true);*/ CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer renderer = new ExtendedStackedBarRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(renderer); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); StackedBarRenderer renderer2 = (StackedBarRenderer) plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:com.cwctravel.hudson.plugins.suitegroupedtests.TrendGraph.java
@Override protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/* w ww .j ava 2 s. c o m*/ chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 7962375662395944968L; @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getURL() + relativeUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
private JFreeChart createDonorsByStateReportsChart(CategoryDataset dataset) { JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors by State", "State", " No Of Registered Donors", dataset, PlotOrientation.VERTICAL, true, true, false); barChart.setBackgroundPaint(Color.white); // Set the background color of the chart barChart.getTitle().setPaint(Color.DARK_GRAY); barChart.setBorderVisible(true);/*from www . ja v a2 s. co m*/ // Adjust the color of the title CategoryPlot plot = barChart.getCategoryPlot(); plot.getRangeAxis().setLowerBound(0.0); // Get the Plot object for a bar graph plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.blue); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.decode("#00008B")); //return chart; return barChart; }
From source file:org.jfree.chart.demo.MinMaxCategoryPlotDemo.java
/** * Creates a new demo.// ww w . java 2s.c om * * @param title the frame title. */ public MinMaxCategoryPlotDemo(final String title) { super(title); // create a dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "First", "Category 1"); dataset.addValue(4.0, "First", "Category 2"); dataset.addValue(3.0, "First", "Category 3"); dataset.addValue(5.0, "First", "Category 4"); dataset.addValue(5.0, "First", "Category 5"); dataset.addValue(7.0, "First", "Category 6"); dataset.addValue(7.0, "First", "Category 7"); dataset.addValue(8.0, "First", "Category 8"); dataset.addValue(5.0, "Second", "Category 1"); dataset.addValue(7.0, "Second", "Category 2"); dataset.addValue(6.0, "Second", "Category 3"); dataset.addValue(8.0, "Second", "Category 4"); dataset.addValue(4.0, "Second", "Category 5"); dataset.addValue(4.0, "Second", "Category 6"); dataset.addValue(2.0, "Second", "Category 7"); dataset.addValue(1.0, "Second", "Category 8"); dataset.addValue(4.0, "Third", "Category 1"); dataset.addValue(3.0, "Third", "Category 2"); dataset.addValue(2.0, "Third", "Category 3"); dataset.addValue(3.0, "Third", "Category 4"); dataset.addValue(6.0, "Third", "Category 5"); dataset.addValue(3.0, "Third", "Category 6"); dataset.addValue(4.0, "Third", "Category 7"); dataset.addValue(3.0, "Third", "Category 8"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Min/Max Category Plot", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.yellow); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRenderer(new MinMaxCategoryRenderer()); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:view.PrograssCharts.java
/** * Creates new form PrograssCharts//from w ww. java 2 s.c om */ public PrograssCharts(java.awt.Frame parent, boolean modal) { super(parent, modal); try { initComponents(); setSize(1400, 800); jPanel1.setVisible(false); jPanel2.setVisible(false); new Thread(new Runnable() { @Override public void run() { loading1(); loading2(); run(); } }).start(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset.setValue(QuestionLab.cat1, "gfdg", "Collectns"); dataset.setValue(QuestionLab.cat2, "gfdg", "Data"); dataset.setValue(QuestionLab.cat3, "gfdg", "Dev"); dataset.setValue(QuestionLab.cat4, "gfdg", "Excep"); dataset.setValue(QuestionLab.cat5, "gfdg", "File"); dataset.setValue(QuestionLab.cat6, "gfdg", "FlowCon"); dataset.setValue(QuestionLab.cat7, "gfdg", "Format"); dataset.setValue(QuestionLab.cat8, "gfdg", "GC"); dataset.setValue(QuestionLab.cat9, "gfdg", "IC"); dataset.setValue(QuestionLab.cat10, "gfdg", "VarArgs"); dataset.setValue(QuestionLab.cat11, "gfdg", "Fundamt"); dataset.setValue(QuestionLab.cat12, "gfdg", "Modif"); dataset.setValue(QuestionLab.cat13, "gfdg", "OOP"); dataset.setValue(QuestionLab.cat14, "gfdg", "Vari"); dataset.setValue(QuestionLab.cat15, "gfdg", "String"); dataset.setValue(QuestionLab.cat16, "gfdg", "Threads"); dataset.setValue(QuestionLab.cat17, "gfdg", "WC"); JFreeChart freeChart = ChartFactory.createBarChart("Exam Prograss by Subjects", "Subject", "Marks", dataset, PlotOrientation.VERTICAL, false, true, false); //JFreeChart freeChart1 = ChartFactory.createBarChart("Income", " Name", "Incomesss", dataset1, PlotOrientation.VERTICAL, false, true, false); TimeSeries pop = new TimeSeries("Population", Day.class); //JFreeChart chart=ChartFactory.create CategoryPlot plot = freeChart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Exam Prograss", freeChart); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel1.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(freeChart); CP.setPreferredSize(new Dimension(785, 440)); CP.setMouseWheelEnabled(true); jPanel1.add(CP); jPanel1.revalidate(); ArrayList<Exam> setChartValue = ServerConnector.getServerConnector().getExamController() .getPreviousMarks(PracticeExamLogIn.studentNic); for (Exam exam : setChartValue) { //dataset1.setValue(exam.getMarks(), "gfdg9", exam.getDate()); pop.addOrUpdate(new Day(exam.getDate()), exam.getMarks()); System.out.println("mar" + exam.getMarks()); System.out.println("date" + exam.getDate()); } TimeSeriesCollection myDataset = new TimeSeriesCollection(); myDataset.addSeries(pop); JFreeChart myChart = ChartFactory.createTimeSeriesChart("Population Your Marks", "Date", "Population", myDataset, true, true, false); //try { //ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300); //} catch (IOException e) { //System.err.println("Problem occurred creating chart."); //} //JFreeChart chart=ChartFactory.create CategoryPlot plot1 = freeChart.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.BLUE); //ChartFrame frame1 = new ChartFrame("Exam Prograss", freeChart1); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel2.setLayout(new java.awt.BorderLayout()); ChartPanel CP1 = new ChartPanel(myChart); CP1.setPreferredSize(new Dimension(785, 440)); CP1.setMouseWheelEnabled(true); jPanel2.add(CP1); jPanel2.revalidate(); } catch (RemoteException | ClassNotFoundException | SQLException | NotBoundException | MalformedURLException ex) { Logger.getLogger(PrograssCharts.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:UserInterface.DonorRole.DonorWorkAreaJPanel.java
private void generateOverallAnalysis() { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount(); dataSet.setValue(objWorldEnterprise.getObjTransactionDirectory().getAvailableVirtualBalance(), "Amount left", "Donation left"); dataSet.setValue(objWorldEnterprise.getObjTransactionDirectory().getTotalVirtualDebitAmount(), "Amount donated", "Donation given"); JFreeChart chart = ChartFactory.createBarChart3D("Overview of Donation received and delivered", "Donation", "Amount in USD $", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.black); ChartPanel myChart = new ChartPanel(chart); donationOverviewJPanel.setLayout(new java.awt.BorderLayout()); donationOverviewJPanel.add(myChart, BorderLayout.CENTER); donationOverviewJPanel.validate();/*from w w w .j a va 2 s.c o m*/ }
From source file:com.cwctravel.hudson.plugins.multimoduletests.TrendGraph.java
@Override protected JFreeChart createGraph() { final CategoryDataset dataset = createDataSet().build(); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart // title null, // unused yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );//from www . java 2s. co m chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 7962375662395944968L; @Override public Paint getItemPaint(int row, int column) { ChartLabel key = (ChartLabel) dataset.getColumnKey(column); if (key.getColor() != null) return key.getColor(); return super.getItemPaint(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return prefixUrl + label.getURL() + suffixUrl; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTipText(); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Skips. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:com.swordlord.gozer.components.wicket.graph.GWStackedBarChartPanel.java
public GWStackedBarChartPanel(String id, IModel<?> model, GStackedBarChart child) { super(id, model); gchart = child;/*from w w w.j a v a 2 s . c o m*/ DataBindingMember dbMemberRowKey = child.getDataBindingMemberRowKey(); DataBindingMember dbMemberTargetId = child.getDataBindingMemberTargetId(); DataBindingMember dbMemberColKey = child.getDataBindingMemberColKey(); DataBindingMember dbMemberValue = child.getDataBindingMemberValue(); DataBindingManager dbManager = child.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> rows = dbManager.getRows(dbMemberValue); // if the graph has some ordering info in the format of "<field> ASCENDING,<field2> DESCENDING" if (child.hasOrdering()) { List<Ordering> ordering = child.formatOrdering(child.getOrdering()); OrderingEx.orderList(rows, ordering); } for (int j = 0; j < rows.size(); j++) { DataRowBase row = rows.get(j); String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField()); dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey, row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField())); if (dbMemberTargetId != null) { _target.put(strKey, row.getPropertyAsStringForce(dbMemberTargetId.getDataBindingFieldName())); } } JFreeChart chart = ChartFactory.createStackedBarChart(child.getTitle(), child.getCategoryAxisLabel(), child.getValueAxisLabel(), dcd, child.getOrientation(), child.getLegend(), false, false); // Do this in a more static way! StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter()); //chart.setBackgroundPaint(Color.white); if (child.getSubTitle() != null) { chart.addSubtitle(new TextTitle(child.getSubTitle())); } CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDrawingSupplier(child.getDrawingSupplier()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(child.getCategoryAxisVisible()); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setVisible(child.getValueAxisVisible()); /* //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer(); for (int j = 0; j < rowKey.length; j++) { renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j])); renderer.setSeriesItemLabelsVisible(j, true); } */ StackedBarRenderer renderer = new StackedBarRenderer(); for (int j = 0; j < dcd.getRowCount(); j++) { renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(j, true); } //renderer.setLegendItemLabelGenerator(new LabelGenerator()); renderer.setShadowVisible(false); plot.setRenderer(renderer); ChartImage image = new ChartImage("chart", chart, child.getWidth(800), child.getHeight(800)); String mapName = child.getCaption(); add(image); DynamicImageMap imageMap = constructImageMap(image, mapName); if (!child.isClickable()) { imageMap.setVisible(false); } else { image.add(new AttributeModifier("usemap", new Model<String>("#" + mapName))); } add(imageMap); }
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java
/** * Creates a sample chart.//from w w w . j a v a 2 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; }