Zobrazujeme graf – zatím s pokusnými daty. Pozor na chybu: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 01 Mar 2009 01:08:24 +0100
changeset 39be6383d38a3a
parent 38 9bb0a26fd616
child 40 fd29fd5a8e29
Zobrazujeme graf – zatím s pokusnými daty. Pozor na chybu: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
V konsoli se vypíše: X11 connection rejected because of wrong authentication.
Je potřeba přidat tuto volbu: -Djava.awt.headless=true
(ve webovém rozhraní GlassFishe a restartovat ho)
java/HrisniciSpameri/src/java/cz/frantovo/hrisniciSpameri/grafy/CasovyGrafUtoku.java
java/HrisniciSpameri/web/graf.jspx
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/HrisniciSpameri/src/java/cz/frantovo/hrisniciSpameri/grafy/CasovyGrafUtoku.java	Sun Mar 01 01:08:24 2009 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +package cz.frantovo.hrisniciSpameri.grafy;
     1.5 +
     1.6 +import de.laures.cewolf.DatasetProduceException;
     1.7 +import de.laures.cewolf.DatasetProducer;
     1.8 +import de.laures.cewolf.links.CategoryItemLinkGenerator;
     1.9 +import de.laures.cewolf.tooltips.CategoryToolTipGenerator;
    1.10 +import java.io.Serializable;
    1.11 +import java.util.Calendar;
    1.12 +import java.util.Date;
    1.13 +import java.util.Map;
    1.14 +import org.jfree.data.category.CategoryDataset;
    1.15 +import org.jfree.data.time.Day;
    1.16 +import org.jfree.data.time.TimeSeries;
    1.17 +import org.jfree.data.time.TimeSeriesCollection;
    1.18 +import org.jfree.data.xy.XYDataset;
    1.19 +
    1.20 +/**
    1.21 + *
    1.22 + * @author fiki
    1.23 + */
    1.24 +public class CasovyGrafUtoku implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable {
    1.25 +
    1.26 +    private static final long serialVersionUID = -9133218147909088777L;
    1.27 +
    1.28 +    public XYDataset produceDataset(Map params) throws DatasetProduceException {
    1.29 +
    1.30 +        System.setProperty("java.awt.headless", "true");
    1.31 +
    1.32 +        TimeSeries timeseries = new TimeSeries("fond", org.jfree.data.time.Day.class);
    1.33 +        TimeSeriesCollection dataset = new TimeSeriesCollection();
    1.34 +
    1.35 +
    1.36 +        Calendar datum = Calendar.getInstance();
    1.37 +        for (int i = 0; i < 11; i++) {
    1.38 +            datum.add(Calendar.DAY_OF_YEAR, -1);
    1.39 +            double nahodneCislo = 100 - 10 * i - 20 * Math.random();
    1.40 +            timeseries.add(new Day(datum.getTime()), nahodneCislo);
    1.41 +        }
    1.42 +
    1.43 +        dataset.addSeries(timeseries);
    1.44 +        return dataset;
    1.45 +    }
    1.46 +
    1.47 +    public boolean hasExpired(Map params, Date since) {
    1.48 +        return (System.currentTimeMillis() - since.getTime()) > 5000;
    1.49 +    }
    1.50 +
    1.51 +    public String getProducerId() {
    1.52 +        return this.getClass().getSimpleName();
    1.53 +    }
    1.54 +
    1.55 +    public String generateToolTip(CategoryDataset data, int series, int item) {
    1.56 +        return "";
    1.57 +    }
    1.58 +
    1.59 +    public String generateLink(Object dataset, int series, Object category) {
    1.60 +        return "";
    1.61 +    }
    1.62 +}
     2.1 --- a/java/HrisniciSpameri/web/graf.jspx	Sun Mar 01 00:10:46 2009 +0100
     2.2 +++ b/java/HrisniciSpameri/web/graf.jspx	Sun Mar 01 01:08:24 2009 +0100
     2.3 @@ -1,14 +1,33 @@
     2.4  <?xml version="1.0" encoding="UTF-8"?>
     2.5 -<!-- 
     2.6 -    Document   : souhrn
     2.7 -    Created on : 11.2.2009, 18:54:42
     2.8 -    Author     : fiki
     2.9 --->
    2.10  <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    2.11            xmlns:c="http://java.sun.com/jsp/jstl/core"
    2.12            xmlns:f="http://java.sun.com/jsp/jstl/functions"
    2.13 +          xmlns:cewolf="http://cewolf.sourceforge.net/taglib/cewolf.tld"
    2.14            version="2.0">
    2.15  
    2.16      <h2>Graf</h2>
    2.17  
    2.18 +    <jsp:useBean id="casovyGrafUtoku" class="cz.frantovo.hrisniciSpameri.grafy.CasovyGrafUtoku" />
    2.19 +
    2.20 +
    2.21 +    <cewolf:chart id="graf" title="Můj graf" type="timeseries" xaxislabel="Datum" yaxislabel="Počet" showlegend="false">
    2.22 +        <cewolf:data>
    2.23 +            <cewolf:producer id="casovyGrafUtoku" usecache="false">
    2.24 +                <!-- TODO: rozchodit mezipaměť - cache -->
    2.25 +                <cewolf:param name="isin" value="${isin}" />
    2.26 +                <cewolf:param name="currency" value="${currency}" />
    2.27 +                <cewolf:param name="monthFrom" value="${monthFrom}" />
    2.28 +                <cewolf:param name="yearFrom" value="${yearFrom}" />
    2.29 +                <cewolf:param name="monthTo" value="${monthTo}" />
    2.30 +                <cewolf:param name="yearTo" value="${yearTo}" />
    2.31 +            </cewolf:producer>
    2.32 +        </cewolf:data>
    2.33 +        <cewolf:gradientpaint>
    2.34 +            <cewolf:point x="0" y="0" color="#F5F5F5" />
    2.35 +            <cewolf:point x="0" y="300" color="#e5e5e5" />
    2.36 +        </cewolf:gradientpaint>
    2.37 +    </cewolf:chart>
    2.38 +
    2.39 +    <cewolf:img chartid="graf" renderer="/cewolf" width="680" height="320" />
    2.40 +
    2.41  </jsp:root>