Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Create and display an overlaid chart.
 * //ww w .j av  a  2s.c  o m
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset1.
 * @param data2
 *           dataset2.
 */
private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Animals Overlaid";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = "Animal";

    // combine the y symbolic values of the two data sets...
    final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
            (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // create main plot...
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer);

    plot.setDataset(1, series1);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(1, renderer1);

    plot.setDataset(2, series2);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(2, renderer2);

    plot.setDataset(3, series3);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(3, renderer3);

    plot.setDataset(4, series4);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(4, renderer4);

    plot.setDataset(5, series5);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(5, renderer5);

    plot.setDataset(6, series6);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(6, renderer6);

    plot.setDataset(7, series7);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(7, renderer7);

    // make the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.drools.planner.benchmark.core.statistic.bestscore.BestScoreProblemStatistic.java

protected void writeGraphStatistic() {
    NumberAxis xAxis = new NumberAxis("Time spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName());
        for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            Score score = point.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }//from  w ww .j ava 2s  .  co  m
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (singleStatistic.getPointList().size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " best score statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "BestScoreStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.operamasks.faces.render.graph.CompositeChartRenderer.java

private JFreeChart createCategoryCompositeChart(List<JFreeChart> subcharts, UIChart comp) {
    CategoryPlot compositePlot = new CategoryPlot();
    compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    compositePlot.setOrientation(getChartOrientation(comp));

    for (int i = 0; i < subcharts.size(); i++) {
        CategoryPlot subplot = (CategoryPlot) subcharts.get(i).getPlot();
        compositePlot.setDataset(i, subplot.getDataset());
        compositePlot.setRenderer(i, subplot.getRenderer());

        if (i == 0) {
            // Axis zero is always available.
            compositePlot.setDomainAxis(0, subplot.getDomainAxis());
            compositePlot.setRangeAxis(0, subplot.getRangeAxis());
        } else {//ww  w  .  java2s  .c o m
            int yAxisMap = getRangeAxisMap(comp, i);
            ValueAxis yAxis = null;
            if (yAxisMap == -1) {
                yAxisMap = 0; // map to axis zero by default
            } else if (yAxisMap == i) {
                yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot
            }
            compositePlot.setRangeAxis(i, yAxis);
            compositePlot.mapDatasetToRangeAxis(i, yAxisMap);
        }
    }

    return new JFreeChart(null, null, compositePlot, false);
}

From source file:com.unicornlabs.kabouter.gui.power.PowerPanel.java

/**
 * Sets the chart data and title/*from ww  w  . j  a va  2  s.  c  o  m*/
 *
 * @param logs the list of power logs
 * @param title the title of the chart
 */
public void setupChart(ArrayList<Powerlog> logs, String title) {

    myDataSeriesMap.clear();

    //Create a collection to store the series
    dataset = new XYSeriesCollection();

    //Add each of the logs to the series
    for (Powerlog p : logs) {
        XYSeries deviceSeries = myDataSeriesMap.get(p.getId().getDeviceid());

        if (deviceSeries == null) {
            deviceSeries = new XYSeries(p.getId().getDeviceid());
            myDataSeriesMap.put(p.getId().getDeviceid(), deviceSeries);
            dataset.addSeries(deviceSeries);
        }

        deviceSeries.add(p.getId().getLogtime().getTime(), p.getPower());
    }

    //Create a custom date axis to display dates on the X axis
    DateAxis dateAxis = new DateAxis("Date");
    //Make the labels vertical
    dateAxis.setVerticalTickLabels(true);

    //Create the power axis
    NumberAxis powerAxis = new NumberAxis("Power");

    //Set both axes to auto range for their values
    powerAxis.setAutoRange(true);
    dateAxis.setAutoRange(true);

    //Create the tooltip generator
    StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
            new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

    //Set the renderer
    StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null);

    //Create the plot
    XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

    //Create the chart
    myChart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //Attach the chart to the panel
    ((ChartPanel) chartPanel).setChart(myChart);
    //Set max draw size to 2560x1440
    ((ChartPanel) chartPanel).setMaximumDrawHeight(1440);
    ((ChartPanel) chartPanel).setMaximumDrawWidth(2560);
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesChart.java

@Override
protected JFreeChart createGraph() {
    TimeTableXYDataset dataset = createDataset();
    ValueAxis xAxis = new DateAxis();
    xAxis.setLowerMargin(0.0);/*from   w  w  w.  j  ava 2  s  .  co m*/
    xAxis.setUpperMargin(0.0);
    Calendar lowerBound = getLowerGraphBound();
    xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis());

    NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            String seriesKey = dataset.getSeriesKey(series).toString();
            StringBuilder sb = new StringBuilder();

            if (seriesKey.equals(GRAPH_OTHERS)) {
                long timeInMillis = dataset.getX(series, item).longValue();
                Date time = new Date(timeInMillis);

                TimePeriod period = null;
                if (intervalSize == Calendar.DATE) {
                    period = new Day(time);
                } else if (intervalSize == Calendar.HOUR_OF_DAY) {
                    period = new Hour(time);
                } else if (intervalSize == Calendar.MONTH) {
                    period = new Month(time);
                }
                List<FailureCauseTimeInterval> excludedDataList = excludedDataForPeriod.get(period);
                if (excludedDataList != null) {
                    Collections.sort(excludedDataList, new Comparator<FailureCauseTimeInterval>() {

                        @Override
                        public int compare(FailureCauseTimeInterval o1, FailureCauseTimeInterval o2) {
                            return o2.getNumber() - o1.getNumber();
                        }
                    });
                    for (FailureCauseTimeInterval excludedData : excludedDataList) {
                        sb.append(excludedData).append(" \n");
                    }
                }
            } else {
                int number = dataset.getY(series, item).intValue();
                sb.append(seriesKey).append(": ").append(number);
            }
            return sb.toString();
        }
    });

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.setRangeAxis(yAxis);

    JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    return chart;
}

From source file:action.GraphAction.java

public String drawgraph() {

    List<CustomerOrder> orderList = new ArrayList<CustomerOrder>();

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    TransactionDao transactionDao = new TransactionDao();
    //  orderList = transactionDao.findByDate(fromdate, todate);
    orderList = (List<CustomerOrder>) request.getSession().getAttribute("orderList");
    int a = orderList.size();
    System.out.println("Size--->" + a);
    Number[] values = getValues(orderList);
    System.out.println("final values are " + Arrays.toString(values));

    final Number[][] data = new Number[][] { values, {} };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("", "", data);

    JFreeChart chart = null;//from  w ww  . j  a  va  2 s. co  m
    BarRenderer renderer3D = null;
    CategoryPlot plot = null;

    final CategoryAxis3D categoryAxis = new CategoryAxis3D("Month");
    final ValueAxis valueAxis = new NumberAxis3D("Number of Transactions");
    renderer3D = new BarRenderer3D();

    plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer3D);
    plot.setOrientation(PlotOrientation.VERTICAL);
    chart = new JFreeChart("Online Transactions", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(new Color(152, 169, 236));

    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        final File file1 = new File("D:\\3dbarchart.png");
        OutputStream out = ServletActionContext.getResponse().getOutputStream();
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        ChartUtilities.writeChartAsPNG(out, chart, 600, 400, info);

        out.close();
        //returnString = "success"; 

    } catch (Exception e) {
        System.out.println(e);
        // returnString = "error";
    }
    return SUCCESS;
}

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/*  www.j av a2 s  .c  o  m*/
 * @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.objectweb.proactive.extensions.timitspmd.util.charts.HierarchicalBarChart.java

private void buildFinalChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, int height,
        int width, String filename, Chart.Scale scaleMode, Chart.LegendFormat legendFormatMode, int alpha) {
    @SuppressWarnings("unchecked")
    Vector<Counter>[] vec = new Vector[this.timers.length];
    boolean exist;

    // create the dataset...
    for (int i = 0; i < this.timers.length; i++) {
        vec[i] = new Vector<Counter>();
        @SuppressWarnings("unchecked")
        Iterator<Element> it = this.timers[i].getDescendants();
        while (it.hasNext()) {
            try {
                Element elt = (Element) it.next();
                String name = elt.getAttributeValue("name");
                double value = Double.valueOf(elt.getAttributeValue("avg"));
                exist = false;/*  ww  w  .  j  av  a 2  s.c o  m*/
                for (int j = 0; j < vec[i].size(); j++) {
                    if (((Counter) vec[i].get(j)).getName().equals(name)) {
                        ((Counter) vec[i].get(j)).addValue(value);
                        exist = true;
                        break;
                    }
                }
                if (!exist) {
                    vec[i].add(new Counter(name, value));
                }
            } catch (ClassCastException e) {
                continue;
            }
        }
    }

    CategoryDataset dataset = null;
    try {
        dataset = DatasetUtilities.createCategoryDataset(toSeries(vec[0]), this.categories, toDataset(vec));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        throw new IllegalArgumentException(
                "Benchmark names must have different names. Be sure that your filter contains correct timers names");
    }

    // create the chart...
    final CategoryAxis categoryAxis = new CategoryAxis(xAxisLabel);
    final ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new HierarchicalBarRenderer());

    plot.setOrientation(PlotOrientation.VERTICAL);
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.addSubtitle(new TextTitle(subTitle));

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    final HierarchicalBarRenderer renderer = (HierarchicalBarRenderer) plot.getRenderer();

    renderer.setItemMargin(0.01);
    renderer.setDatasetTree(this.timers);
    renderer.setSeries(toSeries(vec[0]));
    renderer.setAlpha(alpha);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(HierarchicalBarChart.CATEGORY_MARGIN);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    try {
        if ((filename == null) || "".equals(filename)) {
            throw new RuntimeException(
                    "The output filename for the HierarchicalBarChart cannot be null or empty !");
        }

        ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(filename + ".png"), chart, width, height);

        Utilities.saveChartAsSVG(chart, new Rectangle(width, height),
                XMLHelper.createFileWithDirs(filename + ".svg"));
    } catch (java.io.IOException e) {
        System.err.println("Error writing chart image to file");
        e.printStackTrace();
    }
}

From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java

private JFreeChart createChart(String populationName, CategoryDataset categoryDataset, double max, double min) {
    CategoryAxis categoryaxis = new CategoryAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    //categoryaxis.setMaximumCategoryLabelWidthRatio(5F);
    //categoryaxis.setMaximumCategoryLabelLines(141);
    //categoryaxis.setCategoryMargin(450);

    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    lineandshaperenderer.setBaseShapesFilled(false);
    lineandshaperenderer.setBaseShape(ShapeUtilities.createDiamond((float) 3));
    lineandshaperenderer.setBaseSeriesVisibleInLegend(false);
    //lineandshaperenderer.setBaseLinesVisible(false);
    lineandshaperenderer.setAutoPopulateSeriesShape(false);
    lineandshaperenderer.setAutoPopulateSeriesPaint(false);
    //lineandshaperenderer.findRangeBounds(categoryDataset);

    NumberAxis numberaxis = new NumberAxis("Expression");
    numberaxis.setAutoRangeIncludesZero(false);
    //numberaxis.setRangeWithMargins(min, max);

    CategoryPlot categoryplot = new CategoryPlot(categoryDataset, categoryaxis, numberaxis,
            lineandshaperenderer);//from   w  w w.j a  va  2 s .  c  o  m
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart jfreechart = new JFreeChart(populationName, new Font("SansSerif", 1, 14), categoryplot, true);
    return jfreechart;
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Create the chart//www.  j  a v  a  2s .  co m
 */
private void createChart() {
    if (chartPanel != null) {
        return;
    }
    dataset = new TimeSeriesCollection();
    ValueAxis timeAxis = doMakeDateAxis();
    timeAxis.setLowerMargin(0.02);
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis("Data");
    valueAxis.setAutoRangeIncludesZero(false);
    plot = new MyTimeSeriesPlot(this, dataset, timeAxis, valueAxis);
    plot.setRenderer(doMakeRenderer());
    chart = new JFreeChart(getName(), JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    addAnnotations(segments);
    addAnnotations(wayPoints);
    for (int i = 0; i < wayPoints.size(); i++) {
        WayPoint waypoint = (WayPoint) wayPoints.get(i);
        waypoint.addPropertyChangeListener(this);
    }
    addAnnotations(rangeFilters);

    initXYPlot(plot);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        //            renderer.setDefaultShapesVisible(false);
        //            renderer.setDefaultShapesFilled(false);
        //      renderer.setDefaultShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //        axis.setDateFormatOverride(new SimpleDateFormat("HH:MM:ss"));
    chartPanel = doMakeChartPanel(chart);
}