Example usage for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

Introduction

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

Prototype

public XYSeriesCollection(XYSeries series) 

Source Link

Document

Constructs a dataset and populates it with a single series.

Usage

From source file:org.optaplanner.benchmark.impl.statistic.bestsolutionmutation.BestSolutionMutationProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Best solution mutation count");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(true);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries series = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix());
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.isSuccess()) {
            BestSolutionMutationSingleStatistic singleStatistic = (BestSolutionMutationSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (BestSolutionMutationStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long mutationCount = point.getMutationCount();
                series.add(timeMillisSpent, mutationCount);
            }/*  ww  w. ja va2s  .c o  m*/
        }
        plot.setDataset(seriesIndex, new XYSeriesCollection(series));

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " best solution mutation statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "BestSolutionMutationStatistic");
}

From source file:net.relet.freimap.LinkInfo.java

public void setFlowProfile(LinkedList<FlowData> lp) {

    XYSeries packets = new XYSeries("packets");
    XYSeries bytes = new XYSeries("bytes");
    XYSeries icmp = new XYSeries("icmp");
    XYSeries tcp = new XYSeries("tcp");
    XYSeries udp = new XYSeries("udp");
    XYSeries other = new XYSeries("other");

    XYSeriesCollection data1 = new XYSeriesCollection(bytes);
    XYSeriesCollection data2 = new XYSeriesCollection(packets);
    XYSeriesCollection data3 = new XYSeriesCollection(icmp);
    data3.addSeries(tcp);//from  w  ww . j  av  a 2s .c  o m
    data3.addSeries(udp);
    data3.addSeries(other);

    //linkChart = ChartFactory.createXYLineChart("packets, bytes\r\nicmp, tcp, udp other", "time", "count", data1, PlotOrientation.VERTICAL, false, false, false);
    ValueAxis domain = new DateAxis();
    ValueAxis range1 = new NumberAxis();
    ValueAxis range2 = new NumberAxis();
    ValueAxis range3 = new NumberAxis();
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domain);
    plot.add(new XYPlot(data2, domain, range1, new XYLineAndShapeRenderer(true, false)));
    plot.add(new XYPlot(data1, domain, range2, new XYLineAndShapeRenderer(true, false)));
    plot.add(new XYPlot(data3, domain, range1, new XYLineAndShapeRenderer(true, false)));
    linkChart = new JFreeChart(plot);
    linkChart.setTitle("");
    sexupLayout(linkChart);

    long min = lp.getFirst().begin, max = lp.getLast().end;

    for (float i = 0.0f; i < 1000.0f; i += 1.0f) {
        long cur = min + (long) ((max - min) * (i / 1000.0));

        long cpackets = 0;
        long cbytes = 0;
        long cicmp = 0;
        long ctcp = 0;
        long cudp = 0;
        long cother = 0;

        Iterator<FlowData> li = lp.iterator();
        while (li.hasNext()) {
            FlowData data = li.next();
            if (data.begin > cur)
                break;
            if (data.end < cur)
                continue;
            cpackets += data.packets;
            cbytes += data.bytes;
            switch (data.protocol) {
            case 1: {
                cicmp += data.packets;
                break;
            }
            case 6: {
                ctcp += data.packets;
                break;
            }
            case 17: {
                cudp += data.packets;
                break;
            }
            default: {
                cother += data.packets;
                break;
            }
            }
        }

        packets.add(cur, cpackets);
        bytes.add(cur, cbytes);
        icmp.add(cur, cicmp);
        tcp.add(cur, ctcp);
        udp.add(cur, cudp);
        other.add(cur, cother);
    }

    status = STATUS_AVAILABLE;
}

From source file:com.wattzap.view.graphs.GenericScatterGraph.java

public void addLine(XYSeries series) {
    // add a second dataset and renderer...
    final XYItemRenderer renderer = new StandardXYItemRenderer() {
        //Stroke regularStroke = new BasicStroke(0.7f);
        public Color color;

        //@Override
        //public Stroke getItemStroke(int row, int column) {
        //return regularStroke;
        //}//from  w  w w. j a  v  a 2 s  .  c  o m

        @Override
        public Paint getItemPaint(int row, int column) {
            return color;
        }

        //public Shape lookupLegendShape(int series) {
        //   return new Rectangle(15, 15);
        //}
    };

    renderer.setBasePaint(Color.LIGHT_GRAY);
    plot.setRenderer(line, renderer);
    final IntervalXYDataset cadenceData = new XYSeriesCollection(series);
    plot.setDataset(line, cadenceData);
    line++;
}

From source file:com.att.aro.ui.view.diagnostictab.plot.CpuPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    XYSeries series = new XYSeries(0);
    if (analysis == null) {
        logger.info("didn't get analysis trace data!");
    } else {/*from   ww w .  j  a  v a  2  s.c  o m*/
        TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
        if (resultType.equals(TraceResultType.TRACE_FILE)) {
            logger.info("didn't get analysis trace folder!");

        } else {
            TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult()
                    .getTraceresult();

            cpuAList = traceresult.getCpuActivityList();
            boolean filterByTime = cpuAList.isFilterByTime();
            double beginTime = 0;
            double endTime = 0;
            if (filterByTime) {
                beginTime = cpuAList.getBeginTraceTime();
                endTime = cpuAList.getEndTraceTime();
            }

            cpuData = cpuAList.getCpuActivities();
            logger.debug("Size of CPU data: " + cpuData.size());

            if (cpuData.size() > 0) {
                for (CpuActivity cpu : cpuData) {
                    if (filterByTime) {
                        //                     logger.debug("timestamp: {0}" + cpu.getTimeStamp());
                        if (cpu.getTimeStamp() >= beginTime && cpu.getTimeStamp() <= endTime) {
                            //                        logger.debug("CPU usage: {0}"+ cpu.getCpuUsageTotalFiltered());
                            series.add(cpu.getTimeStamp(), cpu.getCpuUsageTotalFiltered());
                        }

                    } else {
                        //                     logger.debug("CPU usage: {0}"+ cpu.getCpuUsageTotalFiltered());
                        series.add(cpu.getTimeStamp(), cpu.getCpuUsageTotalFiltered());
                    }
                }
            }

            // Assign ToolTip to renderer
            XYItemRenderer renderer = plot.getRenderer();

            renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
                @Override
                public String generateToolTip(XYDataset dataset, int series, int item) {
                    return constructCpuToolTipText(cpuAList, cpuData, item);
                }
            });

        }
    }
    plot.setDataset(new XYSeriesCollection(series));
    //      return plot;
}

From source file:com.comcast.cmb.common.controller.EndpointServlet.java

private byte[] generateChart(EndpointMetrics metric, String id) throws IOException {

    XYSeries series = new XYSeries("Test Run");

    for (int i = 0; i < metric.timeSeries.size(); i++) {
        series.add(i, metric.timeSeries.get(i));
    }//from w w w  . j a v  a 2 s. co m

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createXYBarChart(
            "Start: " + metric.startTime + " End: " + metric.endTime + " Message Count: " + metric.messageCount,
            "Test Second", false, "Number of Messages", dataset, PlotOrientation.VERTICAL, true, true, false);

    //File file = new File(getServletContext().getRealPath("WEB-INF" + "/" + id + ".jpeg"));
    //ChartUtilities.saveChartAsJPEG(file, chart, 1600, 400);
    //byte b[] = Files.toByteArray(file);
    //return b;

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsJPEG(bos, chart, 2400, 400);
    return bos.toByteArray();
}