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

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

Introduction

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

Prototype

public void setDomainAxis(ValueAxis axis) 

Source Link

Document

Sets the domain axis for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:edu.ucla.stat.SOCR.chart.demo.XYAreaChartDemo2.java

/**
 * Creates a chart./*from ww w .  java 2 s.com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYAreaChart(chartTitle, "Time", "Value", dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, // legend
            true, // tool tips
            false // URLs
    );
    XYPlot plot = chart.getXYPlot();

    ValueAxis domainAxis = new DateAxis("Time");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("#,##0.00")));
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    // setXSummary(dataset);    X is time
    return chart;
}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java

private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) {
    NumberAxis domainAxis = null;/*from   w w  w . j av  a  2  s  . c  o m*/
    if (plot.getDomainAxis() == null) {
        domainAxis = new NumberAxis("log2 fold change");
        plot.setDomainAxis(domainAxis);
    } else {
        domainAxis = (NumberAxis) plot.getDomainAxis();
    }
    //        domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit));
    //        domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]");
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainZeroBaselineVisible(true);
    domainAxis.setAutoRange(true);
    domainAxis.setAutoRangeIncludesZero(false);
    NumberAxis rangeAxis = null;
    if (plot.getRangeAxis() == null) {
        rangeAxis = new NumberAxis("-log10 p-value");
        plot.setRangeAxis(rangeAxis);
    } else {
        rangeAxis = (NumberAxis) plot.getRangeAxis();
    }
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(true);
    Logger.getLogger(getClass().getName()).info("Adding chart");
    plot.setBackgroundPaint(Color.WHITE);
    ChartCustomizer.setSeriesColors(plot, 0.8f);
}

From source file:tdunnick.jphineas.console.queue.Charts.java

private JFreeChart createLineChart(String title, String constraint, XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, "Date/Time", // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//www  . j av  a 2 s .  com
    XYPlot plot = chart.getXYPlot();
    // X axis shows dates
    plot.setDomainAxis(new DateAxis());
    // if data has a constraint, hide every thing else
    if (constraint != null) {
        chart.removeLegend();
        XYDataset data = plot.getDataset();
        Paint bg = plot.getBackgroundPaint();
        for (int i = 0; i < data.getSeriesCount(); i++) {
            if (!constraint.equals(data.getSeriesKey(i)))
                plot.getRenderer().setSeriesPaint(i, bg);
            else {
                // get a color match...
                plot.getRenderer().setSeriesPaint(i, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]);
                // reset plot range for this maximum
                double d = 0;
                for (int j = 0; j < data.getItemCount(i); j++) {
                    if (d < data.getYValue(i, j))
                        d = data.getYValue(i, j);
                }
                // add a bit for top margin
                d += d * 0.04;
                plot.getRangeAxis().setUpperBound(d);
            }
        }
    }
    return chart;
}

From source file:org.easyrec.controller.StatisticsController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if (Security.isSignedIn(request)) {

        int tenant;
        int month;
        int year;
        boolean flot;

        String actionType = request.getParameter("actionType");
        try {/* w w  w  .j a  va  2  s  .  co m*/
            tenant = Integer.parseInt(request.getParameter("tenant"));
            month = Integer.parseInt(request.getParameter("month"));
            year = Integer.parseInt(request.getParameter("year"));
            flot = Integer.parseInt(request.getParameter("flot")) != 0;
        } catch (Exception e) {
            logger.warn(e);
            return null;
        }

        ModelAndView mav = new ModelAndView();
        XYSeriesCollection dataset = new XYSeriesCollection();
        FlotDataSet flotDataSet = new FlotDataSet();

        Calendar from = Calendar.getInstance();
        Calendar to = Calendar.getInstance();

        from.set(year, month, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0, 0);
        to.set(year, month, from.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);

        Integer actionTypeId = null;
        Integer assocTypeId = null;

        if (!Strings.isNullOrEmpty(actionType)) {
            if ("CLICKS_ON_RECS".equals(actionType))
                assocTypeId = 1001;
            else if ("CLICKS_ON_CHARTS".equals(actionType))
                assocTypeId = 998;
            else
                actionTypeId = typeMappingService.getIdOfActionType(tenant, actionType);
        }

        HashMap<Integer, HashMap<Integer, Integer>> actionBundleMap = statisticsDAO.getActionBundleMap(tenant,
                from.getTimeInMillis(), to.getTimeInMillis(), actionTypeId, assocTypeId);

        Iterator<Integer> iterator = actionBundleMap.keySet().iterator();

        while (iterator.hasNext()) {
            actionTypeId = iterator.next();
            if (actionTypeId == 1001)
                actionType = "clicks on recommendations";
            else if (actionTypeId == 998)
                actionType = "clicks on rankings";
            else
                actionType = typeMappingService.getActionTypeById(tenant, actionTypeId).toLowerCase()
                        + " actions";

            XYSeries xySeries = new XYSeries(actionType);
            FlotSeries flotSeries = new FlotSeries();
            flotSeries.setTitle(actionType);

            for (int i = 1; i <= 31; i++) {
                Integer y = actionBundleMap.get(actionTypeId).get(i);
                xySeries.add(i, y != null ? y : 0);
                flotSeries.add(i, y != null ? y : 0);
            }
            //mav.addObject("data",flotDataSet.toString());

            dataset.addSeries(xySeries);
            flotDataSet.add(flotSeries);
        }

        // create datapoints that are rendered in the clients browser
        // return array or html side that renders array
        if (flot) {
            boolean onlyData = (ServletUtils.getSafeParameter(request, "onlyData", 0) != 0);
            if (onlyData) {
                mav.setViewName("flot/dataOutput");
            } else {
                mav.setViewName("flot/flotPlot");
            }
            mav.addObject("data", flotDataSet.toString());
            mav.addObject("flotDataSet", flotDataSet.getData());
            mav.addObject("noActions", flotDataSet.getData().isEmpty());
            return mav;

            // create a png
        } else {
            JFreeChart action_chart = ChartFactory.createXYLineChart("", "actions", "days", dataset,
                    PlotOrientation.VERTICAL, true, // show legend
                    true, // show tooltips
                    false); // show urls

            XYPlot plot = action_chart.getXYPlot();

            ValueAxis axis = plot.getDomainAxis();
            axis.setRange(1, 31);
            plot.setDomainAxis(axis);

            BufferedImage bi = action_chart.createBufferedImage(300, 200);

            byte[] bytes = ChartUtilities.encodeAsPNG(bi);

            if (bytes != null & !flot) {
                OutputStream os = response.getOutputStream();
                response.setContentType("image/png");
                response.setContentLength(bytes.length);
                os.write(bytes);
                os.close();
            }
        }
        return null;

    } else {
        return Security.redirectHome(request, response);
    }

}

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

@Override
public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    xAxis.setRange(0.0, 102.0);/*ww w  .  ja v a  2 s  . c o  m*/
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    yAxis.setRange(-0.05, 0.3);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    plot.setDataset(0, this.dataset);
    for (int i = 0; i <= 3; i++) {
        renderer2.setSeriesStroke(i, new BasicStroke(2.0f));
        renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f));
        renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a"));
    }
    plot.setRenderer(0, renderer2);

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

From source file:de.xirp.chart.ChartManager.java

/**
 * Sets some values on the given//from  w  ww.j  a  v  a  2  s.c  o m
 * {@link org.jfree.chart.plot.XYPlot} corresponding to some
 * options of the {@link de.xirp.chart.ChartOptions}
 * field. <br>
 * <br>
 * If <code>options.is(OptionName.SHOW_THRESHOLD)</code> is
 * <code>true</code> a threshold line is painted to the chart
 * using the <code>threshold</code> field. <br>
 * <br>
 * If <code>options.is(OptionName.USE_RELATIVE)</code> is
 * <code>true</code> the date axis of the plot gets a title
 * indicating that relative values are used. If the flag is
 * <code>false</code> the plot gets a title indicating that
 * absolute values are used.
 * 
 * @param plot
 *            The plot to alter.
 * @param start
 *            The start time.
 * @see de.xirp.chart.ChartOptions
 * @see org.jfree.chart.plot.XYPlot
 */
private static void setXYPlot(XYPlot plot, Date start) {
    plot.setNoDataMessage(NO_DATA_AVAILABLE);

    if (options.is(OptionName.SHOW_THRESHOLD)) {
        Marker marker = new ValueMarker(threshold);
        marker.setPaint(Color.orange);
        marker.setAlpha(0.8f);
        plot.addRangeMarker(marker);
    }

    if (options.is(OptionName.USE_RELATIVE)) {
        DateAxis axis = new DateAxis(I18n.getString("ChartManager.text.relativeTime")); //$NON-NLS-1$
        RelativeDateFormat rdf = new RelativeDateFormat(start);
        axis.setDateFormatOverride(rdf);
        plot.setDomainAxis(axis);
    } else {
        plot.setDomainAxis(new DateAxis(I18n.getString("ChartManager.text.absoluteTime"))); //$NON-NLS-1$
    }
}

From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java

public HeadingNeuralNetworkTrainer() {
    outputGraphNetworkSeries = new XYSeries("Network Prediction");
    outputGraphDataSeries = new XYSeries("Error");
    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(outputGraphDataSeries);
    data.addSeries(outputGraphNetworkSeries);
    outputGraph = ChartFactory.createXYLineChart("Error vs. Output", "Time", "Error", data,
            PlotOrientation.VERTICAL, true, true, false);

    NumberAxis xAxis = new NumberAxis();
    xAxis.setRange(new Range(-Math.PI, Math.PI));
    xAxis.setAutoRange(false);//from  www.  java2s.c o  m
    NumberAxis yAxis = new NumberAxis();
    yAxis.setRange(new Range(-1, 1));

    XYPlot plot = (XYPlot) outputGraph.getPlot();
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    network = new Network(new int[] { 1, 5, 1 }, eta, momentum, new TransferFunction.HyperbolicTangent());

    try {
        SwingUtilities.invokeAndWait(() -> {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final Container content = frame.getContentPane();
            content.setLayout(new BorderLayout());

            outputGraphPanel = new ChartPanel(outputGraph);
            outputGraphPanel.setDomainZoomable(false);
            outputGraphPanel.setRangeZoomable(false);
            graphPanel.add(outputGraphPanel);

            graphPanel.setLayout(new GridLayout(1, 1));
            content.add(graphPanel, BorderLayout.CENTER);
            {

                JLabel etaLabel = new JLabel("Eta:");
                etaLabel.setLabelFor(etaField);
                etaField.setText(Double.toString(network.getEta()));
                etaField.setColumns(5);
                etaField.addPropertyChangeListener("value",
                        (evt) -> eta = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(etaLabel);
                controlPanel.add(etaField);

                JLabel momentumLabel = new JLabel("Momentum:");
                momentumLabel.setLabelFor(etaField);
                momentumField.setText(Double.toString(network.getMomentum()));
                momentumField.setColumns(5);
                momentumField.addPropertyChangeListener("value",
                        (evt) -> momentum = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(momentumLabel);
                controlPanel.add(momentumField);

                JLabel iterationsLabel = new JLabel("Iterations:");
                iterationsLabel.setLabelFor(iterationsField);
                iterationsField.setText(Integer.toString(iterations));
                iterationsField.setColumns(10);
                iterationsField.addPropertyChangeListener("value",
                        (evt) -> iterations = ((Number) evt.getNewValue()).intValue());
                controlPanel.add(iterationsLabel);
                controlPanel.add(iterationsField);
            }

            chooseDataButton.addActionListener((e) -> {
                if (dataDirectoryChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    dataDirectory = dataDirectoryChooser.getSelectedFile();
                    displayData();
                }
            });
            controlPanel.add(chooseDataButton);

            trainButton.addActionListener((e) -> trainNetwork());
            controlPanel.add(trainButton);

            saveButton.addActionListener((e) -> {
                saveNetwork();
            });
            controlPanel.add(saveButton);

            content.add(controlPanel, BorderLayout.SOUTH);

            dataDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        });
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*from  ww  w. j av a 2  s .  c  o  m*/
private JFreeChart getGraphic(String title, String legend, String modeName, int inputData[]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[];
    if (inputData.length > this.nofPictureBins) {
        data = Arrays.copyOfRange(inputData, 0, this.nofPictureBins);
    } else
        data = inputData;

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries(legend, false, true);

    for (int i = 0; i < data.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, data[i]);
    }

    xyData.addSeries(dataSerie);
    final JFreeChart chart = ChartFactory.createXYStepChart(title + ", " + modeName + ", it." + this.iteration,
            "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:net.nosleep.superanalyzer.analysis.views.GrowthView.java

private void createChart() {

    _chart = ChartFactory.createXYAreaChart(Misc.getString("LIBRARY_GROWTH"), Misc.getString("DATE"),
            Misc.getString("SONGS_IN_LIBRARY"), _dataset, PlotOrientation.VERTICAL, false, // legend
            true, // tool tips
            false // URLs
    );//w w  w. ja v a  2  s.  c  om
    XYPlot plot = (XYPlot) _chart.getPlot();
    plot.setDomainPannable(true);
    ValueAxis domainAxis = new DateAxis(Misc.getString("TIME"));
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.75f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("#,##0.00")));

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("LIBRARY_GROWTH_SUBTITLE")));

    ChartUtilities.applyCurrentTheme(_chart);
    Misc.formatChart(plot);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    renderer.setSeriesPaint(0, Theme.getColorSet()[1]);

}

From source file:playground.johannes.snowball.Histogram.java

public void plot(String filename, String title) throws IOException {
    fillBins();/*  w ww . j  av  a2 s.c  o  m*/
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    double min, max, width;
    //      int size;

    if (bounds != null) {
        min = bounds[0];
        max = bounds[1];
    } else {
        double minmax[] = getMinMax();
        min = minmax[0];
        max = minmax[1];
    }
    if (binWidth > 0) {
        //         size = (int)Math.ceil((max - min)/(double)binWidth);
        width = binWidth;
    } else {
        //         size = bincount;
        width = (max - min) / (double) bincount;
    }

    int cnt = bins.size();
    for (int i = 0; i < cnt; i++) {
        wave.add(i * width + min, bins.get(i));
    }

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}