Example usage for org.jfree.chart JFreeChart removeLegend

List of usage examples for org.jfree.chart JFreeChart removeLegend

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart removeLegend.

Prototype

public void removeLegend() 

Source Link

Document

Removes the first legend in the chart and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:com.rapidminer.gui.plotter.charts.WebPlotter.java

@Override
public void updatePlotter() {
    final int categoryCount = prepareData();

    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from   www . j a  va2  s .c om*/
        public void run() {
            scrollablePlotterPanel.remove(viewScrollBar);
        }
    });

    if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                viewScrollBar.setOrientation(Adjustable.HORIZONTAL);
                scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH);
            }
        });

        this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT);
        viewScrollBar.setMaximum(categoryCount);
        viewScrollBar.setValue(0);

    } else {
        this.slidingCategoryDataSet = null;
    }

    if (categoryCount <= MAX_CATEGORIES) {

        SpiderWebPlot plot = new SpiderWebPlot(categoryDataSet);

        plot.setAxisLinePaint(Color.LIGHT_GRAY);
        plot.setOutlinePaint(Color.WHITE);

        plot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

        JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, true);

        double[] colorValues = null;
        if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) {
            colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)];
        } else {
            colorValues = new double[categoryDataSet.getColumnCount()];
        }
        for (int i = 0; i < colorValues.length; i++) {
            colorValues[i] = i;
        }

        if (panel != null) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            scrollablePlotterPanel.add(panel, BorderLayout.CENTER);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
        if (groupByColumn < 0) {
            // no legend is needed when there is no group-by selection
            chart.removeLegend();
        }
        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

From source file:edu.fullerton.viewerplugin.XYPlotter.java

private ChartPanel getPanel(double[][] data) throws WebUtilException {
    ChartPanel ret = null;// www.j  a  v  a 2s  .  c om
    try {
        XYSeries xys;
        XYSeriesCollection mtds = new XYSeriesCollection();
        String mylegend = legend == null || legend.isEmpty() ? "series 1" : legend;

        xys = new XYSeries(legend);

        int len = data.length;
        double minx = Double.MAX_VALUE;
        double maxx = Double.MIN_VALUE;
        double miny = Double.MAX_VALUE;
        double maxy = Double.MIN_VALUE;
        boolean gotZeroX = false;
        boolean gotZeroY = false;

        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            if (x == 0) {
                gotZeroX = true;
            } else {
                minx = Math.min(minx, x);
                maxx = Math.max(maxx, x);
            }
            if (y == 0) {
                gotZeroY = true;
            } else {
                miny = Math.min(miny, y);
                maxy = Math.max(maxy, y);
            }
        }
        // this kludge lets us plot a 0 on a log axis
        double fakeZeroX = 0.;
        double fakeZeroY = 0.;
        if (gotZeroX) {
            if (logXaxis) {
                fakeZeroX = minx / 10;
            } else {
                minx = Math.min(0, minx);
                maxx = Math.max(0, maxx);
            }
        }
        if (gotZeroY) {
            if (logYaxis) {
                fakeZeroY = miny / 10;
            } else {
                miny = Math.min(0, miny);
                maxy = Math.max(0, maxy);
            }
        }
        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            x = x == 0 ? fakeZeroX : x;
            y = y == 0 ? fakeZeroY : y;
            xys.add(x, y);
        }
        mtds.addSeries(xys);

        DefaultXYDataset ds = new DefaultXYDataset();

        int exp;
        if (maxy == 0. && miny == 0.) {
            miny = -1.;
            exp = 0;
            logYaxis = false;
        } else {

            maxy = maxy > miny ? maxy : miny * 10;
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
            if (!logYaxis && exp > 0) {
                yLabel += " x 1e-" + Integer.toString(exp);
            }
        }
        JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL,
                true, false, false);
        org.jfree.chart.plot.XYPlot plot = (org.jfree.chart.plot.XYPlot) chart.getPlot();
        if (logYaxis) {
            LogAxis rangeAxis = new LogAxis(yLabel);
            double smallest = miny * Math.pow(10, exp);
            rangeAxis.setSmallestValue(smallest);
            rangeAxis.setMinorTickCount(9);

            LogAxisNumberFormat lanf = new LogAxisNumberFormat();
            lanf.setExp(exp);
            rangeAxis.setNumberFormatOverride(lanf);
            rangeAxis.setRange(smallest, maxy * Math.pow(10, exp));
            plot.setRangeAxis(rangeAxis);
        }
        if (logXaxis) {
            LogAxis domainAxis = new LogAxis(xLabel);
            domainAxis.setMinorTickCount(9);
            domainAxis.setSmallestValue(minx);
            domainAxis.setNumberFormatOverride(new LogAxisNumberFormat());
            plot.setDomainAxis(domainAxis);
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        if (fmin != null && fmin > 0) {
            domainAxis.setLowerBound(fmin);
        }
        if (fmax != null && fmax > 0) {
            domainAxis.setUpperBound(fmax);
        }
        plot.setDomainAxis(domainAxis);
        plot.setDataset(0, mtds);

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (legend == null || legend.isEmpty()) {
            chart.removeLegend();
        }
        ret = new ChartPanel(chart);
    } catch (Exception ex) {
        throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage());
    }
    return ret;

}

From source file:windows.sensorWindow.java

/**
 * window constructor for chart window//from  ww  w .j av a2s  .c  om
 * 
 * @param title
 *            title for the new window
 */
public sensorWindow(final String title) {

    super(title);

    System.out.println("create sensorWindow");

    // font customizing
    // -------------------------------------------------------
    /*
     * Font font1 = null; try { font1 = Font.createFont(Font.TRUETYPE_FONT,
     * new File("U:/workspace/SWTtest/fonts/roboto/Roboto-Black.ttf")); }
     * catch (FontFormatException | IOException e1) { e1.printStackTrace();
     * } StandardChartTheme chartTheme = new
     * StandardChartTheme("robotTheme");
     * chartTheme.setExtraLargeFont(font1.deriveFont(24f));
     * chartTheme.setLargeFont(font1.deriveFont(16f));
     * chartTheme.setRegularFont(font1.deriveFont(12f));
     * chartTheme.setSmallFont(font1.deriveFont(10f));
     * ChartFactory.setChartTheme(chartTheme);
     */
    Font font1 = new Font("Tahoma", Font.BOLD, 16);
    Font font2 = new Font("Tahoma", Font.PLAIN, 12);
    Font font3 = new Font("Tahoma", Font.BOLD, 16);
    customFonts.put("axisLabelFont", font1);
    customFonts.put("axisValueFont", font2);
    customFonts.put("titleFont", font3);
    // -------------------------------------------------------------------------

    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    plot = new CombinedDomainXYPlot(new DateAxis("Time"));

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        Brick tmpBrick = connectionData.presentedBrickList.get(i);
        addPlot(tmpBrick);
    }

    final JFreeChart chart = new JFreeChart("", plot);
    // chart.setBorderPaint(Color.black);
    // chart.setBorderVisible(true);
    // chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setRenderer(renderer2);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(chartRangeSec * 1000); // chart range seconds
    axis.setLabelFont(customFonts.get("axisLabelFont"));
    axis.setTickLabelFont(customFonts.get("axisValueFont"));

    //final JPanel content = new JPanel(new BorderLayout());
    content = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane();
    JViewport viewport = scrollPane.getViewport();
    viewport.setView(content);

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel, BorderLayout.NORTH);
    // content.add(getScrollBar(xAxe), BorderLayout.SOUTH);

    // disable zoom
    chartPanel.setRangeZoomable(false);
    chartPanel.setDomainZoomable(false);

    // mouse selection
    chartPanel.addMouseListener(new MouseMarker(chartPanel));

    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    // chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    // setContentPane(content);

    // ===================================================
    // buttons
    buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < connectionData.presentedBrickList.size(); i++) {
        for (int i2 = 0; i2 < 2; i2++) {
            Brick tmpBrick = connectionData.presentedBrickList.get(i);
            JButton button = new JButton(tmpBrick.uid + " start");
            button.setActionCommand(buttonComAddBtn + tmpBrick.uid + i + "(" + i2 + ")");
            button.addActionListener(this);
            tmplButtons.put(tmpBrick.uid, button);
            // if ((tmpBrick.ctrlTmpl[0]) || (tmpBrick.ctrlTmpl[1]))
            // {
            // buttonPanel.add(button);
            // }
            changeTmplCntrl(tmpBrick, i2);
        }
    }
    content.add(buttonPanel, BorderLayout.SOUTH);
    // ===================================================

    // ===================================================
    // scroll bar
    final JPanel sliderPanel = new JPanel(new FlowLayout());

    slider = new JSlider(1, sliderValuesNumber);
    slider.setValue(sliderValuesNumber);
    slider.setEnabled(false);
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (sliderData.sliderActive == true) {
                int sliderValue = slider.getValue();
                if (sliderValue == sliderValuesNumber)
                    sliderUpdate = true;
                else
                    sliderUpdate = false;
                /*
                System.out.println("slider : " + sliderValue);
                System.out.println("Millis first: "
                      + sliderData.getMilliseconds(
                   sliderValue - sliderValuesNumber)
                   .toString());
                System.out.println("Millis last : "
                      + sliderData.getMilliseconds(sliderValue)
                   .toString());
                */
                DateRange range = new DateRange(
                        sliderData.getMilliseconds(sliderValue - sliderValuesNumber).getFirstMillisecond(),
                        sliderData.getMilliseconds(sliderValue).getFirstMillisecond());
                plot.getDomainAxis().setRange(range);
            }
        }
    });
    sliderPanel.add(slider);
    // chartPanel.add(slider);
    /*
     * final Panel chartPanel2 = new Panel(); chartPanel2.add(slider);
     * content.add(chartPanel2, BorderLayout.SOUTH);
     */
    content.add(sliderPanel, BorderLayout.CENTER);
    // ===================================================

    // ===================================================
    // scrolling
    /*
     * String[] data = {"one", "two", "three", "four", "five", "six",
     * "seven", "eight", "nine", "ten"}; JList list = new JList(data);
     * 
     * // give the list some scrollbars. // the horizontal (bottom)
     * scrollbar will only appear // when the screen is too wide. The
     * vertical // scrollbar is always present, but disabled if the // list
     * is small. JScrollPane jsp = new JScrollPane(list,
     * JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
     * JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     * 
     * // add the JScrollPane (not the list) to the window.
     * getContentPane().add(jsp, BorderLayout.CENTER);
     */
    // ==================================================

    setContentPane(content);

    this.addComponentListener(new java.awt.event.ComponentAdapter() {
        public void componentResized(java.awt.event.ComponentEvent e) {
            chartPanel.setMaximumDrawWidth((int) e.getComponent().getSize().getWidth());
            chartPanel.setMaximumDrawHeight((int) e.getComponent().getSize().getHeight());
            //chartPanel.setPreferredSize(e.getComponent().getPreferredSize());
            //chartPanel.setSize(e.getComponent().getSize());
            //chartPanel.setLocation(0,0); 
        }
    });

    // start auto update plot
    autoUpdatePlot();

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.out.println("close sensor window");
            functions.windowController.closeSensorWindow();
        }

    });
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void legendPositionChanged(LegendPosition legendPosition) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        LegendTitle legend = chart.getLegend();
        RectangleEdge position = legendPosition.getPosition();
        if (legend != null) {
            if (position != null) {
                legend.setPosition(position);
            } else {
                while (chart.getLegend() != null) {
                    chart.removeLegend();
                }//from w  ww  .jav  a2 s  .  c o m
            }
        } else {
            if (position != null) {
                resetLegend();
            }
        }
    }
}

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateGeometricMeanIntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session,
        PrintWriter pw) {/*from w ww .  j a  va2s  . co  m*/
    String gmfilename = "";

    JFreeChart gmChart = null;
    try {

        gmChart = ChartFactory.createBarChart(null, xAxisLabel, // domain axis label
                yAxisLabel, gmDataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
        gmChart.setBackgroundPaint(java.awt.Color.white);
        // lets start some customization to retro fit w/jcharts lookand feel
        CategoryPlot plot = gmChart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        axis.setLowerMargin(0.02); // two percent
        axis.setCategoryMargin(0.20); // 20 percent
        axis.setUpperMargin(0.02); // two percent
        //StatisticalBarRenderer renderer = new StatisticalBarRenderer();
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        // BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setItemMargin(0.01); // one percent
        renderer.setDrawBarOutline(true);
        renderer.setOutlinePaint(Color.BLACK);
        renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                String stdDev = (String) stdDevMap
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + "<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });

        plot.setRenderer(renderer);

        gmChart.removeLegend();
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        //gmfilename = ServletUtilities.saveChartAsPNG(gmChart, imgW, 400, info, session);
        gmfilename = ServletUtilities.saveChartAsPNG(gmChart, imgW, 400, info, session);
        ChartUtilities.writeImageMap(pw, gmfilename, info, new CustomOverlibToolTipTagFragmentGenerator(),
                new StandardURLTagFragmentGenerator());

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    return gmfilename;
}

From source file:whitebox.stats.Kriging.java

/**
 * Draw Semivariogram surface map and also draw the search are if
 * Anisotropic//from w  w  w .j  ava2  s .c om
 *
 * @param Radius
 * @param AnIsotropic
 */
public void DrawSemivariogramSurface(double Radius, boolean AnIsotropic) {
    double[][] data = new double[3][BinSurface.length * BinSurface[0].length];
    int n = 0;
    double max = Double.MIN_VALUE;
    for (int i = 0; i < BinSurface.length; i++) {
        for (int j = 0; j < BinSurface[i].length; j++) {
            data[0][n] = BinSurface[i][j].GridHorDistance;
            data[1][n] = BinSurface[i][j].GridVerDistance;
            if ((Math.pow(data[0][n], 2) + Math.pow(data[1][n], 2)) <= Radius * Radius
                    && !Double.isNaN(BinSurface[i][j].Value)) {
                data[2][n] = BinSurface[i][j].Value;
                if (max < data[2][n]) {
                    max = data[2][n];
                }
            } else {
                data[2][n] = -1;
            }
            n++;
        }
    }
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("Value", data);
    NumberAxis xAxis = new NumberAxis();

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(LagSize);
    renderer.setBlockHeight(LagSize);
    renderer.setBlockAnchor(RectangleAnchor.CENTER);

    LookupPaintScale paintScale = new LookupPaintScale(0, max, Color.white);
    double colorRange = max / 6;
    //double colorRange = 23013;
    paintScale.add(0.0, Color.blue);
    paintScale.add(1 * colorRange, Color.green);
    paintScale.add(2 * colorRange, Color.cyan);
    paintScale.add(3 * colorRange, Color.yellow);
    paintScale.add(4 * colorRange, Color.ORANGE);
    paintScale.add(5 * colorRange, Color.red);

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    if (AnIsotropic) {
        CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot();
        XYSeries seriesT1 = new XYSeries("1");
        XYSeriesCollection AngleCollct = new XYSeriesCollection();

        double bw = BandWidth;
        double r = bw / Math.sin(Tolerance);
        if (r > Radius) {
            bw = Radius * Math.sin(Tolerance);
            r = Radius;
        }
        seriesT1.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));

        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = 2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 + bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 + bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x2, y2);
                }
            } else {
                double x1 = -bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x1, y2);
                }
            }
        } else {
            double y1 = bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT1.add(x1, y1);
            } else {
                seriesT1.add(x2, y1);
            }
        }

        AngleCollct.addSeries(seriesT1);

        XYSeries seriesT2 = new XYSeries("2");
        seriesT2.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));
        seriesT2.add(0.0, 0.0);
        AngleCollct.addSeries(seriesT2);

        XYSeries seriesT3 = new XYSeries("3");
        seriesT3.add(Radius * Math.cos(Angle), Radius * Math.sin(Angle));
        seriesT3.add(0, 0);
        AngleCollct.addSeries(seriesT3);

        XYSeries seriesT4 = new XYSeries("4");
        seriesT4.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        seriesT4.add(0, 0);
        AngleCollct.addSeries(seriesT4);

        XYSeries seriesT5 = new XYSeries("5");

        seriesT5.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = -2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 - bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 - bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x2, y2);
                }
            } else {
                double x1 = bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x1, y2);
                }
            }
        } else {
            double y1 = -bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT5.add(x1, y1);
            } else {
                seriesT5.add(x2, y1);
            }
        }
        AngleCollct.addSeries(seriesT5);
        plot.setDataset(1, AngleCollct);
        XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false);
        for (int i = 0; i < AngleCollct.getSeriesCount(); i++) {
            //plot.getRenderer().setSeriesPaint(i , Color.BLUE);
            lineshapRend.setSeriesPaint(i, Color.BLACK);
        }
        plot.setRenderer(1, lineshapRend);
        combinedrangexyplot.add(plot);
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    JFreeChart chart = new JFreeChart("Semivariogram Surface", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // create and display a frame...
    ChartFrame frame = new ChartFrame("", chart);
    frame.pack();
    //frame.setSize(100, 50);
    frame.setVisible(true);
}

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateLog2Chart(String xAxisLabel, String yAxisLabel, HttpSession session, PrintWriter pw) {
    String log2Filename = "";

    JFreeChart log2Chart = null;
    try {/*  w w w  . ja v  a  2 s  . c  o  m*/

        log2Chart = ChartFactory.createBarChart(null, xAxisLabel, // domain axis label
                yAxisLabel, log2Dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
        log2Chart.setBackgroundPaint(java.awt.Color.white);
        // lets start some customization to retro fit w/jcharts lookand feel
        CategoryPlot plot = log2Chart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        axis.setLowerMargin(0.02); // two percent
        axis.setCategoryMargin(0.20); // 20 percent
        axis.setUpperMargin(0.02); // two percent
        StatisticalBarRenderer renderer = new StatisticalBarRenderer();

        // BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setItemMargin(0.01); // one percent
        renderer.setDrawBarOutline(true);
        renderer.setOutlinePaint(Color.BLACK);
        renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                String stdDev = (String) stdDevMap
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + "<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });

        // LegendTitle lg = chart.getLegend();
        plot.setRenderer(renderer);

        // lets generate a custom legend - assumes theres only one source?
        //LegendItemCollection lic = log2Chart.getLegend().getSources()[0].getLegendItems();
        //legendHtml = LegendCreator.buildLegend(lic, "Probesets");
        log2Chart.removeLegend();
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        log2Filename = ServletUtilities.saveChartAsPNG(log2Chart, imgW, 400, info, session);
        ChartUtilities.writeImageMap(pw, log2Filename, info, new CustomOverlibToolTipTagFragmentGenerator(),
                new StandardURLTagFragmentGenerator());

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    return log2Filename;
}

From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java

/** Create a scatter plot. */
@Override//from   www.jav a  2  s. c o m
public JFreeChart createChart() {
    JFreeChart chart;
    String xLabel = null, yLabel = null;
    if (!chromeless) {
        xLabel = Translator.translate(data.getColName(1));

        yLabel = getSetting("yLabel");
        if (yLabel == null && data.numCols() == 2)
            yLabel = data.getColName(2);
        if (yLabel == null)
            yLabel = getSetting("units");
        if (yLabel == null)
            yLabel = "Value";
        yLabel = Translator.translate(yLabel);
    }

    Object autoZero = parameters.get("autoZero");

    boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0
            && data.getData(1, 1) instanceof DateData;
    if (firstColumnContainsDate || parameters.get("xDate") != null) {
        chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true,
                false);
        if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                            DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
    } else {
        XYDataset src = data.xyDataSource();
        chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true,
                false);
        if (src instanceof XYToolTipGenerator) {
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
        }

        String trendLine = getParameter("trend");
        if ("none".equalsIgnoreCase(trendLine))
            ;
        else if ("average".equalsIgnoreCase(trendLine))
            addTrendLine(chart,
                    XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
        else
            addTrendLine(chart,
                    XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
    }

    if (autoZero != null) {
        if (!"x".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
        if (!"y".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
    }

    if (data.numCols() == 2)
        chart.removeLegend();

    return chart;
}

From source file:ru.spbspu.viewer.DataView.java

/**
 * ?     /*from  ww w  .j a v a  2 s  .  co  m*/
 */
public void buildFourierTransformGraph() {
    CategoryTableXYDataset serie = new CategoryTableXYDataset();
    serie.setNotify(false);
    double[] data = _presenter.getFourierTransform(getFramePosition(), getFrameWidth(), getWindowWidth());
    JFreeChart chart = null;
    String select = v.getSelection().getActionCommand();
    if (select.equalsIgnoreCase(vAcceleration.getActionCommand())) {
        for (int i = 0; i < data.length; i++) {
            serie.add(1.0 * i / getFrameWidth() * getDiscretization(), 2.0 * data[i], "");
        }
        chart = ChartFactory.createXYLineChart("", "", "g, /?^2", serie);
    } else if (select.equalsIgnoreCase(vDisplacement.getActionCommand())) {
        for (int i = 0; i < data.length; i++) {
            double freq = 1.0 * i / getFrameWidth() * getDiscretization();
            if (freq < 1.0) {
                continue;
            }
            double value = 2.0 * data[i] * Math.pow(10, 6) / Math.pow(freq, 2);

            serie.add(freq, value, "");
        }
        chart = ChartFactory.createXYLineChart("", "", "?, ", serie);
    } else
        return;

    chart.removeLegend();
    chart.setAntiAlias(false);

    XYPlot plot = chart.getXYPlot();
    //        org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis();
    //        
    //        org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis();
    //        yAxis.setRange(3.99, 4.01);
    ChartPanel chartPanel = new ChartPanel(chart);
    drawGraphOfEnergy(chartPanel);
}

From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java

public ArrayList<Integer> makePlot(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException {
    int imageId;/* w ww  . j a  v a2s.c o m*/
    try {
        PluginSupport psupport = new PluginSupport();
        String gtitle = psupport.getTitle(dbufs, compact);
        String xAxisLabel = "";
        XYSeriesCollection xyds = new XYSeriesCollection();
        TimeSeriesCollection mtds = new TimeSeriesCollection();

        compact = dbufs.size() > 2 ? false : compact;
        for (ChanDataBuffer dbuf : dbufs) {
            int npts = dbuf.getDataLength();
            int sum = 1;
            if (npts > 2000) {
                sum = npts / 2000;
            }
            String legend = psupport.getLegend(dbuf, compact);
            if (timeAxis.equalsIgnoreCase("utc")) {
                TimeSeries ts = psupport.getTimeSeries(dbuf, legend, sum);
                xAxisLabel = "Time (UTC)";
                mtds.addSeries(ts);
            } else {
                boolean isDt = timeAxis.equalsIgnoreCase("dt");
                XYSeries xys = psupport.addXySeries(dbuf, legend, isDt, sum);
                xAxisLabel = psupport.getxAxisLabel();
                xyds.addSeries(xys);
            }
        }
        Double minx, miny, maxx, maxy;
        Double[] rng = new Double[4];

        if (timeAxis.equalsIgnoreCase("utc")) {
            PluginSupport.getRangeLimits(mtds, rng);
        } else {
            int skip = 0;
            PluginSupport.getRangeLimits(xyds, rng, skip);
        }
        minx = rng[0];
        miny = rng[1];
        maxx = rng[2];
        maxy = rng[3];

        int exp;
        if (timeAxis.equalsIgnoreCase("utc")) {
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
        } else {
            exp = PluginSupport.scaleRange(xyds, miny, maxy);
        }

        ChartPanel cpnl;
        DefaultXYDataset ds = new DefaultXYDataset();
        JFreeChart chart;
        if (timeAxis.equalsIgnoreCase("utc")) {
            chart = ChartFactory.createTimeSeriesChart(gtitle, "Time (UTC)", "Counts", ds, true, true, false);
        } else {
            chart = ChartFactory.createXYLineChart(gtitle, xAxisLabel, "Counts", ds, PlotOrientation.VERTICAL,
                    true, false, false);
        }
        chart.setBackgroundPaint(Color.WHITE);
        chart.setAntiAlias(true);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        NumberAxis rangeAxis = new NumberAxis("Counts");
        ScaledAxisNumberFormat sanf = new ScaledAxisNumberFormat();
        sanf.setExp(exp);
        NumberTickUnit tickUnit;
        double plotRange;
        if (maxy != 0 && Math.abs(maxy - miny) < Math.abs(maxy) * 1e-30) {
            // this garbage is to get jFreeChart to always put labels on the Y axis
            double dt = Math.abs(miny) / 10;
            double scaledMin = (miny - dt) * Math.pow(10., exp);
            double scaledMax = (maxy + dt) * Math.pow(10., exp);
            rangeAxis.setRange(scaledMin, scaledMax);
            plotRange = scaledMax - scaledMin;
            rangeAxis.setAutoRange(false);
        } else {
            sanf.setMinMax(miny, maxy);
            plotRange = maxy - miny;
            rangeAxis.setAutoRange(true);
        }
        tickUnit = rangeAxis.getTickUnit();
        double tickSize = tickUnit.getSize();
        int nticks = (int) ((plotRange) / tickSize);
        if (nticks > yTicks) {
            double newTickSize = plotRange / yTicks;
            rangeAxis.setTickUnit(new NumberTickUnit(newTickSize));
        }
        rangeAxis.setNumberFormatOverride(sanf);
        rangeAxis.setAutoRangeIncludesZero(false);
        plot.setRangeAxis(rangeAxis);

        if (timeAxis.equalsIgnoreCase("utc")) {
            plot.setDataset(0, mtds);

        } else {
            plot.setDataset(0, xyds);
        }

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (compact) {
            chart.removeLegend();
        }
        cpnl = new ChartPanel(chart);
        if (outFilename.isEmpty()) {
            imageId = psupport.saveImageAsPNG(cpnl);
        } else {
            imageId = 0;
            psupport.saveImageAsPdfFile(chart, outFilename);
        }

    } catch (SQLException | NoSuchAlgorithmException | IOException ex) {
        throw new WebUtilException(ex);
    }
    ArrayList<Integer> ret = new ArrayList<>();
    ret.add(imageId);
    return ret;
}