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:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java

/**
 * sets up all charts for later usage//from ww  w. j  a v a2  s. c o m
 */
public void insertAllCharts() {
    for (int i = 0; i < MAXCHARTS; i++) {
        tsc[i] = new TimeSeriesCollection(new TimeSeries("unused", Millisecond.class));
        charts[i] = ChartFactory.createTimeSeriesChart("unused", null, "bitrate kbit/sec", tsc[i], false, true,
                false);

        XYPlot plot = charts[i].getXYPlot();
        ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        axis.setFixedAutoRange(DISPLAYEDTIME);
        axis = plot.getRangeAxis();
        axis.setRange(0.0, 128);
        ChartPanel chartPanel = new ChartPanel(charts[i]);

        // do the layout stuff
        GridBagConstraints c = new GridBagConstraints();
        c.weighty = 3;
        c.weightx = 10.0;
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(0, 0, 0, 0);
        c.gridx = 1;
        c.gridy = i;
        c.gridwidth = 1;
        c.gridheight = 1;
        gridBagLayout.setConstraints(chartPanel, c);

        // paste it
        content.add(chartPanel);
        chartPanel.setPreferredSize(new java.awt.Dimension(1000, 270));
    }
}

From source file:com.googlecode.logVisualizer.chart.LineChartBuilder.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setNoDataMessage("No data available");
    if (dataset.getSeriesCount() > 0)
        ((NumberAxis) plot.getDomainAxis()).setUpperBound(lastXValue);
    ((NumberAxis) plot.getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesStroke(i, new BasicStroke(2));
    }/*  ww w  . jav  a2 s .  c o m*/
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);

    return chart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createAgentsChart() {
    JFreeChart chart = ChartFactory.createXYLineChart("Alive Agents", // the title of the chart
            "Time Step", // the label for the X axis
            "Alive Agents", // the label for the Y axis
            model.agents_series_coll, // the dataset for the chart
            PlotOrientation.VERTICAL, // the orientation of the chart
            true, // a flag specifying whether or not a legend is required
            true, // a flag specifying whether or not tooltips should be generated
            false); // a flag specifying whether or not the chart should generate URLs

    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    //xAxis.setFixedDimension(50);
    //System.out.println("agents time series chart created");
    ValueAxis axis1 = plot.getRangeAxis();
    //axis1.setRange(0,1750);
    //StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(0);

    /*Color purple = new Color(140,0,164);
    renderer.setSeriesPaint(0,purple);/*from ww w. j a v a  2s.  c  o  m*/
            
    ((NumberAxis)axis1).setLabelPaint(purple);
    ((NumberAxis)axis1).setTickLabelPaint(purple);
            
    NumberAxis axis2 = new NumberAxis("Average Metabolic Rate");
            
    //axis2.setAutoRangeIncludesZero(false);
            
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection metab = new XYSeriesCollection(model.metabolism);
    plot.setDataset(1, metab);
            
    StandardXYItemRenderer rend2 = new StandardXYItemRenderer();
            
    //if (rend2 != null)
    rend2.setSeriesPaint(1, Color.BLACK);
    ((NumberAxis)axis2).setLabelPaint(Color.BLACK);
    ((NumberAxis)axis2).setTickLabelPaint(Color.BLACK);
            
    plot.setRenderer(1, rend2);
    plot.mapDatasetToRangeAxis(1, 1);
            
    NumberAxis axis3 = new NumberAxis("Age");
    plot.setRangeAxis(2, axis3);
    plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection ageXYSeries= new XYSeriesCollection(model.age);
    plot.setDataset(2, ageXYSeries);
    //ValueAxis yAgeAxis = plot.getRangeAxis();
            
    axis3.setRange(0,80);
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    StandardXYItemRenderer rend3 = new StandardXYItemRenderer();
    //if (rend2 != null)
    rend3.setSeriesPaint(2, Color.BLUE);
    plot.setRenderer(2, rend3);
    plot.mapDatasetToRangeAxis(2, 2);
            
    NumberAxis axis4 = new NumberAxis("Alive Agents");
    plot.setRangeAxis(3, axis4);
    axis4.setRange(0,1500);
    axis4.setLabelPaint(Color.BLACK);
    axis4.setTickLabelPaint(Color.BLACK);
    plot.setRangeAxisLocation(3, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection agentsXYSeries= new XYSeriesCollection(model.agents_series);
    plot.setDataset(3, agentsXYSeries);
    //ValueAxis yAgentsAxis = plot.getRangeAxis();
            
            
    StandardXYItemRenderer rend4 = new StandardXYItemRenderer();
    //if (rend2 != null)
    rend4.setSeriesPaint(3, Color.BLACK);
    plot.setRenderer(3, rend4);
    plot.mapDatasetToRangeAxis(3, 3);
            
    //}
    //System.out.println("done creating chart"); */
    return chart;
}

From source file:net.relet.freimap.LinkInfo.java

private void sexupPlot(Plot plot) {
    if (plot instanceof CombinedDomainXYPlot) {
        List<Plot> subs = (List<Plot>) (((CombinedDomainXYPlot) plot).getSubplots());
        Iterator<Plot> i = subs.iterator();
        while (i.hasNext()) {
            Plot p = i.next();/*from w  w w  .j a  v a2 s .co m*/
            sexupPlot(p);
        }
    } else if (plot instanceof XYPlot) {
        XYPlot xyplot = (XYPlot) plot;
        xyplot.setBackgroundPaint(VisorFrame.bgcolor2);
        xyplot.setDomainAxis(new DateAxis());
        sexupAxis(xyplot.getDomainAxis());
        sexupAxis(xyplot.getRangeAxis());
    }
}

From source file:slash.navigation.converter.gui.profileview.LazyToolTipChartPanel.java

protected String getTooltipAtPoint(Point point) {
    XYPlot plot = (XYPlot) getChart().getPlot();
    PlotRenderingInfo info = getChartRenderingInfo().getPlotInfo();
    double x0 = point.getX();
    double x1 = x0 - 2 * getScaleX();
    double x2 = x0 + 4 * getScaleX();

    ValueAxis domainAxis = plot.getDomainAxis();
    Rectangle2D screenArea = scale(info.getDataArea());
    double tx1 = domainAxis.java2DToValue(x1, screenArea, BOTTOM);
    double tx2 = domainAxis.java2DToValue(x2, screenArea, BOTTOM);

    for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {
        XYDataset dataset = plot.getDataset(datasetIndex);
        for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) {
            int itemCount = dataset.getItemCount(seriesIndex);
            for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) {
                double xValue = dataset.getXValue(seriesIndex, itemIndex);
                if (tx1 < xValue && xValue < tx2)
                    return toolTipGenerator.generateToolTip(dataset, seriesIndex, itemIndex);
            }// w w w . j  a  va2s.  co  m
        }
    }
    return null;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java

public void plotXTBalls(TrackDataHolder trackDataHolder) {
    int selectedIndexEpsilon = exploreTrackController.getExploreTrackPanel().getEnclosingBallEpsCombobox()
            .getSelectedIndex();/*from w  w  w .  ja v  a2 s . co m*/
    List<List<EnclosingBall>> xtEnclosingBallList = trackDataHolder.getStepCentricDataHolder()
            .getxTEnclosingBalls();
    List<EnclosingBall> xTempBalls = xtEnclosingBallList.get(selectedIndexEpsilon);
    // get the track coordinates matrix and transpose it
    Double[][] transpose2DArray = AnalysisUtils
            .transpose2DArray(trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix());
    // we get the x coordinates and the time information
    double[] xCoordinates = ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(transpose2DArray[0]));
    double[] timeIndexes = trackDataHolder.getStepCentricDataHolder().getTimeIndexes();
    // we create the series and set its key
    XYSeries xtSeries = JFreeChartUtils.generateXYSeries(timeIndexes, xCoordinates);
    String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well "
            + trackDataHolder.getTrack().getWellHasImagingType().getWell();
    xtSeries.setKey(seriesKey);
    // we then create the XYSeriesCollection and use it to make a new line chart
    XYSeriesCollection xtSeriesCollection = new XYSeriesCollection(xtSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "time", "x (m)",
            xtSeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis yaxis = (NumberAxis) xyPlot.getRangeAxis();
    yaxis.setAutoRangeIncludesZero(false);
    JFreeChartUtils.setupXYPlot(xyPlot);
    JFreeChartUtils.setupSingleTrackPlot(chart,
            exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true);
    xTBallsChartPanel.setChart(chart);
    xTempBalls.stream().forEach((ball) -> {
        xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(),
                GuiUtils.getDefaultColor()));
    });
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java

public void plotYTBalls(TrackDataHolder trackDataHolder) {
    int selectedIndexEpsilon = exploreTrackController.getExploreTrackPanel().getEnclosingBallEpsCombobox()
            .getSelectedIndex();/*from w  ww.  j  av a  2s  .c  om*/
    List<List<EnclosingBall>> ytEnclosingBallList = trackDataHolder.getStepCentricDataHolder()
            .getyTEnclosingBalls();
    List<EnclosingBall> yTempBalls = ytEnclosingBallList.get(selectedIndexEpsilon);
    // get the track coordinates matrix and transpose it
    Double[][] transpose2DArray = AnalysisUtils
            .transpose2DArray(trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix());
    // we get the y coordinates and the time information
    double[] yCoordinates = ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(transpose2DArray[1]));
    double[] timeIndexes = trackDataHolder.getStepCentricDataHolder().getTimeIndexes();
    // we create the series and set its key
    XYSeries ytSeries = JFreeChartUtils.generateXYSeries(timeIndexes, yCoordinates);
    String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well "
            + trackDataHolder.getTrack().getWellHasImagingType().getWell();
    ytSeries.setKey(seriesKey);
    // we then create the XYSeriesCollection and use it to make a new line chart
    XYSeriesCollection ytSeriesCollection = new XYSeriesCollection(ytSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "time", "y (m)",
            ytSeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis yaxis = (NumberAxis) xyPlot.getRangeAxis();
    yaxis.setAutoRangeIncludesZero(false);
    JFreeChartUtils.setupXYPlot(xyPlot);
    JFreeChartUtils.setupSingleTrackPlot(chart,
            exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true);
    yTBallsChartPanel.setChart(chart);
    yTempBalls.stream().forEach((ball) -> {
        xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(),
                GuiUtils.getDefaultColor()));
    });
}

From source file:au.edu.jcu.usb.USBPlotFrame.java

/**
 * Constructs the ChartPanel from the provided XYSeriesCollection
 *
 * @param xySeriesCollection/* w w w.ja  va2s  .c o  m*/
 * @return The constructed ChartPanel containing the XY scatter plot
 */
private ChartPanel constructChart(XYSeriesCollection xySeriesCollection) {
    // Construct the scatter plot from the provided xySeriesCollection
    JFreeChart chart = ChartFactory.createScatterPlot("Title", "X Axis", "Y Axis", xySeriesCollection);

    // Get the XY Plot from the scatter chart
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    // Create the renderer
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);

    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();

    domain.setVerticalTickLabels(true);

    ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

@Override
public void stateChanged(ChangeEvent e) {
    int value = this.slider.getValue();
    XYPlot plot = (XYPlot) this.getChart().getPlot();

    ValueAxis domainAxis = plot.getDomainAxis();
    Range range = domainAxis.getRange();
    double c = domainAxis.getLowerBound() + (value / 100.0) * range.getLength();

    // displays the vertical crosshair in the desired position
    plot.setDomainCrosshairValue(c);//from w w  w .  ja  va  2 s .co  m

    // the cross hair is keyed to the horizontal slider - for the time domain axis
    setCrossHairDomainIndex();
}

From source file:com.charts.FiveDayChart.java

public FiveDayChart(YStockQuote currentStock) {
    TimeSeries series = new TimeSeries(currentStock.get_name());
    ArrayList<String> fiveDayData = currentStock.get_five_day_data();
    int length = fiveDayData.size();
    for (int i = 22; i < length; i += 5) {
        String[] data = fiveDayData.get(i).split(",");
        Date time = new Date((long) Integer.parseInt(data[0]) * 1000);
        DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m");
        series.addOrUpdate(new Minute(time), Double.parseDouble(data[1]));
    }//  w  w w.  ja va  2 s  . c om
    String[] data = fiveDayData.get(length - 1).split(",");
    Date time = new Date((long) Integer.parseInt(data[0]) * 1000);
    DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m");
    series.addOrUpdate(new Minute(time), Double.parseDouble(data[1]));

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Five Day", "Date", "Price",
            dataset, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();

    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    Date now = new Date();
    SegmentedTimeline segmentedTimeline = SegmentedTimeline.newFifteenMinuteTimeline();
    segmentedTimeline.addBaseTimelineExclusions(segmentedTimeline.getStartTime(), now.getTime());
    Calendar[][] holidays = DayRange.getHolidayDates();
    for (int i = 0; i < holidays[0].length; i++) {
        Calendar day = Calendar.getInstance();
        day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR));
        day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH));
        day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH));
        day.set(Calendar.HOUR_OF_DAY, 9);
        segmentedTimeline.addException(day.getTimeInMillis(), day.getTimeInMillis() + 21600000);
    }
    xAxis.setTimeline(segmentedTimeline);
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    //xAxis.setVerticalTickLabels(true);
    xAxis.setDateFormatOverride(new SimpleDateFormat("MM-dd"));
    xAxis.setAutoTickUnitSelection(false);
    xAxis.setAutoRange(false);

    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage5 = MovingAverage.createMovingAverage(series, "MA(5)", 30, 0);
    Double currMA5 = (Double) movingAverage5.getDataItem(movingAverage5.getItemCount() - 1).getValue();
    currMA5 = Math.round(currMA5 * 100.0) / 100.0;
    movingAverage5.setKey("MA(5): " + currMA5);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage5);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    plot.setBackgroundPaint(Color.WHITE);

    chartPanel = new ChartPanel(chart);
    chart.setBackgroundPaint(chartPanel.getBackground());
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
}