Example usage for org.jfree.data.xy XYIntervalSeries getKey

List of usage examples for org.jfree.data.xy XYIntervalSeries getKey

Introduction

In this page you can find the example usage for org.jfree.data.xy XYIntervalSeries getKey.

Prototype

public Comparable getKey() 

Source Link

Document

Returns the key for the series.

Usage

From source file:userinterface.graph.Histogram.java

/**
 * Exports our Histogram to a GNU plot readable file
 * /*from   ww w .j av a  2 s .co m*/
 * @param file The file to which the data has to be written
 * @throws IOException
 */
public void exportToGnuplot(File file) throws IOException {

    PrintWriter out = new PrintWriter(new FileWriter(file));

    //add some info for the users
    out.println("#=========================================");
    out.println("# Generated by PRISM Chart Package");
    out.println("#=========================================");
    out.println("# usage: gnuplot <filename>");
    out.println("# Written by Muhammad Omer Saeed <muhammad.omar555@gmail.com>");

    out.println();

    //set some properties
    out.println("set xtics rotate out");
    out.println("set auto x");
    out.println("set yrange " + "[0:" + getChart().getXYPlot().getRangeAxis().getRange().getUpperBound() * 1.2
            + "]");
    out.println("set style data histogram");
    out.println("set style fill solid border");
    out.println("set style histogram clustered");
    out.println("set boxwidth 3");

    synchronized (getSeriesLock()) {

        for (int i = 0; i < getChart().getXYPlot().getSeriesCount(); i++) {

            if (i == 0)
                out.print("plot '-' using 2:xticlabels(1)");
            else
                out.print(", '-' using 2:xticlabels(1)");
        }

        out.println();
        out.println();

        //write the histogram data
        for (int i = 0; i < getAllSeriesKeys().size(); i++) {

            XYIntervalSeries series = keyToSeries.get(getAllSeriesKeys().get(i));

            out.println("max   " + series.getKey());

            for (int j = 0; j < series.getItemCount(); j++) {

                XYIntervalDataItem item = (XYIntervalDataItem) series.getDataItem(j);

                double x = item.getXHighValue();
                x = x * 100;
                x = Math.round(x);
                x = x / 100;

                out.println(x + "   " + item.getYValue());

            }

            out.println("end series");
            out.println();
        }

    }

    //finishing up
    out.println();
    out.println("pause -1");

    out.flush();
    out.close();
}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartDistribution(boolean horizontal) {
    //        System.out.println("Min: " + minValue());
    //        System.out.println("Max: " + maxValue());
    XYIntervalSeriesCollection datasetDistribution = createIntervalXYDatasetDistribution(horizontal);
    XYSeriesCollection dataset2 = createXYDatasetGauss(horizontal);
    // create the chart...
    NumberAxis xAxis = new NumberAxis(getValueString());
    xAxis.setAutoRangeIncludesZero(false);
    //        NumberAxis yAxis = new NumberAxis("Distribution");
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true);
    //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer = new MyBarRenderer();
    XYPlot plot = new XYPlot(datasetDistribution, xAxis, yAxis, renderer);
    plot.setOrientation(horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    chart.setBackgroundPaint((Paint) UIManager.get("Panel.background"));
    //        plot.setBackgroundPaint(Color.white);
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    StandardXYItemLabelGenerator itemlabels = new StandardXYItemLabelGenerator();
    renderer.setBaseItemLabelGenerator(itemlabels);
    renderer.setBaseItemLabelsVisible(true);
    plot.setDataset(1, dataset2);/* w  w  w . ja  v a 2 s .com*/
    plot.mapDatasetToRangeAxis(1, 1);
    //        ValueAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(horizontal?CategoryLabelPositions.STANDARD:CategoryLabelPositions.UP_90);
    ValueAxis axis2 = new NumberAxis("Gaussian");
    plot.setRangeAxis(1, axis2);
    axis2.setVisible(false);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    //renderer2.setShapesVisible(false);
    //renderer2.setSeriesVisibleInLegend(false);
    renderer2.setBaseSeriesVisibleInLegend(false);
    //renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    renderer.setUseYInterval(true);
    renderer.setBaseSeriesVisibleInLegend(false);
    /* coloring */
    Color c;
    if (isMultipleCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            c = ChartCategories.getColor(i);
            for (int j = 0; j < datasetDistribution.getSeriesCount(); j++) {
                XYIntervalSeries s = datasetDistribution.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
                    renderer.setSeriesPaint(j, gp);
                }
            }
            for (int j = 0; j < dataset2.getSeriesCount(); j++) {
                XYSeries s = dataset2.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer2.setSeriesPaint(j, c);
                    renderer2.setSeriesShapesVisible(j, false);
                    renderer2.setSeriesStroke(j, myStroke);
                }
            }
        }
        c = Color.black;
    } else {
        c = ChartCategories.getColor(0);
        GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
        renderer.setSeriesPaint(0, gp);
    }
    renderer2.setSeriesPaint(0, c);
    renderer2.setSeriesShapesVisible(0, false);
    renderer2.setSeriesStroke(0, myStroke);

    placeLimitMarkers(plot, false);
    //        renderer.setAutoPopulateSeriesOutlinePaint(true);
    //        renderer.setBaseOutlinePaint(Color.black);
    //        renderer.setSeriesOutlinePaint(0, Color.black, true);
    //        renderer.setDrawBarOutline(true);

    renderer.setHighlightedItem(0, 0);
    yAxis.setAutoRange(false);
    yAxis.setAutoRange(true);
    xAxis.setRange(leftValue(0), rightValue(numberOfCategories - 1));
    chart.setTextAntiAlias(false);
    return chart;
}