Example usage for org.jfree.chart.renderer.xy XYItemRenderer setSeriesPaint

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setSeriesPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYItemRenderer setSeriesPaint.

Prototype

public void setSeriesPaint(int series, Paint paint);

Source Link

Document

Sets the paint used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:courseapplication.CourseApplication1.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    double[] xValues = data.getxValues();
    double[] yValues = data.getyValues();
    double step = 0.0001;
    double[] xValuesForGraph = prepareArray(xValues, step);
    double[] polinom = new double[xValuesForGraph.length];
    double[] lagr = new double[xValuesForGraph.length];
    XYSeries seriesFunction = new XYSeries("Function values");
    XYSeries seriesLagranje = new XYSeries("Lagranje values");
    XYSeries seriesPolinom = new XYSeries("Polinom values");
    double[] yValuesForGraph = new double[xValuesForGraph.length];

    for (int i = 0; i < yValuesForGraph.length; i++) {
        yValuesForGraph[i] = data.function(function, (xValuesForGraph[i]));
    }/*from ww w.  j a  v  a  2  s  . c o  m*/

    for (int i = 0; i < yValuesForGraph.length; i++) {
        polinom[i] = interpolation.polinomInterpolation(polinomResult, xValuesForGraph[i]);
        lagr[i] = interpolation.lagranjeInterpolation(xValues, yValues, xValuesForGraph[i]);
    }

    for (int i = 0; i < xValuesForGraph.length; i++) {
        seriesFunction.add(xValuesForGraph[i], yValuesForGraph[i]);
        seriesLagranje.add(xValuesForGraph[i], lagr[i]);
        seriesPolinom.add(xValuesForGraph[i], polinom[i]);

    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(seriesFunction);
    data.addSeries(seriesLagranje);
    data.addSeries(seriesPolinom);

    // XYDataset data = new XYSeriesCollection(seriesFunction);

    JFreeChart chart = ChartFactory.createXYLineChart("Function values and approximation functions", "X",
            "F(x)", data, PlotOrientation.VERTICAL, true, true, true);
    JFrame frameForGraphic = new JFrame("Graphic");
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.PINK);
    frameForGraphic.getContentPane().add(new ChartPanel(chart));
    frameForGraphic.show();
    frameForGraphic.setPreferredSize(new Dimension(800, 600));
    frameForGraphic.setLocationRelativeTo(null);
    frameForGraphic.pack();
}

From source file:nu.nethome.home.items.web.GraphServlet.java

/**
* This is the main enterence point of the class. This is called when a http request is
* routed to this servlet./*from  w ww . j ava2s  . co m*/
*/
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    ServletOutputStream p = res.getOutputStream();
    Date startTime = null;
    Date stopTime = null;

    // Analyse arguments
    String fileName = req.getParameter("file");
    if (fileName != null)
        fileName = getFullFileName(fromURL(fileName));
    String startTimeString = req.getParameter("start");
    String stopTimeString = req.getParameter("stop");
    try {
        if (startTimeString != null) {
            startTime = m_Format.parse(startTimeString);
        }
        if (stopTimeString != null) {
            stopTime = m_Format.parse(stopTimeString);
        }
    } catch (ParseException e1) {
        e1.printStackTrace();
    }
    String look = req.getParameter("look");
    if (look == null)
        look = "";

    TimeSeries timeSeries = new TimeSeries("Data", Minute.class);

    // Calculate time window
    Calendar cal = Calendar.getInstance();
    Date currentTime = cal.getTime();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    Date startOfDay = cal.getTime();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Date startOfWeek = cal.getTime();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Date startOfMonth = cal.getTime();
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    Date startOfYear = cal.getTime();

    // if (startTime == null) startTime = startOfWeek;
    if (stopTime == null)
        stopTime = currentTime;
    if (startTime == null)
        startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L);

    try {
        // Open the data file
        File logFile = new File(fileName);
        Scanner fileScanner = new Scanner(logFile);
        Long startTimeMs = startTime.getTime();
        Long month = 1000L * 60L * 60L * 24L * 30L;
        boolean doOptimize = true;
        boolean justOptimized = false;
        try {
            while (fileScanner.hasNext()) {
                try {
                    // Get next log entry
                    String line = fileScanner.nextLine();
                    if (line.length() > 21) {
                        // Adapt the time format
                        String minuteTime = line.substring(0, 16).replace('.', '-');
                        // Parse the time stamp
                        Minute min = Minute.parseMinute(minuteTime);

                        // Ok, this is an ugly optimization. If the current time position in the file
                        // is more than a month (30 days) ahead of the start of the time window, we
                        // quick read two weeks worth of data, assuming that there is 4 samples per hour.
                        // This may lead to scanning past start of window if there are holes in the data
                        // series.
                        if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) {
                            for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) {
                                fileScanner.nextLine();
                            }
                            justOptimized = true;
                            continue;
                        }
                        // Detect if we have scanned past the window start position just after an optimization scan.
                        // If this is the case it may be because of the optimization. In that case we have to switch 
                        // optimization off and start over.
                        if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) {
                            logFile = new File(fileName);
                            fileScanner = new Scanner(logFile);
                            doOptimize = false;
                            continue;
                        }
                        justOptimized = false;
                        // Check if value is within time window
                        if ((min.getFirstMillisecond() > startTimeMs)
                                && (min.getFirstMillisecond() < stopTime.getTime())) {
                            // Parse the value
                            double value = Double.parseDouble((line.substring(20)).replace(',', '.'));
                            // Add the entry
                            timeSeries.add(min, value);
                            doOptimize = false;
                        }
                    }
                } catch (SeriesException se) {
                    // Bad entry, for example due to duplicates at daylight saving time switch
                } catch (NumberFormatException nfe) {
                    // Bad number format in a line, try to continue
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        } finally {
            fileScanner.close();
        }
    } catch (FileNotFoundException f) {
        System.out.println(f.toString());
    }

    // Create a collection for plotting
    TimeSeriesCollection data = new TimeSeriesCollection();
    data.addSeries(timeSeries);

    JFreeChart chart;

    int xSize = 750;
    int ySize = 450;
    // Customize colors and look of the Graph.
    if (look.equals("mobtemp")) {
        // Look for the mobile GUI
        chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false);
        XYPlot plot = chart.getXYPlot();
        ValueAxis timeAxis = plot.getDomainAxis();
        timeAxis.setAxisLineVisible(false);
        ValueAxis valueAxis = plot.getRangeAxis(0);
        valueAxis.setAxisLineVisible(false);
        xSize = 175;
        ySize = 180;
    } else {
        // Create a Chart with time range as heading
        SimpleDateFormat localFormat = new SimpleDateFormat();
        String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime);
        chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false);

        Paint background = new Color(0x9D8140);
        chart.setBackgroundPaint(background);
        TextTitle title = chart.getTitle(); // fix title
        Font titleFont = title.getFont();
        titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0);
        title.setFont(titleFont);
        title.setPaint(Color.darkGray);
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(Color.darkGray);
        ValueAxis timeAxis = plot.getDomainAxis();
        timeAxis.setAxisLineVisible(false);
        ValueAxis valueAxis = plot.getRangeAxis(0);
        valueAxis.setAxisLineVisible(false);
        plot.setRangeGridlinePaint(Color.darkGray);
        XYItemRenderer renderer = plot.getRenderer(0);
        renderer.setSeriesPaint(0, Color.darkGray);
        xSize = 750;
        ySize = 450;
    }

    try {
        res.setContentType("image/png");
        res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "no-cache");
        res.setStatus(HttpServletResponse.SC_OK);
        ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }

    p.flush();
    p.close();
    return;
}

From source file:com.jbombardier.console.charts.XYTimeChartPanel.java

protected XYSeries getSeriesForSource(String label) {
    XYSeries xySeries;/*from  w  w  w  .j  a  va 2s.  c  o  m*/
    synchronized (seriesForSource) {
        xySeries = seriesForSource.get(label);
        if (xySeries == null) {
            xySeries = new XYSeries(label);
            int seriesIndex = xyseriescollection.getSeriesCount();
            xyseriescollection.addSeries(xySeries);

            xySeries.setMaximumItemCount(datapoints);
            seriesForSource.put(label, xySeries);

            if (lineFormatController != null) {
                Paint paint = lineFormatController.allocateColour(label);

                XYPlot xyPlot = chart.getXYPlot();
                XYItemRenderer xyir = xyPlot.getRenderer();
                xyir.setSeriesPaint(seriesIndex, paint);

                Stroke stroke = lineFormatController.getStroke(label);
                xyir.setSeriesStroke(seriesIndex, stroke);
            }
        }
    }
    return xySeries;
}

From source file:sanger.team16.gui.genevar.eqtl.gene.RegionalPlot.java

private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold,
        XYDataset dataset) {//from  w  ww.j  ava2s.c om
    JFreeChart chart = ChartFactory.createScatterPlot(null,
            "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.lightGray);
    //plot.setRangeCrosshairVisible(true);

    //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setRange(geneStart - distance, geneStart + distance);       
    //domainAxis.setUpperMargin(1000);
    //domainAxis.setLowerMargin(1000);

    //ValueAxis rangeAxis = plot.getRangeAxis();
    //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5);
    //rangeAxis.setLowerBound(0);

    XYItemRenderer renderer = plot.getRenderer();
    int size = dataset.getSeriesCount();
    for (int i = 0; i < size; i++) {
        //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4);
        //renderer.setSeriesPaint(i, new Color(255, scale, scale));

        renderer.setSeriesPaint(i, new Color(255, 0, 0));
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3));
        renderer.setBaseSeriesVisibleInLegend(false);
    }

    ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold));
    upperMarker.setPaint(Color.gray);
    //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);        
    //upperMarker.setLabel("-log10(10E-4)");
    //upperMarker.setLabelPaint(Color.red);
    //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    float[] f = { 4, 3, 4, 3 };
    upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f));
    plot.addRangeMarker(upperMarker);

    ValueMarker marker = new ValueMarker(0.0);
    marker.setPaint(Color.lightGray);
    plot.addRangeMarker(marker);

    XYSeries series = new XYSeries("Range");
    series.add(geneStart - distanceToTSS, -0.05);
    series.add(geneStart + distanceToTSS, -0.05);
    ((XYSeriesCollection) dataset).addSeries(series);
    renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false);

    return chart;
}

From source file:sanger.team16.gui.genevar.mqtl.gene.RegionalPlot.java

private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold,
        XYDataset dataset) {//ww  w  .j  ava2 s  .  c  om
    JFreeChart chart = ChartFactory.createScatterPlot(null,
            "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.lightGray);
    //plot.setRangeCrosshairVisible(true);

    //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setRange(geneStart - distance, geneStart + distance);       
    //domainAxis.setUpperMargin(1000);
    //domainAxis.setLowerMargin(1000);

    //ValueAxis rangeAxis = plot.getRangeAxis();
    //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5);
    //rangeAxis.setLowerBound(0);

    XYItemRenderer renderer = plot.getRenderer();
    int size = dataset.getSeriesCount();
    for (int i = 0; i < size; i++) {
        //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4);
        //renderer.setSeriesPaint(i, new Color(255, scale, scale));

        renderer.setSeriesPaint(i, new Color(50, 205, 50));
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3));
        renderer.setBaseSeriesVisibleInLegend(false);
    }

    ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold));
    upperMarker.setPaint(Color.gray);
    //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);        
    //upperMarker.setLabel("-log10(10E-4)");
    //upperMarker.setLabelPaint(Color.red);
    //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    float[] f = { 4, 3, 4, 3 };
    upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f));
    plot.addRangeMarker(upperMarker);

    ValueMarker marker = new ValueMarker(0.0);
    marker.setPaint(Color.lightGray);
    plot.addRangeMarker(marker);

    XYSeries series = new XYSeries("Range");
    series.add(geneStart - distanceToTSS, -0.05);
    series.add(geneStart + distanceToTSS, -0.05);
    ((XYSeriesCollection) dataset).addSeries(series);
    renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false);

    return chart;
}

From source file:playground.dgrether.linkanalysis.DgCountPerIterationGraph.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Iteration");
    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Trips");
    //      yAxis.setRange(-0.05, 0.3);
    //      xAxis.setVisible(false);
    //      xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);//from   w w  w  .j  a  v a 2 s.  c o  m
    plot.setRangeAxis(yAxis);

    plot.setDataset(0, this.dataset);

    DgColorScheme colorScheme = new DgColorScheme();
    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    for (int i = 0; i < this.dataset.getSeriesCount(); i++) {
        renderer2.setSeriesItemLabelsVisible(i, true);
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    //      renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    //      renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    //      renderer2.setSeriesOutlineStroke(1, new BasicStroke(3.0f));
    //      renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));

    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    //      chart.removeLegend();
    return chart;
}

From source file:com.att.aro.main.PacketPlots.java

/**
 * Creates the XYIntervalSeries for the uplink and downlink packets plot.
 * /*from  w ww .j a  va  2  s.  com*/
 * @param plot
 *            The XYPlot for the uplink/downlink plots.
 * @param dataset
 *            The uplink/downlink datasets.
 */
private void populatePacketPlot(XYPlot plot, LinkedHashMap<Color, PacketSeries> dataset) {

    // Create the XY data set
    YIntervalSeriesCollection coll = new YIntervalSeriesCollection();
    XYItemRenderer renderer = plot.getRenderer();
    for (PacketSeries series : dataset.values()) {
        coll.addSeries(series);

        renderer.setSeriesPaint(coll.indexOf(series.getKey()), series.getColor());
    }

    // Create tooltip generator
    renderer.setBaseToolTipGenerator(new PacketToolTipGenerator());

    plot.setDataset(coll);
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsQuantilesChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    xAxis.setRange(0.0, 102.0);//from  ww  w  .  j a v a  2 s .  com
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    yAxis.setRange(-0.05, 0.3);
    //      xAxis.setVisible(false);
    //      xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    //      renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    chart.removeLegend();
    return chart;
}

From source file:de.dfki.owlsmx.gui.ResultVisualization.java

private JFreeChart createMemoryChart() {
    XYSeriesCollection data = new XYSeriesCollection();
    Map memory = MemoryContainer.getInstance().getStoredValues();
    //       System.err.println("Memory consumption: " + memory);
    data.addSeries(createSeriesFromDataMap(memory));
    JFreeChart chart = ChartFactory.createXYLineChart("Memoryconsumption", "Services", "Memory (KByte)", data,
            org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();/*from   w w  w  . j  av a2  s .  c  o m*/
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.red);
    chart.removeLegend();
    return chart;
}

From source file:de.dfki.owlsmx.gui.ResultVisualization.java

private JFreeChart createAQRTChart() {
    XYSeriesCollection data = new XYSeriesCollection();
    Map passedTime = PassedTimeContainer.getInstance().getStoredValues();
    //       System.err.println("Passed time: " + passedTime);
    passedTime.put(new Integer(0), new Long(0));
    data.addSeries(createSeriesFromDataMap(passedTime));
    JFreeChart chart = ChartFactory.createXYLineChart("Average query response time", "Services", "Time (ms)",
            data, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();//  w  w  w. ja  v a 2 s.c  o  m
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.red);
    chart.removeLegend();
    return chart;
}