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:jfreeechart.DynamicDataDemo.java

/**
 * Creates a sample chart.//  ww  w  .  j  a  v a 2 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);
    return result;
}

From source file:old.MonitoringChart.java

private JFreeChart createChart(String title, final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(title, "Time", "Usage in %", dataset, true,
            true, false);/* w  w  w  .  j a va2  s.  co m*/
    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, 100.0);
    return result;
}

From source file:at.ac.tuwien.dsg.utility.DesignChart.java

public void chart(LinkedList<String> xValue, LinkedList<String> yValue) throws Exception {

    XYSeries series = new XYSeries("Sensory Data");
    final JFreeChart chart;

    //data assignment in the chart
    {/*from w  ww.  j  a  va  2  s .  c om*/
        for (int i = 0; i < xValue.size(); i++) {
            series.add(Double.parseDouble(xValue.get(i)), Double.parseDouble(yValue.get(i)));
        }

        final XYSeriesCollection data = new XYSeriesCollection(series);
        chart = ChartFactory.createXYLineChart("Graph Visualization", "collection_time", "collection_data",
                data, PlotOrientation.VERTICAL, true, true, false);
    }

    //design the plot of the chart
    {
        XYPlot xyPlot = chart.getXYPlot();
        NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
        NumberAxis yAxis = (NumberAxis) xyPlot.getRangeAxis();

        xAxis.setRange(20, 120);
        xAxis.setTickUnit(new NumberTickUnit(15));
        yAxis.setRange(947, 950);
        yAxis.setTickUnit(new NumberTickUnit(0.5));
    }

    //generation of the image  
    {
        try {

            BufferedImage img = chart.createBufferedImage(300, 200);
            //File outputfile = new File("./example/Sample.png");
            File outputfile = new File(
                    "/Users/dsg/Documents/phd/Big Demo/CloudLyra/Utils/JBPMEngine/example/Sample.png");
            ImageIO.write(img, "png", outputfile);

        } catch (Exception e) {
            System.out.println("exception occured in tomcat: " + e);
        }
    }

}

From source file:support.SystemMonitorGui.java

private void startGui() {
    XYSeries series = new XYSeries("Rate", false);
    XYPlot plot = createChartFrame(series);
    ValueAxis xAxis = plot.getDomainAxis();
    ValueAxis yAxis = plot.getRangeAxis();
    xAxis.setRange(0, TIME_RANGE);/* ww  w.  j av a  2 s.  c  om*/
    yAxis.setRange(Y_RANGE_MIN, Y_RANGE_UPPER_INITIAL);

    long initialTimestamp = System.currentTimeMillis();
    EntryAddedListener<Long, Double> entryAddedListener = event -> {
        long x = event.getKey() - initialTimestamp;
        double y = event.getValue() / SCALE_Y;
        EventQueue.invokeLater(() -> {
            series.add(x, y);
            xAxis.setRange(max(0, x - TIME_RANGE), max(TIME_RANGE, x));
            yAxis.setRange(Y_RANGE_MIN, max(series.getMaxY(), Y_RANGE_UPPER_INITIAL));
        });
        hzMap.remove(event.getKey());
    };
    entryListenerId = hzMap.addEntryListener(entryAddedListener, true);
}

From source file:graph.MySensorPanel.java

/**
 * Creates a new self-contained demo panel.
 *//* ww  w.  jav a2 s .  c  o m*/
public MySensorPanel(String header_str) {
    //super(new BorderLayout());
    this.series1 = new TimeSeries("Temperature");
    this.series2 = new TimeSeries("Humidity");
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(header_str, "Time", "C", dataset1, true, true,
            false);

    /*this.addChart(chart);*/

    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(1000.0 * 60 * 60 /* 24*/); // 24 hrs

    plot.setDataset(1, dataset2);
    NumberAxis rangeAxis2 = new NumberAxis("%");
    rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(1, new DefaultXYItemRenderer());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    ChartUtilities.applyCurrentTheme(chart);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    chartPanel = new ChartPanel(chart);
}

From source file:vincent.DynamicDataDemo.java

/**
 * Creates a sample chart.//from  w w w  .j a  va 2s  .c o  m
 * 
 * @param dataset the dataset.
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("", "Temps", "Temprature", 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(10.0, 50.0);// 50C
    return result;
}

From source file:org.jfree.chart.demo.XYBarChartDemo4.java

/**
 * Constructs the demo application.//  w w  w  .  j a va 2 s  . com
 *
 * @param title  the frame title.
 */
public XYBarChartDemo4(final String title) {

    super(title);

    final IntervalXYDataset dataset = createDataset();

    final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", false, "Y", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:cgpanalyser.gui.chart.ChartCreator.java

private void setBothAxisProperties(XYPlot plot, XYDataset dataset) {
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); //set x axis tick
    xAxis.setVerticalTickLabels(true); //set x axis text rotation
    //xAxis.setTickUnit(new NumberTickUnit(100));
    //xAxis.setLowerBound(1); 
    //xAxis.setUpperBound(1000);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    //yAxis.setTickUnit(new NumberTickUnit(100));
}

From source file:erigo.filewatch.DisplayPlot.java

/**
  * Creates a new plot.//from  w ww .j  a  v  a  2 s .  c  om
  *
  * @param chartTitleI   Chart title
  * @param xaxisLabelI   Label for x-axis
  * @param yaxisLabelI   Label for y-axis
  * @param xDataI      x-axis data
  * @param yDataI      y-axis data
  * @param xLocI         x-pos of lower left corner of the JFrame
  * @param yLocI         y-pos of lower left corner of the JFrame
  */
public DisplayPlot(String chartTitleI, String xaxisLabelI, String yaxisLabelI, List<Double> xDataI,
        List<Double> yDataI, int xLocI, int yLocI) {
    super("FileWatch data");
    chartTitle = chartTitleI;
    xaxisLabel = xaxisLabelI;
    yaxisLabel = yaxisLabelI;
    xData = xDataI;
    yData = yDataI;

    // Create dataset
    XYDataset dataset = createDataset();

    // Create chart
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xaxisLabel, yaxisLabel, dataset,
            PlotOrientation.VERTICAL, false, // no legend
            true, false);

    // Don't have any lower or upper margin; I think this will set the ends of the data
    // right up against the lower and upper edges of the plot
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // Create Panel
    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
    setSize(800, 400);
    // setLocationRelativeTo(null);  // to place in center of screen; not good if there are multiple plots
    setLocation(xLocI, yLocI);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

}

From source file:org.jfree.chart.demo.SerializationTest1.java

/**
 * Creates a sample chart./*  w ww. j  a  v  a2  s .  co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Serialization Test 1", "Time", "Value",
            dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    return result;
}