Example usage for org.jfree.chart ChartFactory createLineChart

List of usage examples for org.jfree.chart ChartFactory createLineChart

Introduction

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

Prototype

public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a line chart with default settings.

Usage

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

/**
 * Creates a sample chart.//from  ww  w .  j  a  v a2 s .c o m
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    //    legend.setShapeScaleX(1.5);
    //  legend.setShapeScaleY(1.5);
    //legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);

    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 2.0f, 6.0f }, 0.0f));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:mzmatch.ipeak.normalisation.VanDeSompele.java

public static void main(String args[]) {
    try {//from ww  w . jav  a 2s . c  o  m
        Tool.init();

        // parse the commandline options
        Options options = new Options();
        CmdLineParser cmdline = new CmdLineParser(options);

        // check whether we need to show the help
        cmdline.parse(args);
        if (options.help) {
            Tool.printHeader(System.out, application, version);
            cmdline.printUsage(System.out, "");
            return;
        }

        if (options.verbose) {
            Tool.printHeader(System.out, application, version);
            cmdline.printOptions();
        }

        // check the command-line parameters
        {
            // if the output directories do not exist, create them
            if (options.output != null)
                Tool.createFilePath(options.output, true);
        }

        // load the data
        if (options.verbose)
            System.out.println("Loading data");
        ParseResult result = PeakMLParser.parse(new FileInputStream(options.input), true);

        Header header = result.header;
        IPeakSet<IPeakSet<? extends IPeak>> peaksets = (IPeakSet<IPeakSet<? extends IPeak>>) result.measurement;

        int nrmeasurements = header.getNrMeasurementInfos();

        // remove the stability factor annotation
        for (IPeak peak : peaksets)
            peak.removeAnnotation("stability factor");

        // load the database
        if (options.verbose)
            System.out.println("Loading the molecule database");
        HashMap<String, Molecule> database = MoleculeIO.parseXml(new FileInputStream(options.database));

        // filter the set to include only identifiable metabolites
        if (options.verbose)
            System.out.println("Creating selection");
        Vector<IPeakSet<? extends IPeak>> selection = new Vector<IPeakSet<? extends IPeak>>();
        for (Molecule molecule : database.values()) {
            double mass = molecule.getMass(Mass.MONOISOTOPIC);
            double delta = PeriodicTable.PPM(mass, options.ppm);

            // get the most intense peak containing all the measurements
            Vector<IPeakSet<? extends IPeak>> neighbourhoud = peaksets.getPeaksInMassRange(mass - delta,
                    mass + delta);
            Collections.sort(neighbourhoud, IPeak.sort_intensity_descending);
            for (IPeakSet<? extends IPeak> neighbour : neighbourhoud)
                if (count(neighbour) == nrmeasurements) {
                    selection.add(neighbour);
                    break;
                }
        }

        // calculate the stability factor for each peak in the selection
        if (options.verbose)
            System.out.println("Calculating stability factors");
        for (int peakid1 = 0; peakid1 < selection.size(); ++peakid1) {
            double stddeviations[] = new double[selection.size()];

            IPeakSet<? extends IPeak> peakset1 = selection.get(peakid1);
            for (int peakid2 = 0; peakid2 < selection.size(); ++peakid2) {
                IPeakSet<? extends IPeak> peakset2 = selection.get(peakid2);

                double values[] = new double[nrmeasurements];
                for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) {
                    int measurementid1 = peakset1.get(measurementid).getMeasurementID();
                    int setid1 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid1));
                    int measurementid2 = peakset2.get(measurementid).getMeasurementID();
                    int setid2 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid2));
                    if (setid1 != setid2 || measurementid1 != measurementid2)
                        System.err.println("[WARNING]: differing setid or spectrumid for comparison");

                    values[measurementid] = Math.log(peakset1.get(measurementid).getIntensity()
                            / peakset2.get(measurementid).getIntensity()) / Math.log(2);
                }
                stddeviations[peakid2] = Statistical.stddev(values);
            }

            peakset1.addAnnotation("stability factor", Statistical.mean(stddeviations));
        }

        // sort on the stability factor
        Collections.sort(selection, new IPeak.AnnotationAscending("stability factor"));

        // take the top 10% and calculate the geometric mean
        if (options.verbose)
            System.out.println("Calculating normalisation factors");
        int nrselected = (int) (0.1 * selection.size());
        if (nrselected < 10)
            nrselected = (10 < selection.size() ? 10 : selection.size());
        double normalization_factors[] = new double[nrmeasurements];
        for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) {
            double values[] = new double[nrselected];
            for (int i = 0; i < nrselected; ++i) {
                IPeak peak = selection.get(i).get(measurementid);
                values[i] = peak.getIntensity();
            }
            normalization_factors[measurementid] = Statistical.geomean(values);
        }

        // scale the found normalization factors
        double maxnf = Statistical.max(normalization_factors);
        for (int sampleid = 0; sampleid < nrmeasurements; ++sampleid)
            normalization_factors[sampleid] /= maxnf;

        // write the selection if needed
        if (options.selection != null) {
            if (options.verbose)
                System.out.println("Writing original selection data");

            PeakMLWriter.write(result.header, selection, null,
                    new GZIPOutputStream(new FileOutputStream(options.selection)), null);
        }

        // normalize all the peaks
        if (options.verbose)
            System.out.println("Normalizing all the entries");
        for (IPeakSet<? extends IPeak> peakset : peaksets) {
            for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) {
                // TODO why did I do this again ?
                int id = 0;
                int setid = 0;
                int spectrumid = 0;
                for (int i = 0; i < header.getNrSetInfos(); ++i) {
                    SetInfo set = header.getSetInfos().get(i);

                    if (id + set.getNrMeasurementIDs() > measurementid) {
                        setid = i;
                        spectrumid = measurementid - id;
                        break;
                    } else
                        id += set.getNrMeasurementIDs();
                }

                MassChromatogram<Peak> masschromatogram = null;
                for (IPeak p : peakset) {
                    int mymeasurementid = p.getMeasurementID();
                    int mysetid = header.indexOfSetInfo(header.getSetInfoForMeasurementID(mymeasurementid));
                    if (mysetid == setid && mymeasurementid == spectrumid) {
                        masschromatogram = (MassChromatogram<Peak>) p;
                        break;
                    }
                }
                if (masschromatogram == null)
                    continue;

                for (IPeak peak : masschromatogram.getPeaks())
                    peak.setIntensity(peak.getIntensity() / normalization_factors[measurementid]);
            }
        }

        // write the selection if needed
        if (options.selection_normalized != null) {
            if (options.verbose)
                System.out.println("Writing the normalized selection data");

            PeakMLWriter.write(result.header, selection, null,
                    new GZIPOutputStream(new FileOutputStream(options.selection_normalized)), null);
        }

        // write the factors if needed
        if (options.factors != null) {
            if (options.verbose)
                System.out.println("Writing the normalization factors");

            PrintStream out = new PrintStream(options.factors);
            for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid)
                out.println(header.getMeasurementInfo(measurementid).getLabel() + "\t"
                        + normalization_factors[measurementid]);
        }

        // write the plot if needed
        if (options.img != null) {
            if (options.verbose)
                System.out.println("Writing the graph");

            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            JFreeChart linechart = ChartFactory.createLineChart(null, "measurement", "normalization factor",
                    dataset, PlotOrientation.VERTICAL, false, // legend
                    false, // tooltips
                    false // urls
            );

            CategoryPlot plot = (CategoryPlot) linechart.getPlot();
            CategoryAxis axis = (CategoryAxis) plot.getDomainAxis();
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();

            renderer.setSeriesShapesFilled(0, true);
            renderer.setSeriesShapesVisible(0, true);

            linechart.setBackgroundPaint(Color.WHITE);
            linechart.setBorderVisible(false);
            linechart.setAntiAlias(true);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinesVisible(true);

            // create the datasets
            for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid)
                dataset.addValue(normalization_factors[measurementid], "",
                        header.getMeasurementInfo(measurementid).getLabel());
            JFreeChartTools.writeAsPDF(new FileOutputStream(options.img), linechart, 800, 500);
        }

        // write the normalized values
        if (options.verbose)
            System.out.println("Writing the normalized data");
        PeakMLWriter.write(result.header, peaksets.getPeaks(), null,
                new GZIPOutputStream(new FileOutputStream(options.output)), null);
    } catch (Exception e) {
        Tool.unexpectedError(e, application);
    }
}

From source file:org.bench4Q.console.ui.section.S_SPSSection.java

private JPanel printWIPSPic() throws IOException {
    double[][] value = sessionSmooth();
    for (int i = 0; i < value[0].length; ++i) {
        value[0][i] = i;//from  ww w .ja  v a2s .co m
        // value[1][i] = webInteractionThroughput[i];.
    }

    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    String series1 = "Basic";
    String series2 = "real";

    for (int i = 0; i < value[0].length; ++i) {
        defaultcategorydataset.addValue(value[1][i], series1, new Integer((int) value[0][i]));
        defaultcategorydataset.addValue(session[1][i], series2, new Integer((int) value[0][i]));
    }

    JFreeChart chart = ChartFactory.createLineChart("SPS = " + SPS, "time", "SPS", defaultcategorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.WHITE);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setShapesVisible(false);
    lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 1F, 1F }, 0.0F));
    lineandshaperenderer.setSeriesStroke(1,
            new BasicStroke(2.0F, 1, 0, 2.0F, new float[] { 1F, 10000F }, 0.0F));
    return new ChartPanel(chart);
}

From source file:Controlador.ControladorLecturas.java

public JInternalFrame graficoHumedadAmbiental() {
    DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
    for (Object row : vectorHumedadAmbiental()) {
        int porcentaje = Integer.parseInt(((Vector) row).elementAt(0).toString());
        String rowKey = "Sensor 1";
        String columnKey = ((Vector) row).elementAt(1).toString();
        defaultCategoryDataset.addValue(porcentaje, rowKey, columnKey);
    }//from w w w  .  j av  a 2 s  . co m
    JFreeChart jFreeChart = ChartFactory.createLineChart(null, "Hora", "Porcentaje Humedad",
            defaultCategoryDataset, PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    JInternalFrame jInternalFrame = new JInternalFrame("Grafico de Humedad Ambiental", true, true, true, true);
    jInternalFrame.add(chartPanel, BorderLayout.CENTER);
    jInternalFrame.pack();
    return jInternalFrame;
}

From source file:org.cyberoam.iview.charts.CustomDomainAxis.java

public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;/*from   w  w w.ja  va  2  s  .com*/
    //   DefaultCategoryDataset dataset=null;
    CustomCategoryDataset datasetCustom = null;

    try {
        ReportColumnBean reportColumnBeanX = null;
        ReportColumnBean reportColumnBeanY = null;
        ReportColumnBean reportColumnBeanZ = null;
        GraphBean graphBean = null;

        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBeanX.getDbColumnName();
        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBeanY.getDbColumnName();
        String zColumnDBname = null;

        datasetCustom = new CustomCategoryDataset();
        rsw.beforeFirst();
        String data = "";
        int count = -1;
        Boolean showLegend = false;
        if (graphBean.getZColumnId() == -1) {

            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), "", data);
            }

        } else {
            String zData;
            showLegend = true;
            reportColumnBeanZ = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                    graphBean.getZColumnId());
            zColumnDBname = reportColumnBeanZ.getDbColumnName();
            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                zData = rsw.getString(zColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), zData, data);
                count++;
            }

        }
        chart = ChartFactory.createLineChart("", // chart title
                "", // domain axis label
                "", // range axis label
                datasetCustom, // data
                PlotOrientation.VERTICAL, // orientation
                showLegend, // include legend
                true, // tooltips
                false // urls
        );
        LegendTitle legendTitle = chart.getLegend();
        if (legendTitle != null)
            legendTitle.setItemFont(new Font("Vandara", Font.BOLD, 11));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelInsets(new RectangleInsets(0, 0, 0, 5));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);
        CustomDomainAxis catAxis = new CustomDomainAxis();
        CustomDomainAxis.counter = 0;
        CustomDomainAxis.colCount = datasetCustom.getColumnCount();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setTickLabelInsets(new RectangleInsets(10, 15, 30, 10));
        catAxis.setAxisLineVisible(false);
        catAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(20 * Math.PI / 180));
        plot.setDomainAxis(catAxis);
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        if (count > 0) {
            Color[] colors = null;
            colors = new Color[5];
            colors[0] = new Color(24, 112, 176);
            colors[1] = new Color(168, 192, 232);
            colors[2] = new Color(248, 120, 8);
            colors[3] = new Color(248, 184, 120);
            colors[4] = new Color(152, 216, 136);
            for (int i = 0; i < count && i < colors.length; i++)
                renderer.setSeriesPaint(i, colors[i]);
        }
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("LineChart: " + e.getMessage(), e);
    }
    return chart;
}

From source file:org.usip.osp.graphs.GraphServer.java

public static JFreeChart getLineChart() {
    DefaultCategoryDataset cd = new DefaultCategoryDataset();

    cd.addValue(20, "Population Satisfaction", new Integer(1)); //$NON-NLS-1$
    cd.addValue(40, "Population Satisfaction", new Integer(2)); //$NON-NLS-1$
    cd.addValue(60, "Population Satisfaction", new Integer(3)); //$NON-NLS-1$
    cd.addValue(80, "Population Satisfaction", new Integer(4)); //$NON-NLS-1$

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Population Satisfaction", // chart title //$NON-NLS-1$
            "Game Round", // domain axis label //$NON-NLS-1$
            "Satisfaction Level", // range axis label //$NON-NLS-1$
            cd, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//  ww  w. j a  v  a 2 s. c  o m

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo1.java

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createLineChart(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  w w  .  j a va2  s  . c om*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false);
    plot.setRenderer(renderer);

    return chart;

}

From source file:org.yooreeka.util.gui.ScatterGui.java

public JFreeChart createLineChart(String[] items, LineChartData data1, LineChartData data2) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0, n = items.length; i < n; i++) {
        dataset.addValue(data1.getData()[i], data1.getLabel(), items[i]);
        dataset.addValue(data2.getData()[i], data2.getLabel(), items[i]);
    }/*from w w w .  j  ava 2s. c o  m*/
    //TODO: Externalize the hardcoded values
    final JFreeChart chart = ChartFactory.createLineChart(getTitle(), getXLabel(), getYLabel(), dataset,
            PlotOrientation.VERTICAL, true, // does it have a legend?
            true, // does it have tooltips?
            false); // does it have URLs?

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo5.java

/**
 * Creates a sample chart.// w  w w .j  a  va 2  s  .  c o m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] { -3, 3, -3 };
    ypoints = new int[] { -3, 0, 3 };
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] { -3, 3, 3 };
    ypoints = new int[] { 0, -3, 3 };
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDrawingSupplier(supplier);

    // set the stroke for each series...
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 6.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 2.0f, 6.0f }, 0.0f));

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.12);

    setCategorySummary(dataset);
    return chart;

}

From source file:org.yooreeka.util.gui.XyLogGui.java

/**
 * @param title// w w  w . j  a  v a  2  s.  c om
 *            chart title
 * @param nameForData1
 *            identifier for a data group/series
 * @param nameForData2
 *            identifier for a data group/series
 * @param items
 *            values/categories that correspond to data values
 */
public XyLogGui(String title, String nameForData1, String nameForData2, String[] items, double[] data1,
        double[] data2) {

    super(title);
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0, n = items.length; i < n; i++) {
        dataset.addValue(data1[i], nameForData1, items[i]);
        dataset.addValue(data2[i], nameForData2, items[i]);
    }

    final JFreeChart chart = ChartFactory.createLineChart("User Similarity", "Items", "Rating", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}