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

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

Introduction

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

Prototype

public void setNoDataMessage(String message) 

Source Link

Document

Sets the message that is displayed when the dataset is empty or null, and sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * A demonstration application showing a scatter plot.
 * //from  w w w .j  a va2 s  .c  o  m
 * @param title
 *           the frame title.
 */
public ScatterPlotDemo(final String title) {

    super(title);
    final XYDataset data = new SampleXYDataset2();
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    final Legend legend = chart.getLegend();
    if (legend instanceof StandardLegend) {
        final StandardLegend sl = (StandardLegend) legend;
        sl.setDisplaySeriesShapes(true);
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalZoom(true);
    chartPanel.setHorizontalZoom(true);
    setContentPane(chartPanel);

}

From source file:gsn.charts.GsnChartJfreechart.java

public JFreeChart createChart(Collection<Data> datas) {
    TimeSeries t1 = new TimeSeries("S1");
    Iterator<Data> iter = datas.iterator();
    Data data;/*from   w  w  w .  ja va2s  .  com*/
    while (iter.hasNext()) {
        data = iter.next();
        t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()),
                TimeZone.getDefault()), data.getValue());
    }
    XYDataset dataset = new TimeSeriesCollection(t1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chart.setBackgroundPaint(Color.WHITE);
    //
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("No Data to Display");
    plot.setDomainGridlinesVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInsets(new RectangleInsets(5, 14, 0, 5));
    //
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(ssdf);
    axis.setTickLabelFont(TICK_FONT);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickLabelFont(TICK_FONT);
    //
    return chart;
}

From source file:com.itemanalysis.jmetrik.graph.scatterplot.ScatterplotPanel.java

public void setGraph() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    PlotOrientation orientation = PlotOrientation.VERTICAL;

    try {/*w  w  w.  ja v a2  s  .co m*/
        chart = ChartFactory.createScatterPlot(title, // chart title
                xlabel, // x axis label
                ylabel, // y axis label
                dataset, // data
                orientation, showLegend, // include legend
                true, // tooltips
                false // urls
        );

        if (subtitle != null && !"".equals(subtitle)) {
            TextTitle subtitle1 = new TextTitle(subtitle);
            chart.addSubtitle(subtitle1);
        }

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setNoDataMessage("NO DATA");
        plot.setDomainZeroBaselineVisible(false);
        plot.setRangeZeroBaselineVisible(false);
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);

    } catch (IllegalArgumentException ex) {
        logger.fatal(ex.getMessage(), ex);
        this.firePropertyChange("error", "", "Error - Check log for details.");
    }
}

From source file:org.gaixie.micrite.jfreechart.style.LineStyle.java

public static void styleOne(JFreeChart chart) {
    XYPlot xyplot = (XYPlot) chart.getPlot();
    XYDataset xyd = xyplot.getDataset();
    //?/*w  w  w  .  ja  va  2  s .  c  o  m*/
    LineStyle.setBackground(chart);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    if (xyd != null) {
        //?
        xylineandshaperenderer.setBaseShapesVisible(true);
        //
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        xylineandshaperenderer.setBaseItemLabelsVisible(true);
        xyplot.setRenderer(xylineandshaperenderer);
        //tooltip
        //            xyplot.getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),new DecimalFormat()));
        //?
        for (int i = 0; i < xyd.getSeriesCount(); i++) {
            int colorIdx = i % colors.length;
            xylineandshaperenderer.setSeriesPaint(i, colors[colorIdx]);
        }
    } else {
        xyplot.setNoDataMessage("NO DATA");
    }

}

From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.AbstractPlot.java

/**
 * Creates a chart for a Sonargraph metric 
 * @param categoryName Name for the X-Axis, representing a category
 * @return Chart built with the given parameters.
 *///from w w w . j  a v  a2 s .  co  m
public final JFreeChart createXYChart(SonargraphMetrics metric, String categoryName,
        int maximumNumberOfDataPoints, boolean hideLegend) {
    XYDataset dataset = null;
    try {
        dataset = createXYDataset(metric, maximumNumberOfDataPoints);
    } catch (IOException ioe) {
        SonargraphLogger.INSTANCE.log(Level.SEVERE,
                "Failed to read metrics from data file '" + m_datasetProvider.getStorageName() + "'");
    }
    JFreeChart chart = createChartInternal(metric.getDescription(), categoryName, metric.getShortDescription(),
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();

    int dataPoints = 0;
    if (dataset == null) {
        plot.setNoDataMessage(
                "There was an error loading data for metric '" + metric.getShortDescription() + "'");
    } else {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            dataPoints += dataset.getItemCount(i);
        }
        if (dataPoints == 0) {
            plot.setNoDataMessage("No data found for metric '" + metric.getShortDescription() + "'");
        }
    }
    if ((dataset == null) || (dataPoints == 0)) {
        plot.setNoDataMessagePaint(Color.RED);
        plot.setDomainGridlinesVisible(false);
        plot.setRangeGridlinesVisible(false);
    }
    applyRendering(plot);
    setRangeAxis(metric.isNaturalNumber(), plot);
    applyStandardPlotColors(plot);
    if (hideLegend) {
        chart.removeLegend();
    }
    return chart;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.ClinicalPlot.java

private void createChart() {

    //String xLabel = factor1.toString();
    String xLabel = factor1AxisLabel;
    //String yLabel = factor2.toString();
    String yLabel = factor2AxisLabel;

    clinicalChart = ChartFactory.createScatterPlot("Clinical Plot", xLabel, yLabel, null,
            PlotOrientation.VERTICAL, true, true, false);

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

    buildLegend();//from  w  w w  .  j  ava  2s  .c  o m

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.

    domainAxis.setAutoRangeIncludesZero(false);

    //get domain and range of the axis.
    DataRange domainAxisLimits = getDataRange(dataPoints, factor1, true);
    DataRange rangeAxisLimits = getDataRange(dataPoints, factor2, true);

    //domainAxis.setRange(domainAxisLimits.getMinRange(), domainAxisLimits.getMaxRange());
    //rangeAxis.setRange(rangeAxisLimits.getMinRange(), rangeAxisLimits.getMaxRange());

    double domainMax = Math.max(100.0, domainAxisLimits.getMaxRange()) + 5.0;
    double rangeMax = Math.max(100.0, rangeAxisLimits.getMaxRange()) + 5.0;

    domainAxis.setRange(0.0, domainMax);
    rangeAxis.setRange(0.0, rangeMax);

    System.out.println("domainAxis=" + domainAxis.getLabel());
    System.out.println("rangeAxis=" + rangeAxis.getLabel());

    createGlyphsAndAddToPlot(plot);
}

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

private JFreeChart createChart(final IntervalXYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYBarChart(getTitle(), xLable, false, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();

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

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.setNoDataMessage("No data available");
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    setBarShadowVisible(chart, false);/*from www  .  j ava 2  s. c  om*/

    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (dataset.getSeriesCount() > 0)
        plot.getDomainAxis().setUpperBound(lastXValue);
    plot.getDomainAxis().setLowerBound(0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setUpperMargin(0.1);

    return chart;
}

From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java

/**
 * Creates the Chart based on a dataset//from   w ww  . j a va2s .  c o m
 */
private JFreeChart createChart(final TimeSeriesCollection dataset) {

    final String annTitle = "[PENDING]";
    final String catLabel = "Time";
    final String valueLabel = "Value";
    final JFreeChart chart = ChartFactory.createXYLineChart(annTitle, catLabel, valueLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis dateA = new DateAxis();
    plot.setDomainAxis(dateA);
    plot.setRenderer(new XYLineAndShapeRenderer());
    plot.setNoDataMessage("No data available");
    return chart;

}

From source file:Demo.ScatterGraph.java

private JFreeChart CreateChart(int x, int y) {
    dataSet = new DefaultXYDataset();
    AddDataSet(x, y);/*  ww  w  .j  a  v a  2s  . c  om*/

    JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter", paraType_list.get(x),
            paraType_list.get(y), dataSet, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) jfreechart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    plot.setDomainGridlinesVisible(true);
    plot.setNoDataMessage("no data");

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) plot.getRenderer();
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.WHITE);
    xylineandshaperenderer.setUseOutlinePaint(true);
    xylineandshaperenderer.setSeriesPaint(0, Color.BLUE);

    return jfreechart;
}

From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.domain.stadistics.graphics.implement.Grafica.java

@Override
public JFreeChart createXYLineChartToHoursOfDay(List<HoraDelDiaEstadistica> horasDelDia) {
    //Se obtiene el conjunto de datos
    XYDataset dataset = createDataForHoursOfDay(horasDelDia);

    JFreeChart chart = ChartFactory.createXYLineChart(TITLE_OF_XY_CHART, //Titulo del grafico
            DOMAIN_AXIS_LABEL_HOUR, //Nombre del Rango
            RANGE_AXIS_LABEL, //Nombre del dominio
            dataset, //conjunto de datos
            PlotOrientation.VERTICAL, //Orientacion del grafico
            true, //incluir leyendas
            true, false);//from ww  w  .j  av  a  2s  . c  om

    //Se pinta el fondo de blanco
    chart.setBackgroundPaint(Color.WHITE);

    //Se pintan el fondo del grafico de gris y las lineas de blanco
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    plot.setNoDataMessage(NO_DATA_TO_DISPLAY);

    //Se configura para que solo muestre nmeros enteros en el rango
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //Se configura para que solo muestre nmeros enteros en el dominio
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}