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:org.encog.workbench.tabs.rbf.RadialBasisFunctionsTab.java

public JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(null, "input (x)", "output (y)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

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

    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainPannable(true);/*from   w ww .ja  v a  2s.c o  m*/
    plot.setRangePannable(true);
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setDrawSeriesLineAsPath(true);
    r.setSeriesStroke(0, new BasicStroke(1.5f));
    r.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 4.0f }, 0.0f));
    r.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 4.0f, 3.0f, 3.0f }, 0.0f));
    r.setSeriesStroke(3, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 4.0f, 4.0f }, 0.0f));

    return chart;
}

From source file:sistemacontrole.LeituraEscritaCanais.java

public void criarGraficoSaida() {
    JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Tempo (s)", "Tenso (V)", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel graficoGerado = new ChartPanel(xylineChart);

    this.mainWindow.PainelSaida.setLayout(null);
    this.mainWindow.PainelSaida.add(graficoGerado);
    graficoGerado.setBounds(this.mainWindow.PainelSaida.getVisibleRect());
    final XYPlot plot = xylineChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from   w  ww.j  av  a 2s. c o m
    axis.setFixedAutoRange(120.0);
}

From source file:daylightchart.daylightchart.chart.DaylightChart.java

private void adjustForChartOrientation(final ChartOrientation chartOrientation) {
    if (chartOrientation == null) {
        return;/*from w w w.  j av  a  2 s  .  com*/
    }

    final XYPlot plot = getXYPlot();
    final ValueAxis hoursAxis = plot.getRangeAxis();
    final ValueAxis monthsAxis = plot.getDomainAxis();

    switch (chartOrientation) {
    case STANDARD:
        hoursAxis.setInverted(true);
        plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
        break;
    case CONVENTIONAL:
        break;
    case VERTICAL:
        plot.setOrientation(PlotOrientation.HORIZONTAL);
        monthsAxis.setInverted(true);
        break;
    default:
        break;
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * /*from  w w w .ja  v  a 2s .c o m*/
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:sistemacontrole.LeituraEscritaCanais.java

public void criarGraficoEntrada() {
    JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Tempo (s)", "Altura (cm)",
            createDatasetEntrada(), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel graficoGerado = new ChartPanel(xylineChart);

    this.mainWindow.PainelEntrada.setLayout(null);
    this.mainWindow.PainelEntrada.removeAll();
    this.mainWindow.PainelEntrada.add(graficoGerado);
    graficoGerado.setBounds(this.mainWindow.PainelEntrada.getVisibleRect());
    final XYPlot plot = xylineChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//www  .j a  v a 2s. c  o  m
    axis.setFixedAutoRange(120.0);
}

From source file:org.nees.rpi.vis.ui.ProfilePlotFrame.java

public void plot() {
    Collections.sort(series);/*from   w ww .j  a  v  a  2s.  c  o  m*/

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setRange(rangeMin, rangeMax);

    int timeIndex = 0;
    plotTime(timeIndex);
}

From source file:networkanalyzer.DynamicPing.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Ping Chart", //title
            "Time", //x-axis
            "Ping", //y-axis
            dataset, false, false, false);

    final XYPlot plot = result.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);//from w  w  w  .j a  va 2s  .  co  m

    xaxis.setFixedAutoRange(60000.0);
    xaxis.setVerticalTickLabels(true);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setAutoRange(true);

    return result;

}

From source file:org.posterita.struts.pos.POSSalesReportAction.java

public ActionForward getCustomReport(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws OperationException, ApplicationException {
    ActionForward fwd = init(mapping, form, request, response);
    if (fwd != null)
        return fwd;

    Properties ctx = TmkJSPEnv.getCtx(request);
    DefaultForm df = (DefaultForm) form;

    ReportBean bean = (ReportBean) df.getBean();
    Timestamp fromDate = ReportDateManager.getFromDate(bean);
    Timestamp toDate = ReportDateManager.getToDate(bean);
    String timeperiod = bean.getTimePeriod();
    String chartType = bean.getChartType();
    String salesGroup = bean.getSalesGroup();

    String reportDir = ReportManager.getReportDirectoryFromServletContext(this.servlet);
    String filename = RandomStringGenerator.randomstring();

    String subtitle = null;//from  w ww  .  j ava 2s.com
    String title = null;

    if (timeperiod != null) {
        subtitle = "For " + timeperiod;
    } else {
        subtitle = "For period:" + fromDate + " to " + toDate;
    }

    if (salesGroup.equalsIgnoreCase(Constants.REVENUE_RECOGNITION)
            || salesGroup.equalsIgnoreCase(Constants.ATTRIBUTESET)) {
        title = "Sales By " + salesGroup;
    } else {
        String[] s = salesGroup.split("_");

        if (s.length != 2) {
            throw new OperationException("Cannot generate sql. Unknown salesGroup parameter:" + salesGroup);
        }

        int attributeSetId = Integer.parseInt(s[0]);
        int attributeId = Integer.parseInt(s[1]);

        String attributeSetName = null;
        String attributeName = null;

        attributeSetName = MAttributeSet.get(ctx, attributeSetId).getName();
        attributeName = new MAttribute(ctx, attributeId, null).getName();

        title = "Sales By " + attributeName + " For " + attributeSetName;
    }

    if (chartType.equals(PieChart.CHART_TYPE)) {
        //draw pie chart
        String pieChartSQL = SalesAnalysisReportManager.getPieChartDataSetSQL(ctx, Integer.valueOf(1), fromDate,
                toDate, salesGroup);
        PieChart pieChart = new PieChart();

        pieChart.setTitle(title);
        pieChart.setSubtitle(subtitle);
        pieChart.getDataSetFromSQL(pieChartSQL);
        pieChart.getChart().setBackgroundPaint(Color.white);
        pieChart.saveChartAsJPEG(reportDir + filename + ".jpg", 700, 600);
    } else if (chartType.equals(TimeSeriesChart.CHART_TYPE)) {
        //draw timeseries
        String timeSeriesChartSQL = SalesAnalysisReportManager.getTimeSeriesDataSetSQL(ctx, Integer.valueOf(1),
                fromDate, toDate, salesGroup);
        TimeSeriesChart timeSeriesChart = new TimeSeriesChart();

        timeSeriesChart.setTitle(title);
        timeSeriesChart.setSubtitle(subtitle);
        timeSeriesChart.setShowShapes(true);
        timeSeriesChart.getDataSetFromSQL(timeSeriesChartSQL);

        XYPlot plot = (XYPlot) timeSeriesChart.getChart().getPlot();
        DateAxis axis = (DateAxis) plot.getDomainAxis();

        axis.setRange(fromDate, toDate);
        //axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1,new SimpleDateFormat("MMM-yyyy")));

        timeSeriesChart.getChart().setBackgroundPaint(Color.white);
        timeSeriesChart.saveChartAsJPEG(reportDir + filename + ".jpg", 700, 600);
    } else {
        throw new OperationException("Invalid Chart type:" + chartType);
    }

    String imgURL = request.getContextPath() + "/config/reports/" + filename + ".jpg";
    request.getSession().setAttribute(Constants.REPORT_URL, imgURL);

    return mapping.findForward(GET_CUSTOM_REPORT);
    //return getGroupedSalesReport(mapping,form,request,response);
}

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

/**
 * Creates a chart./*from ww w  . ja v  a 2s . co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYAreaChart("XY Area Chart Demo", "Domain (X)", "Range (Y)",
            dataset, PlotOrientation.VERTICAL, true, // legend
            true, // tool tips
            false // URLs
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(Color.black);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    return chart;

}

From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java

private JFreeChart getPerformanceChart(int intervalSize, List<PerformanceData> performance,
        int expectedRevoked) {
    TimeSeries series = new TimeSeries("Success");
    TimeSeries revokedSeries = new TimeSeries("Revoked");
    TimeSeries failureSeries = new TimeSeries("Failures");

    performance.remove(performance.size() - 1);
    if (performance.isEmpty()) {
        JOptionPane.showMessageDialog(null, "test did not run long enough");
        return null;
    }// ww w . j  a va2 s .  c o m

    JFreeChart chart;

    int totalCount = 0;
    int totalRevoked = 0;
    int totalFailures = 0;

    for (PerformanceData performanceEntry : performance) {
        series.add(new Second(performanceEntry.getDate()), performanceEntry.getCount());
        totalCount += performanceEntry.getCount();

        revokedSeries.add(new Second(performanceEntry.getDate()), performanceEntry.getRevoked());
        totalRevoked += performanceEntry.getRevoked();

        failureSeries.add(new Second(performanceEntry.getDate()), performanceEntry.getFailures());
        totalFailures += performanceEntry.getFailures();
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(revokedSeries);
    dataset.addSeries(failureSeries);
    chart = ChartFactory.createTimeSeriesChart("eID Trust Service Performance History",
            "Time (interval size " + intervalSize + " msec)", "Number of XKMS requests", dataset, true, false,
            false);

    chart.addSubtitle(new TextTitle(performance.get(0).getDate().toString() + " - "
            + performance.get(performance.size() - 1).getDate().toString()));

    TextTitle info = new TextTitle("Total number of successful requests: " + totalCount);
    info.setTextAlignment(HorizontalAlignment.LEFT);
    info.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(info);

    TextTitle info2 = new TextTitle(
            "Total number of revoked: " + totalRevoked + " expected=" + expectedRevoked);
    info2.setPosition(RectangleEdge.BOTTOM);
    info2.setTextAlignment(HorizontalAlignment.LEFT);
    chart.addSubtitle(info2);

    TextTitle info3 = new TextTitle("Total number of failures: " + totalFailures);
    info3.setPosition(RectangleEdge.BOTTOM);
    info3.setTextAlignment(HorizontalAlignment.LEFT);
    chart.addSubtitle(info3);

    chart.setBackgroundPaint(Color.WHITE);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    return chart;
}