Example usage for org.jfree.chart.plot XYPlot setDataset

List of usage examples for org.jfree.chart.plot XYPlot setDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDataset.

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

Sets a dataset for the plot and sends a change event to all registered listeners.

Usage

From source file:msi.gama.outputs.layers.ChartLayerStatement.java

public void updateseries(final IScope scope) throws GamaRuntimeException {
    // datas=dataswithoutlists;
    datasfromlists = new ArrayList<ChartData>();
    for (int dl = 0; dl < datalists.size(); dl++) {
        ChartDataList datalist = datalists.get(dl);

        Object val = datalist.valuelistexp.resolveAgainst(scope).value(scope);
        if (!(val instanceof GamaList)) {
            // GuiUtils.debug("chart list with no list...");
            return;
        }/*from w w w  .ja  v a  2 s  . co m*/
        List<List> values = Cast.asList(scope, val);
        if (datalist.doreverse) {
            List tempvalues = Cast.asList(scope, val);
            values = new ArrayList<List>();
            if (tempvalues.get(0) instanceof GamaList) {
                IList nval = Cast.asList(scope, tempvalues.get(0));
                for (int j = 0; j < nval.size(); j++) {
                    List nl = new ArrayList();
                    nl.add(nval.get(j));
                    values.add(nl);
                }
            } else {
                // GuiUtils.debug("Reverse series but not list of list..." + tempvalues);
                return;

            }
            if (tempvalues.size() > 1) {
                for (int i = 1; i < tempvalues.size(); i++) {
                    if (tempvalues.get(i) instanceof GamaList) {
                        IList nval = Cast.asList(scope, tempvalues.get(i));
                        for (int j = 0; j < nval.size(); j++) {
                            // Cast.asList(scope, values.get(j)).add(nval.get(j));

                            values.get(j).add(nval.get(j));

                        }
                    } else {
                        // GuiUtils.debug("Reverse series but not list of list..." + tempvalues);
                        return;

                    }
                }
            }

            // GuiUtils.debug("New Values"+values);
        }

        List defaultnames = new ArrayList<String>();
        List defaultcolors = new ArrayList<GamaColor>();
        for (int i = 0; i < values.size() + 1; i++) {
            defaultnames.add("data" + i);
            // defaultcolors.add(GamaColor.array[i]);
            if (i < 10) {

                if (i == 0) {
                    defaultcolors.add(Cast.asColor(scope, Color.CYAN));
                }
                if (i == 1) {
                    defaultcolors.add(Cast.asColor(scope, Color.RED));
                }
                if (i == 2) {
                    defaultcolors.add(Cast.asColor(scope, Color.YELLOW));
                }
                if (i == 3) {
                    defaultcolors.add(Cast.asColor(scope, Color.GREEN));
                }
                if (i == 4) {
                    defaultcolors.add(Cast.asColor(scope, Color.BLUE));
                }
                if (i == 5) {
                    defaultcolors.add(Cast.asColor(scope, Color.PINK));
                }
                if (i == 6) {
                    defaultcolors.add(Cast.asColor(scope, Color.MAGENTA));
                }
                if (i == 7) {
                    defaultcolors.add(Cast.asColor(scope, Color.ORANGE));
                }
                if (i == 8) {
                    defaultcolors.add(Cast.asColor(scope, Color.LIGHT_GRAY));
                }
                if (i == 9) {
                    defaultcolors.add(Cast.asColor(scope, Color.DARK_GRAY));
                }
            }
            if (i >= 10) {
                if (i < GamaColor.colors.size()) {
                    defaultcolors.add(GamaColor.int_colors.values()[i]);
                } else {
                    defaultcolors.add(GamaColor.getInt(Random.opRnd(scope, 10000)));
                }
            }

        }

        if (datalist.colorlistexp != null) {
            Object valcol = datalist.colorlistexp.resolveAgainst(scope).value(scope);
            if (valcol instanceof GamaList) {
                for (int c = 0; c < ((GamaList) valcol).size(); c++) {
                    // if ( type == SERIES_CHART)
                    // defaultcolors.set(c+1, Cast.asColor(scope, ((GamaList)valcol).get(c)));
                    // else
                    defaultcolors.set(c, Cast.asColor(scope, ((GamaList) valcol).get(c)));

                }

            }
        }

        boolean dynamicseriesnames = false;
        List<String> seriesnames = new ArrayList();

        if (datalist.legendlistexp != null) {
            Object valc = datalist.legendlistexp.resolveAgainst(scope).value(scope);

            if (valc instanceof GamaList) {
                dynamicseriesnames = true;
                seriesnames = (GamaList) valc;
                for (int i = 0; i < Math.min(values.size(), seriesnames.size()); i++) {
                    defaultnames.set(i, seriesnames.get(i) + "(" + i + ")");
                    if (type == SERIES_CHART && ((XYPlot) chart.getPlot()).getDataset(i + 1) != null) {
                        if (((DefaultTableXYDataset) ((XYPlot) chart.getPlot()).getDataset(i + 1))
                                .getSeriesCount() > 0) {
                            ((DefaultTableXYDataset) ((XYPlot) chart.getPlot()).getDataset(i + 1)).getSeries(0)
                                    .setKey(seriesnames.get(i) + "(" + i + ")");
                        }

                    }
                }
                if (values.size() > seriesnames.size()) {
                    for (int i = seriesnames.size(); i < values.size(); i++) {
                        defaultnames.set(i, "(" + i + ")");
                    }
                }
            } else {
                for (int i = values.size(); i < values.size(); i++) {
                    defaultnames.set(i, "(" + i + ")");
                }
            }
        }

        int nbseries = values.size();
        // if ( type==SERIES_CHART ) nbseries++;
        // ChartData first=datas.get(0);
        if (type == HISTOGRAM_CHART) {
            ((DefaultCategoryDataset) dataset).clear();
        }
        if (type == PIE_CHART) {
            ((DefaultPieDataset) dataset).clear();
        }
        if (nbseries > datalist.previoussize) {

            for (int i = datalist.previoussize; i < nbseries; i++) {
                AbstractRenderer r;
                try {
                    r = datalist.renderer.getClass().newInstance();
                    if (XYLineAndShapeRenderer.class.isAssignableFrom(r.getClass())) {
                        ((XYLineAndShapeRenderer) r).setBaseShapesFilled(
                                ((XYLineAndShapeRenderer) datalist.renderer).getBaseShapesFilled());
                        ((XYLineAndShapeRenderer) r).setBaseShapesVisible(
                                ((XYLineAndShapeRenderer) datalist.renderer).getBaseShapesVisible());
                        ((XYLineAndShapeRenderer) r).setSeriesLinesVisible(0,
                                ((XYLineAndShapeRenderer) datalist.renderer).getSeriesLinesVisible(0));
                    }
                    ChartData newdata;
                    newdata = ChartDataListStatement.newChartData(scope, r,
                            Cast.asString(scope, defaultnames.get(i)),
                            Cast.asColor(scope, defaultcolors.get(i)), values.get(i));

                    datas.add(newdata);
                    datasfromlists.add(newdata);

                    if (type == SERIES_CHART || type == XY_CHART || type == SCATTER_CHART) {
                        final XYPlot plot = (XYPlot) chart.getPlot();
                        final String legend = newdata.getName();
                        // if (dataset==null)
                        // dataset = new XYDataset();
                        if (type == SERIES_CHART || type == XY_CHART) {
                            dataset = new DefaultTableXYDataset();
                            final XYSeries serie = new XYSeries(legend, false, false);
                            ((DefaultTableXYDataset) dataset).addSeries(serie);

                        } else {
                            dataset = new XYSeriesCollection();
                            final XYSeries serie = new XYSeries(legend, false, true);
                            ((XYSeriesCollection) dataset).addSeries(serie);

                        }
                        expressions_index.put(legend, datas.size() - 1);
                        plot.setRenderer(datas.size() - 1, (XYItemRenderer) newdata.getRenderer(), false);
                        final Color c = newdata.getColor();
                        plot.getRenderer(datas.size() - 1).setSeriesPaint(0, c);
                        // if ((i>0)||(type==XY_CHART))
                        plot.setDataset(datas.size() - 1, (XYDataset) dataset);
                        history.append(legend);
                        history.append(',');
                    }

                    if (type == HISTOGRAM_CHART) {
                        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
                        int l = 0;
                        for (final ChartData e : datas) {
                            // String legend = e.getName();
                            // ((DefaultCategoryDataset) dataset).setValue(0d, new Integer(0), legend/* , legend
                            // */);

                            final String legend = e.getName();
                            if (!CategoryItemRenderer.class.isInstance(e.getRenderer())) {
                                e.renderer = new BarRenderer();
                            }
                            plot.setRenderer(l, (CategoryItemRenderer) e.getRenderer(), false);
                            final Color c = e.getColor();
                            plot.getRenderer(l).setSeriesPaint(0, c);
                            // plot.setDataset(i, (DefaultCategoryDataset) dataset);
                            // }
                            l++;
                            history.append(legend);
                            history.append(',');

                        }
                        if (history.length() > 0) {
                            history.deleteCharAt(history.length() - 1);
                        }
                        history.append(Strings.LN);
                        // plot.setDataset((DefaultCategoryDataset) dataset);

                    }
                    if (type == PIE_CHART) {
                        int l = 0;
                        // dataset = new DefaultPieDataset();
                        final PiePlot plot = (PiePlot) chart.getPlot();
                        for (final ChartData e : datas) {
                            final String legend = e.getName();
                            ((DefaultPieDataset) dataset).insertValue(l++, legend, null);
                            history.append(legend);
                            history.append(',');
                        }
                        if (history.length() > 0) {
                            history.deleteCharAt(history.length() - 1);
                        }
                        history.append(Strings.LN);
                        history.append(Strings.LN);
                        // plot.setDataset((DefaultPieDataset) dataset);
                        l = 0;
                        for (final ChartData e : datas) {
                            plot.setSectionPaint(l++, e.getColor());
                        }
                        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
                        if (exploded) {
                            for (final Object c : ((DefaultPieDataset) dataset).getKeys()) {
                                plot.setExplodePercent((Comparable) c, 0.20);
                            }
                        }
                    }

                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
            datalist.previoussize = nbseries;
        }

        boolean dynamiccategorynames = false;
        List<String> categorynames = new ArrayList<String>();
        /*
         * if (datalist.categlistexp!=null)
         * {
         * Object valc=datalist.categlistexp.resolveAgainst(scope).value(scope);
         * if ((valc instanceof GamaList))
         * {
         * dynamiccategorynames=true;
         * categorynames=(GamaList)valc;
         * }
         *
         * if (type==HISTOGRAM_CHART)
         * {
         * for ( int i=0; i<values.size(); i++ ) {
         * GamaList x = new GamaList();
         * Object obj = values.get(i);
         * if ( obj instanceof GamaList ) {
         * x = (GamaList) obj;
         * // clearvalues=true;
         * if (dynamiccategorynames)
         * {
         * for (int j=0;j<x.length(scope);j++)
         * if (j<categorynames.size())
         * {
         * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope,
         * x.get(j)).doubleValue(),(String)defaultnames.get(i),categorynames.get(j).toString()+"("+j+")");
         * }
         * else
         * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope,
         * x.get(j)).doubleValue(),(String)defaultnames.get(i),"("+j+")");
         * }
         * else
         * {
         * for (int j=0;j<x.length(scope);j++)
         * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope,
         * x.get(j)).doubleValue(),(String)defaultnames.get(i), new Integer(j));
         *
         * }
         * } else {
         * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope, obj).doubleValue(), new
         * Integer(0),(String)defaultnames.get(i));
         * }
         * }
         * }
         * }
         */
        if (chart.getLegend() == null) {
            chart.addLegend(new LegendTitle(chart.getPlot()));
        }
        // LegendTitle legend = chart.getLegend();
        // GuiUtils.debug("dyncateg:"+defaultnames);
        // GuiUtils.debug("legend:"+legend);
        for (int i = 0; i < nbseries; i++) {
            ChartData first = datas.get(i);
            if (type == SERIES_CHART) {
                first = datas.get(i + 1);
            }
            first.lastvalue = values.get(i);

        }

    }
}

From source file:org.matsim.counts.algorithms.graphs.CountsSimReal24Graph.java

@Override
public JFreeChart createChart(final int nbr) {

    XYSeriesCollection dataset0 = new XYSeriesCollection();
    XYSeries series = new XYSeries("MATSim volumes");
    // easier to use another dataset
    XYSeriesCollection dataset_outliers = new XYSeriesCollection();
    XYSeries series_outliers = new XYSeries("MATSim outliers");

    CustomXYURLGenerator url_gen = new CustomXYURLGenerator();
    CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator();

    final ArrayList<String> urls = new ArrayList<>();
    final ArrayList<String> tooltips = new ArrayList<>();
    List<Comp> comps = new Vector<>();

    //--------------------
    CountSimComparisonLinkFilter linkFilter = new CountSimComparisonLinkFilter(this.ccl_);

    final Vector<Id<Link>> linkIds = new CountSimComparisonLinkFilter(this.ccl_).getLinkIds();
    Iterator<Id<Link>> id_it = linkIds.iterator();

    double maxCountValue = 0.1;
    double maxSimValue = 0.1;
    // yyyy PtCountsKMLWriterTest.testPtAlightKMLCreation never touches these and then leads to an exception later
    // when they are zero.  Don't know why. kai, sep'16

    while (id_it.hasNext()) {
        Id<Link> id = id_it.next();

        double countVal = linkFilter.getAggregatedCountValue(id);
        double simVal = linkFilter.getAggregatedSimValue(id);

        if (countVal > 100.0 && simVal > 100.0) {

            if (countVal > maxCountValue)
                maxCountValue = countVal;
            if (simVal > maxSimValue)
                maxSimValue = simVal;/*from w  w  w  . jav  a2 s  .c  o  m*/

            series.add(countVal, simVal);
            comps.add(new Comp(countVal, "link" + id + ".html",
                    "Link " + id + "; " + "Count: " + countVal + ", Sim: " + simVal));
        } else {
            /* values with simVal<100.0 or countVal<100.0 are drawn on the x==100 or/and y==100-line
             */
            countVal = Math.max(100.0, countVal);
            simVal = Math.max(100.0, simVal);
            series_outliers.add(countVal, simVal);

            if (countVal > maxCountValue)
                maxCountValue = countVal;
            if (simVal > maxSimValue)
                maxSimValue = simVal;
        }
    } //while
    dataset0.addSeries(series);
    dataset_outliers.addSeries(series_outliers);

    Collections.sort(comps, new MyComparator());

    for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) {
        Comp cp = iter.next();
        urls.add(cp.getURL());
        tooltips.add(cp.getTooltip());
    }

    url_gen.addURLSeries(urls);
    tt_gen.addToolTipSeries(tooltips);

    String title = "Avg. Weekday Traffic Volumes, Iteration: " + this.iteration_;
    this.setChartTitle(title);
    this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes", // x axis label
            "Sim Volumes", // y axis label
            dataset0, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            true // urls
    );
    XYPlot plot = this.chart_.getXYPlot();
    final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/24h]");
    final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/24h]");
    axis_x.setAllowNegativesFlag(false);
    axis_y.setAllowNegativesFlag(false);

    //regular values
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setURLGenerator(url_gen);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesToolTipGenerator(0, tt_gen);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));

    //outliers
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setLinesVisible(false);
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    // error band
    DefaultXYDataset dataset1 = new DefaultXYDataset();
    Gbl.assertIf(maxCountValue > 0.);
    dataset1.addSeries("f1x", new double[][] { { 100.0, maxCountValue }, { 100.0, maxCountValue } });
    dataset1.addSeries("f2x", new double[][] { { 100.0, maxCountValue }, { 200.0, 2 * maxCountValue } });
    dataset1.addSeries("f05x", new double[][] { { 200.0, maxCountValue }, { 100.0, 0.5 * maxCountValue } });

    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer();
    renderer3.setShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.blue);
    renderer3.setSeriesPaint(1, Color.blue);
    renderer3.setSeriesPaint(2, Color.blue);
    renderer3.setBaseSeriesVisibleInLegend(false);
    renderer3.setSeriesItemLabelsVisible(0, true);
    renderer3.setSeriesItemLabelsVisible(1, false);
    renderer3.setSeriesItemLabelsVisible(2, false);

    XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", maxCountValue, 2 * maxCountValue);
    annotation0.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation0);
    XYTextAnnotation annotation1 = new XYTextAnnotation("count", maxCountValue, maxCountValue);
    annotation1.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation1);
    XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", maxCountValue, 0.5 * maxCountValue);
    annotation2.setFont(new Font("SansSerif", Font.BOLD, 11));
    plot.addAnnotation(annotation2);

    plot.setDomainAxis(axis_x);
    plot.setRangeAxis(axis_y);
    plot.setRenderer(0, renderer);

    plot.setRenderer(1, renderer2);
    plot.setDataset(1, dataset_outliers);

    plot.setRenderer(2, renderer3);
    plot.setDataset(2, dataset1);

    //plot.getRangeAxis().setRange(1.0, 19000.0);
    //plot.getDomainAxis().setRange(1.0, 19000.0);

    return this.chart_;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *//*w  w w  .j a v a2s. c o m*/
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotDataSetStrict(XYPlot plot, Plotable plotable, String id) throws ConvertException {
    String legend = shortLegend.get(id);
    List<Color> colorList = colorLists.get(id);
    List<Shape> shapeList = shapeLists.get(id);
    ColorAndShapeCreator creator = new ColorAndShapeCreator(plotable.getNumberOfCombinations());
    int index = 0;

    if (addInfoInLegend) {
        legend = longLegend.get(id);//from   w  w  w  .ja  va 2s .  c  om
    }

    if (colorList == null || colorList.isEmpty()) {
        colorList = creator.getColorList();
    }

    if (shapeList == null || shapeList.isEmpty()) {
        shapeList = creator.getShapeList();
    }

    for (Map<String, Integer> choiceMap : plotable.getAllChoices()) {
        double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY,
                choiceMap);

        if (dataPoints != null) {
            DefaultXYDataset dataSet = new DefaultXYDataset();
            XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true);
            String addLegend = "";

            for (String arg : choiceMap.keySet()) {
                if (!arg.equals(paramX)) {
                    addLegend += " (" + arg + "="
                            + plotable.getFunctionArguments().get(arg).get(choiceMap.get(arg)) + ")";
                }
            }

            dataSet.addSeries(legend + addLegend, dataPoints);
            dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            dataRenderer.setSeriesPaint(0, colorList.get(index));
            dataRenderer.setSeriesShape(0, shapeList.get(index));

            int i;

            if (plot.getDataset(0) == null) {
                i = 0;
            } else {
                i = plot.getDatasetCount();
            }

            plot.setDataset(i, dataSet);
            plot.setRenderer(i, dataRenderer);
        }

        index++;
    }
}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

@FXML
public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);// www. j  a  v a2  s.  c o m
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("Retention time (min)");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chartTitle.setText("Chromatogram");

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (ChromatogramPlotDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (ChromatogramPlotDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

/**
 * Erzeuge je einen Graphen fr die Sensoren Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from  w w  w .ja  va2 s . c om
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 02.08.2012
 * @param diveList
 * @param thePlot
 * @param sensor
 */
private void makePpoGraph(Vector<Integer[]> diveList, XYPlot thePlot, int sensor) {
    XYDataset ppo2DataSet;
    int indexForCreate;
    int posForGraph;
    int posColor;
    String title;
    //
    lg.debug("create Sensor <" + sensor + "> dataset");
    // Titel schon mal...
    title = String.format(LangStrings.getString("spx42LogGraphPanel.graph.ppo2SensorScalaTitle"), sensor);
    //
    // Dataset Index einstellen
    switch (sensor) {
    case 0:
        indexForCreate = LogDerbyDatabaseUtil.PPO2;
        posForGraph = GRAPH_PPO2ALL;
        posColor = ProjectConst.GRAPH_PPO2ALL_RCOLOR;
        title = LangStrings.getString("spx42LogGraphPanel.graph.ppo2ScalaTitle");
        break;
    case 1:
        indexForCreate = LogDerbyDatabaseUtil.PPO2_01;
        posForGraph = GRAPH_PPO2_01;
        posColor = ProjectConst.GRAPH_PPO2_01_RCOLOR;
        break;
    case 2:
        indexForCreate = LogDerbyDatabaseUtil.PPO2_02;
        posForGraph = GRAPH_PPO2_02;
        posColor = ProjectConst.GRAPH_PPO2_02_RCOLOR;
        break;
    case 3:
        indexForCreate = LogDerbyDatabaseUtil.PPO2_03;
        posForGraph = GRAPH_PPO2_03;
        posColor = ProjectConst.GRAPH_PPO2_02_RCOLOR;
        break;
    default:
        indexForCreate = LogDerbyDatabaseUtil.PPO2_01;
        posForGraph = GRAPH_PPO2_01;
        posColor = ProjectConst.GRAPH_PPO2_01_RCOLOR;
    }
    if (showingUnitSystem == savedUnitSystem || showingUnitSystem == ProjectConst.UNITS_DEFAULT) {
        ppo2DataSet = createXYDataset(title, diveList, ProjectConst.UNITS_DEFAULT, 0, indexForCreate);
    } else {
        ppo2DataSet = createXYDataset(title, diveList, showingUnitSystem, 0, indexForCreate);
    }
    final XYLineAndShapeRenderer ppo2Renderer = new XYLineAndShapeRenderer(true, true);
    // die Achse sollte schon erstellt sein
    thePlot.setDataset(posForGraph, ppo2DataSet);
    thePlot.mapDatasetToRangeAxis(posForGraph, GRAPH_PPO2ALL);
    ppo2Renderer.setSeriesPaint(0, new Color(posColor));
    ppo2Renderer.setSeriesShapesVisible(0, false);
    ppo2Renderer.setDrawSeriesLineAsPath(true);
    thePlot.setRenderer(posForGraph, ppo2Renderer);
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

protected JFreeChart createCharts(ChartPanel chartPanel, ChartDefinition cd) {
    List<DataSetValue> datasets = createDataSets(cd);
    int len = datasets.size();
    UIFont f = getAxisLabelFont(cd.getRangeAxis());
    UIFontMetrics fm = UIFontMetrics.getMetrics(f);

    tickSize = (int) fm.getHeight();

    if (cd.getChartType() == ChartType.PIE) {
        PiePlot plot;/*from   w w w.ja  v a2 s  .  c  o  m*/
        PieCollection pie = (PieCollection) datasets.get(0).dataset;

        if (cd.isDraw3D()) {
            plot = new PiePlot3D(pie);
        } else {
            plot = new PiePlot(pie);
        }

        customizePiePlot(cd, plot, pie);

        return new JFreeChart(null, getChartFont(), plot, false);
    }

    ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo();
    XYPlot xyplot = null;
    NumberAxis yAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getRangeLabel())
            : new NumberAxisEx(cd, false, cd.getRangeLabel());

    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRange(false);

    NumberAxis xAxis;

    if (ci.categoryDomain) {
        LabelData[] labels = ci.createLabelData(cd, fm, true);

        xAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getDomainLabel())
                : new NumberAxisEx(cd, labels, cd.getDomainLabel());
    } else {
        xAxis = cd.isDraw3D() ? new NumberAxis3DEx(cd, true, cd.getDomainLabel())
                : new NumberAxisEx(cd, true, cd.getDomainLabel());
    }

    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setAutoRange(false);
    xyplot = new XYPlotEx(null, xAxis, yAxis, null);

    for (int i = 0; i < len; i++) {
        DataSetValue dv = datasets.get(i);

        xyplot.setDataset(i, (XYDataset) dv.dataset);

        switch (dv.chartType) {
        case SPLINE:
            xyplot.setRenderer(i, new XYSplineRendererEx(ci.seriesData));

            break;

        case LINE:
            xyplot.setRenderer(i, cd.isDraw3D() ? new XYLine3DRendererEx(ci.seriesData)
                    : new XYLineAndShapeRendererEx(ci.seriesData));

            break;

        case BAR: {
            XYClusteredBarRendererEx renderer = new XYClusteredBarRendererEx(ci.seriesData);

            renderer.setShadowVisible(false);
            xyplot.setRenderer(i, renderer);
        }

            break;

        case STACKED_BAR: {
            StackedXYBarRenderer renderer = new XYStackedBarRendererEx(0.10, ci.seriesData);

            renderer.setDrawBarOutline(false);
            renderer.setShadowVisible(false);
            xyplot.setRenderer(i, renderer);
        }

            break;

        case RANGE_AREA:
            xyplot.setRenderer(i, new XYRangeAreaRendererEx(ci.seriesData));

            break;

        case RANGE_BAR:
            xyplot.setRenderer(i, new XYRangeBarRendererEx(ci.seriesData));

            break;

        case STACKED_AREA:
            XYStackedAreaRendererEx renderer = new XYStackedAreaRendererEx(ci.seriesData);

            renderer.setOutline(false);
            xyplot.setRenderer(i, renderer);

            break;

        case SPLINE_AREA:
        case AREA:
            XYItemRenderer r;

            if (dv.chartType == ChartType.SPLINE_AREA) {
                r = new XYAreaSplineRendererEx(ci.seriesData);
            } else {
                r = new XYAreaRendererEx(ci.seriesData);
            }

            xyplot.setRenderer(r);

            break;

        default:
            throw new InvalidParameterException("Unsupported chart type");
        }
    }

    customizeXYPlot(chartPanel, cd, xyplot);

    JFreeChart chart = new JFreeChart(null, getChartFont(), xyplot, false);

    return chart;
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotFunction(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape,
        double minX, double maxX) throws ConvertException {
    double[][] points = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX,
            maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }/*from   w ww  . ja va 2 s  . c o m*/

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (points != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < points[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(points[0][j], points[1][j], points[1][j] - error, points[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, points);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }
    }
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);//  w  w w. j  a v a2 s  .c o m
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (m/z) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("m/z");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (MsSpectrumDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (MsSpectrumDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });

}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java

public static XYDataset createLineDataset(DataItems dataitems1, DataItems dataitems2,
        Map<String, ArrayList<LinePos>> mapAB, XYPlot xyplot) {
    // ????/*  w w  w . j ava  2s .co m*/
    int modelcount = mapAB.keySet().size();
    long off1 = dataitems1.getElementAt(0).getTime().getTime();
    long off2 = dataitems2.getElementAt(0).getTime().getTime();
    long unit = 0;
    if (dataitems1.getLength() > 0) {
        unit = dataitems1.getElementAt(1).getTime().getTime() - off1;
    } else {
        unit = 3600000;
    }

    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    // ??

    int colorindex = 0;
    int renderercount = 2;
    for (Object se : mapAB.keySet()) {
        ArrayList<LinePos> s = mapAB.get(se);
        int oneModelCount = s.size();

        ArrayList<DataItems> dslist = new ArrayList<DataItems>();
        Iterator it = s.iterator();

        System.out.println("**************");
        System.out.println("?=" + se + ":=" + oneModelCount);

        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
        // ???
        xylineandshaperenderer.setBaseShapesVisible(false);
        // ??
        xylineandshaperenderer.setSeriesLinesVisible(0, true);
        // xylineandshaperenderer.setSeriesShape(0, double1); //?
        // 
        xylineandshaperenderer.setSeriesPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesFillPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesOutlinePaint(0, getcolor(colorindex % 9));
        colorindex++;
        xylineandshaperenderer.setUseFillPaint(true);
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());

        xylineandshaperenderer.setBaseShapesVisible(false);
        xylineandshaperenderer.setSeriesStroke(0,
                new BasicStroke(1.0F, 1, 1, 1.0F, new float[] { 15F, 12F }, 0.0F)); // 
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        xylineandshaperenderer.setBaseItemLabelsVisible(false);

        while (it.hasNext()) {
            LinePos temp = (LinePos) it.next();

            DataItem d1 = new DataItem();
            d1 = dataitems1.getElementAt(temp.A_start);
            DataItem d2 = new DataItem();
            d2 = dataitems2.getElementAt(temp.B_start);
            DataItems ds1 = new DataItems();
            ds1.add1Data(d1);
            ds1.add1Data(d2);
            // dslist.add(ds1);
            XYDataset xydataset1 = createmodeDataset(ds1, off1, se.toString() + ":" + 1, unit);

            DataItem d3 = new DataItem();
            d3 = dataitems1.getElementAt(temp.A_end);
            DataItem d4 = new DataItem();
            d4 = dataitems2.getElementAt(temp.B_end);
            DataItems ds2 = new DataItems();
            ds2.add1Data(d3);
            ds2.add1Data(d4);
            // dslist.add(ds2);
            XYDataset xydataset2 = createmodeDataset(ds2, off1, se.toString() + ":" + 2, unit);

            int datasetCount = xyplot.getDatasetCount();
            XYTextAnnotation localXYTextAnnotation = null;
            int modelx = (temp.A_start + temp.B_end) / 2;
            double modely = (Double.parseDouble(dataitems2.getElementAt(temp.A_start).getData())
                    + Double.parseDouble(dataitems1.getElementAt(temp.B_end).getData())) / 2;
            /*System.out.println("se=" + se + "::" + "x=" + modelx + "y="
                  + modely);*/
            localXYTextAnnotation = new XYTextAnnotation("" + se + ":" + oneModelCount, modelx, modely);
            xyplot.addAnnotation(localXYTextAnnotation);
            /*System.out.println("datasetCount=" + datasetCount);*/

            xyplot.setDataset(datasetCount, xydataset1);
            xyplot.setRenderer(datasetCount, xylineandshaperenderer);
            xyplot.setDataset(datasetCount + 1, xydataset2);
            xyplot.setRenderer(datasetCount + 1, xylineandshaperenderer);

        }

    }
    return xyseriescollection;
}