Example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero.

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java

/**
 * Creates a new demo./*from w  w  w  .j a v a 2s.c om*/
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsPercentageInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"};
    /*for (String mode : aMode) {
     info.put(mode, new ArrayList());
     }*/
    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsPercentageInfoCollected" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ec.ui.view.MarginView.java

private JFreeChart createMarginViewChart() {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    XYPlot plot = result.getXYPlot();//from  ww  w. j a va  2  s  .c om
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    LinesThickness linesThickness = LinesThickness.Thin;

    XYLineAndShapeRenderer main = new LineRenderer();
    plot.setRenderer(MAIN_INDEX, main);

    XYDifferenceRenderer difference = new XYDifferenceRenderer();
    difference.setAutoPopulateSeriesPaint(false);
    difference.setAutoPopulateSeriesStroke(false);
    difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness));
    plot.setRenderer(DIFFERENCE_INDEX, difference);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}

From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java

/**
 * Creates a new demo./*  ww  w .java  2s .  c o m*/
 *
 * @param title the frame title.
 * @param pf
 */
public BestAgentsRoundInfoCollected(final String title, ArrayList<Double> pf) {

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    /*for (String mode : aMode) {
    info.put(mode, new ArrayList());
    }*/

    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);
    System.out.println("info" + info);
    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round of Best Agents " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("BestAgentsRound" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java

/**
 * Init ChartPanel Mouse Listener For MouseDraggedOverAxis event For scrolling X-Axis und zooming
 * Y-Axis0//  w w w  .j a v  a 2  s.  c  om
 */
private void initChartPanel(boolean stickyZeroForRangeAxis) {
    final EChartPanel chartPanel = this;

    // remove old init
    if (mouseAdapter != null) {
        this.removeMouseListener(mouseAdapter);
        this.removeMouseMotionListener(mouseAdapter);
        this.removeMouseWheelListener(mouseAdapter);
    }

    if (chartPanel.getChart().getPlot() instanceof XYPlot) {
        // set sticky zero
        if (stickyZeroForRangeAxis) {
            ValueAxis rangeAxis = chartPanel.getChart().getXYPlot().getRangeAxis();
            if (rangeAxis instanceof NumberAxis) {
                NumberAxis axis = (NumberAxis) rangeAxis;
                axis.setAutoRangeIncludesZero(true);
                axis.setAutoRange(true);
                axis.setAutoRangeStickyZero(true);
                axis.setRangeType(RangeType.POSITIVE);
            }
        }

        Plot p = getChart().getPlot();
        if (addZoomHistory && (p instanceof XYPlot)
                && !(p instanceof CombinedDomainXYPlot || p instanceof CombinedRangeXYPlot)) {
            // zoom history
            zoomHistory = new ZoomHistory(this, 20);

            // axis range changed listener for zooming and more
            ValueAxis rangeAxis = this.getChart().getXYPlot().getRangeAxis();
            ValueAxis domainAxis = this.getChart().getXYPlot().getDomainAxis();
            if (rangeAxis != null) {
                rangeAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {
                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR,
                            Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener)
                                l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
            if (domainAxis != null) {
                domainAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {
                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR,
                            Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener)
                                l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
        }

        // mouse adapter for scrolling and zooming
        mouseAdapter = new ChartGestureMouseAdapter();
        // mouseAdapter.addDebugHandler();
        this.addMouseListener(mouseAdapter);
        this.addMouseMotionListener(mouseAdapter);
        this.addMouseWheelListener(mouseAdapter);

        // add gestures
        if (standardGestures) {
            addStandardGestures();
        }
    }
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a residue plot./* w  w w . j a v a2 s.  c  o m*/
 * 
 * @param yValues
 * @param header
 * @param xAxis
 * @param yAxis
 * @param seriesNames
 * @return
 */
public JFreeChart createResiduePlot(List<Double[]> yValues, String header, String xAxis, String yAxis,
        List<String> seriesNames) {
    LinkedList<XYLineAnnotation> lines = new LinkedList<XYLineAnnotation>();
    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int j = 0; j < yValues.size(); j++) {
        XYSeries series = new XYSeries(seriesNames.get(j));
        for (int i = 0; i < yValues.get(j).length; i++) {
            series.add(i + 1, yValues.get(j)[i]);
            float dash[] = { 10.0f };
            BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    dash, 0.0f);
            XYLineAnnotation annotation = new XYLineAnnotation(i + 1, 0, i + 1, yValues.get(j)[i], stroke,
                    Color.BLUE);
            lines.add(annotation);
        }
        xyDataSet.addSeries(seriesNames.get(j), series.toArray());
    }
    JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, xyDataSet, PlotOrientation.VERTICAL,
            true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    for (int i = 0; i < lines.size(); i++) {
        plot.addAnnotation(lines.get(i));
    }
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
}

From source file:edu.ku.brc.specify.toycode.BugParse.java

/**
 * @param lines/*  w w  w.j  a va2  s.co  m*/
 */
protected void createChart(final List<String> lines, final String engineer) {

    int[] mins = new int[lines.size() - 1];
    for (int index = 1; index < lines.size(); index++) {
        String line = lines.get(index);
        String[] values = StringUtils.splitPreserveAllTokens(line, ",");
        int inx = 0;
        while (inx < values.length && values[inx].equals("0")) {
            inx++;
        }
        mins[index - 1] = inx < values.length ? inx : Integer.MAX_VALUE;
        System.err.println(mins[index - 1]);
    }

    int startInx = Integer.MAX_VALUE;
    for (int min : mins) {
        startInx = Math.min(startInx, min);
        System.out.println(min + "  " + startInx);
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String[] headers = StringUtils.split(lines.get(0), ",");
    int len = headers.length - startInx;
    System.out.println(headers.length + "  " + len);
    List<double[]> valArray = new Vector<double[]>();

    for (int i = 1; i < lines.size(); i++) {
        String[] values = StringUtils.splitPreserveAllTokens(lines.get(i), ",");
        double[] vals = new double[len];
        int inx = 0;
        double prev = -1;
        for (int j = startInx; j < headers.length; j++) {
            if (StringUtils.isNotEmpty(values[j])) {
                prev = Double.parseDouble(values[j]);
                vals[inx++] = prev;
            } else {
                vals[inx++] = 0.0;
            }
        }
        valArray.add(vals);
    }

    double[] vals = valArray.get(0);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Bugs", headers[i + startInx]);
    }
    vals = valArray.get(1);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Resolved", headers[i + startInx]);
    }

    vals = valArray.get(2);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Open", headers[i + startInx]);
    }

    JFreeChart chart = ChartFactory.createLineChart("Bugs - " + engineer, "Time", "Bugs", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //plot.setBackgroundPaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAxisLineVisible(true);

    CategoryAxis catAxis = plot.getDomainAxis();
    catAxis.setAxisLineVisible(true);
    catAxis.setTickMarksVisible(true);

    ChartFrame frame = new ChartFrame("", chart, false);
    frame.setBackground(Color.WHITE);
    frame.setSize(500, 500);
    frame.setVisible(true);
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.tasks.ChromatogramViewLoaderWorker.java

private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) {
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit));
    domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]");
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainZeroBaselineVisible(false);
    domainAxis.setAutoRange(true);/*from   ww w . jav a  2  s . co  m*/
    domainAxis.setAutoRangeIncludesZero(false);
    ((NumberAxis) plot.getRangeAxis()).setAutoRange(true);
    ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(true);
    Logger.getLogger(getClass().getName()).info("Adding chart");
    plot.setBackgroundPaint(Color.WHITE);
}

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);// w  w w  .j a  v  a2s .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:com.charts.FiveYearChart.java

public FiveYearChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);/*from  ww  w  . j  a va2s .  co  m*/
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:com.charts.MaxChart.java

public MaxChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);// w  w  w  .j  ava2s . c o m
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}