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

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

Introduction

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

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

From source file:net.sourceforge.processdash.ev.ui.chart.AbstractEVXYChart.java

protected void setPlotAxisLabels(XYPlot plot, String xLabel, String yLabel) {

    if (xLabel != null && xLabel.length() != 0)
        plot.getDomainAxis().setLabel(xLabel);

    if (yLabel != null && yLabel.length() != 0)
        plot.getRangeAxis().setLabel(yLabel);
}

From source file:DynamicDataDemo.java

/**
 * Creates a sample chart./*ww  w. java  2s.c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, String title, String xcoor, String ycoor) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(title, xcoor, ycoor, dataset, true, true,
            false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 500.0);
    return result;
}

From source file:com.experiments.DynamicDataDemo.java

/**
 * Creates a sample chart./*from   w  w  w.  java2 s .c  o m*/
 * 
 * @param dataset
 *            the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Dynamic Data Demo", "Time", "Value", dataset,
            true, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 200.0);
    axis.setVisible(false);
    return result;
}

From source file:com.okmich.twitanalysis.gui.ApplicationFrame.java

/**
 * Creates a sample chart.//from  www.  jav  a  2s .  co m
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Twitter Sentiments Analysis", "Time",
            "Sentiment score", dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 50.0);
    return result;
}

From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java

private void createChartPanel(JFreeChart chart) {
    chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override//from w w  w  .ja  v  a  2 s . c o  m
        public void chartMouseClicked(ChartMouseEvent arg0) {
            //ignore
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            ValueAxis yAxis = plot.getRangeAxis();
            double y = yAxis.java2DToValue(event.getTrigger().getY(), dataArea, RectangleEdge.LEFT);

            //Alternatively, obtain y for one of the subplots, which would be very neat.
            //We should find the "nearest" subplot to the cursor -- this is easy
            //double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x);
            xCrosshair.setValue(x);
            yCrosshair.setValue(y);
        }
    });

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    chartPanel.addOverlay(crosshairOverlay);

    chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
    setContentPane(chartPanel);
}

From source file:org.cyberoam.iview.charts.XYLine.java

/**
 * This method generates JFreeChart instance for XYLine chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from URL.
 * @return jfreechart instance with iView Customization.
 *///w ww.j a va  2 s  .  c  om
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        XYDataset dataset = null;
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries(reportBean.getTitle());
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        String xColumnName = reportColumnBean.getColumnName();
        //Wheather DataLink is Given For X Axis column
        if (reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        String yColumnName = reportColumnBean.getColumnName();
        //if DataLink is not Given For X Axis column then Check of Y Axis Column
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        String zColumnDbname = reportColumnBean.getDbColumnName();
        //Preparing DataSet
        String data = "";
        rsw.beforeFirst();
        while (rsw.next()) {
            data = rsw.getString(xColumnDBname);
            series.add(Long.parseLong((data).substring(data.length() - 2)),
                    new Long(rsw.getLong(yColumnDBname)).longValue());
        }
        seriesCollection.addSeries(series);

        dataset = seriesCollection;
        // create the chart...
        chart = ChartFactory.createXYLineChart("", // chart title
                "", // domain axis label
                "", seriesCollection, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         * Additional iView Customization.
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(new Color(245, 245, 245));
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setForegroundAlpha(0.7f);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);

        Axis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        domainAxis.setTickMarksVisible(false);
        domainAxis.setAxisLineVisible(false);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        renderer.setSeriesStroke(0, new BasicStroke(1));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return chart;
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

private void configurePlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(BLACK);/*  w ww  .ja v a  2  s.  co  m*/
    plot.getDomainAxis().setLabelPaint(WHITE);
    plot.getRangeAxis().setLabelPaint(WHITE);
    plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY);
    plot.getRangeAxis().setTickLabelPaint(LIGHT_GREY);
    plot.setDomainGridlinePaint(DARK_GREY);
    plot.setRangeGridlinePaint(DARK_GREY);
    plot.setOutlinePaint(DARK_GREY);
    plot.setRenderer(buildScatterRenderer(2, RED));
}

From source file:Modelos.Grafica.java

public JFreeChart crearGrafica(XYSeriesCollection dataset) {
    chart = ChartFactory.createXYLineChart("Sensores", "Tiempo", "Porcentaje", dataset,
            PlotOrientation.VERTICAL, true, // uso de leyenda
            false, // uso de tooltips  
            false // uso de urls
    );//  ww  w .  j av a 2  s . c o m
    // color de fondo de la grfica
    chart.setBackgroundPaint(COLOR_FONDO_GRAFICA);

    final XYPlot plot = (XYPlot) chart.getPlot();
    configurarPlot(plot);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    configurarRangeAxis(rangeAxis);

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    configurarRendered(renderer);

    return chart;
}

From source file:com.redhat.rhn.frontend.graphing.GraphGenerator.java

/**
 * Generate a JFreeChart class from specified parameters.
 *
 * @param height height in pixels of the image generated
 * @param width in pixels of the image generated
 * @param xAxisLabel label for the x axis
 * @param yAxisLabel label for the y axis
 * @param timeSeriesData List of TimeSeriesData[] DTO objects
 * @param labelMap a map containing the localized labels used
 *        for the metrics.  Contains simple "metricId" keys
 *        with the localized Strings as the value.  For example:
 *        labelMap={"pctfree" -> "Percent Free", "memused" -> "Memory Used"}
 * @return JFreeChart representation//from  w w  w. j  a  v  a 2  s  . com
 */
public JFreeChart generateJFReeChart(int height, int width, String xAxisLabel, String yAxisLabel,
        List timeSeriesData, Map labelMap) {

    if (Context.getCurrentContext() == null || Context.getCurrentContext().getTimezone() == null
            || Context.getCurrentContext().getLocale() == null) {
        throw new IllegalArgumentException(
                "Context, Timezone or Locale is " + "NULL in the Context.  Please make sure it has been set.");
    }

    XYDataset jfreeDataset = createDataset(timeSeriesData, labelMap);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            xAxisLabel, // x-axis label
            yAxisLabel, // y-axis label
            jfreeDataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    XYPlot plot = chart.getXYPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTimeZone(Context.getCurrentContext().getTimezone());

    return chart;
}

From source file:EspectroForm.java

private void removerYAxisLabels() {
    XYPlot plot = (XYPlot) spectroChart.getChart().getPlot();
    plot.getRangeAxis().setMinorTickMarksVisible(false);
    plot.getDomainAxis().setTickLabelsVisible(false);
}