Search in sources :

Example 1 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project openblocks by mikaelhg.

the class CBarGraph method getCSV.

public String getCSV() {
    StringBuilder output = new StringBuilder();
    DefaultCategoryDataset d = (DefaultCategoryDataset) chart.getCategoryPlot().getDataset();
    for (int i = 0; i < d.getRowCount(); i++) {
        output.append(d.getRowKey(i) + "," + d.getValue(d.getRowKey(i), Integer.valueOf(0)) + "\n");
    }
    return output.toString();
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 2 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project openblocks by mikaelhg.

the class CBarGraph method updateValues.

public void updateValues(String seriesName, double value) {
    if (!lock) {
        DefaultCategoryDataset dataset = (DefaultCategoryDataset) chart.getCategoryPlot().getDataset();
        dataset.addValue(value, seriesName, Integer.valueOf(0));
        if (value < lowerBound) {
            lowerBound = value;
        }
        if (value > upperBound) {
            upperBound = value;
        }
        CategoryPlot plot = chart.getCategoryPlot();
        plot.getRangeAxis().setLowerBound(lowerBound);
        plot.getRangeAxis().setUpperBound(upperBound);
    }
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 3 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project spring-data-document-examples by spring-projects.

the class ChartController method getControllerData.

private DefaultCategoryDataset getControllerData(String controllerName) {
    MongoTemplate mongoTemplate;
    DefaultCategoryDataset ds = null;
    try {
        Mongo m = new Mongo();
        mongoTemplate = new MongoTemplate(m, "mvc");
        List<ControllerCounter> counters;
        ds = new DefaultCategoryDataset();
        if (controllerName != null) {
            counters = mongoTemplate.find(new Query(where("name").is(controllerName)), ControllerCounter.class, "counters");
            for (ControllerCounter controllerCounter : counters) {
                Map<String, Double> methodInvocations = controllerCounter.getMethods();
                Set<Entry<String, Double>> es = methodInvocations.entrySet();
                for (Entry<String, Double> entry : es) {
                    ds.addValue(entry.getValue(), "invoked", entry.getKey());
                }
            }
        } else {
            counters = mongoTemplate.findAll(ControllerCounter.class, "counters");
            for (ControllerCounter controllerCounter : counters) {
                ds.addValue(controllerCounter.getCount(), "invoked (aggregate)", controllerCounter.getName());
            }
        }
        /*
			if (result instanceof BasicDBList) {
				BasicDBList dbList = (BasicDBList) result;
				for (Iterator iterator = dbList.iterator(); iterator.hasNext();) {
					DBObject dbo = (DBObject) iterator.next();
					System.out.println(dbo);
					Restaurant r = restaurantDao.findRestaurant(Long.parseLong(dbo.get("parameters.p1").toString()));
					ds.addValue(Double.parseDouble(dbo.get("count").toString()), "recommended", r.getName());
				}
			}*/
        return ds;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ds;
}
Also used : Query(org.springframework.data.document.mongodb.query.Query) Mongo(com.mongodb.Mongo) ControllerCounter(org.springframework.data.document.analytics.ControllerCounter) MongoTemplate(org.springframework.data.document.mongodb.MongoTemplate) Entry(java.util.Map.Entry) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 4 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project spring-data-document-examples by spring-projects.

the class ChartController method getFavoritesData.

private DefaultCategoryDataset getFavoritesData() {
    MongoTemplate mongoTemplate;
    DefaultCategoryDataset ds = null;
    try {
        Mongo m = new Mongo();
        mongoTemplate = new MongoTemplate(m, "mvc");
        DBObject result = getTopRecommendedRestaurants(mongoTemplate);
        /* Example data.
			 * [ { "parameters.p1" : "1" , "count" : 5.0} , 
			 *   { "parameters.p1" : "2" , "count" : 6.0} , 
			 *   { "parameters.p1" : "3" , "count" : 3.0} , 
			 *   { "parameters.p1" : "4" , "count" : 8.0}]
			 */
        ds = new DefaultCategoryDataset();
        if (result instanceof BasicDBList) {
            BasicDBList dbList = (BasicDBList) result;
            for (Iterator iterator = dbList.iterator(); iterator.hasNext(); ) {
                DBObject dbo = (DBObject) iterator.next();
                System.out.println(dbo);
                Restaurant r = restaurantDao.findRestaurant(Long.parseLong(dbo.get("parameters.p1").toString()));
                ds.addValue(Double.parseDouble(dbo.get("count").toString()), "recommended", r.getName());
            }
        }
        return ds;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ds;
}
Also used : BasicDBList(com.mongodb.BasicDBList) Restaurant(com.springone.myrestaurants.domain.Restaurant) Mongo(com.mongodb.Mongo) Iterator(java.util.Iterator) MongoTemplate(org.springframework.data.document.mongodb.MongoTemplate) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 5 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project spring-data-document-examples by spring-projects.

the class ChartController method generateControllerChart.

private JFreeChart generateControllerChart(String controllerName) {
    DefaultCategoryDataset dataset = getControllerData(controllerName);
    String xAxisLabel;
    String title;
    if (controllerName != null) {
        xAxisLabel = controllerName;
        title = controllerName + " Actions";
    } else {
        xAxisLabel = "Controllers";
        title = "Controller Invocations";
    }
    return ChartFactory.createBarChart(title, xAxisLabel, // y-axis label
    "Number of times invoked", // legend displayed
    dataset, // legend displayed
    PlotOrientation.VERTICAL, // legend displayed
    true, // tooltips displayed
    true, // no URLs*/
    false);
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Aggregations

DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)26 JFreeChart (org.jfree.chart.JFreeChart)9 CategoryPlot (org.jfree.chart.plot.CategoryPlot)7 Paint (java.awt.Paint)6 NumberAxis (org.jfree.chart.axis.NumberAxis)5 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)4 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)4 Color (java.awt.Color)3 Timestamp (java.sql.Timestamp)3 Mongo (com.mongodb.Mongo)2 Font (java.awt.Font)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)2 MResourceType (org.compiere.model.MResourceType)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 TextTitle (org.jfree.chart.title.TextTitle)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 RectangleInsets (org.jfree.ui.RectangleInsets)2