use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.
the class CRP method createWeightDataset.
/**
* Create Category Dataset based on Weight , date start and resource
* @param start
* @param resource
* @return CategoryDataset
*/
protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) {
GregorianCalendar gc1 = new GregorianCalendar();
gc1.setTimeInMillis(start.getTime());
gc1.clear(Calendar.MILLISECOND);
gc1.clear(Calendar.SECOND);
gc1.clear(Calendar.MINUTE);
gc1.clear(Calendar.HOUR_OF_DAY);
String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
String nameload = Msg.translate(Env.getCtx(), "Load");
String namesummary = Msg.translate(Env.getCtx(), "Summary");
String namepossiblecapacity = "Possible Capacity";
MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID());
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID());
double dailyCapacity = rosource.getDailyCapacity().doubleValue();
double utilization = rosource.getPercentUtilization().doubleValue();
double summary = 0;
int day = 0;
while (day < 32) {
day++;
switch(gc1.get(Calendar.DAY_OF_WEEK)) {
case Calendar.SUNDAY:
if (t.isOnSunday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.MONDAY:
if (t.isOnMonday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.TUESDAY:
if (t.isOnTuesday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.WEDNESDAY:
if (t.isOnWednesday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.THURSDAY:
if (t.isOnThursday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.FRIDAY:
if (t.isOnFriday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
case Calendar.SATURDAY:
if (t.isOnSaturday()) {
currentweight -= (dailyCapacity * utilization) / 100;
summary += ((dailyCapacity * utilization) / 100);
dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
} else {
dataset.addValue(0, namepossiblecapacity, new Integer(day));
dataset.addValue(0, namecapacity, new Integer(day));
}
break;
}
dataset.addValue(currentweight, nameload, new Integer(day));
dataset.addValue(summary, namesummary, new Integer(day));
gc1.add(Calendar.DATE, 1);
}
return dataset;
}
use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.
the class MChartDatasource method addData.
public void addData(MChart parent) {
String value = getValueColumn();
String category;
String unit = "D";
if (!parent.isTimeSeries())
category = getCategoryColumn();
else {
if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Week)) {
unit = "W";
} else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Month)) {
unit = "MM";
} else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Quarter)) {
unit = "Q";
} else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Year)) {
unit = "Y";
}
category = " TRUNC(" + getDateColumn() + ", '" + unit + "') ";
}
String series = DB.TO_STRING(getName());
boolean hasSeries = false;
if (getSeriesColumn() != null) {
series = getSeriesColumn();
hasSeries = true;
}
String where = getWhereClause();
if (!Util.isEmpty(where)) {
where = Env.parseContext(getCtx(), parent.getWindowNo(), where, true);
}
boolean hasWhere = false;
String sql = "SELECT " + value + ", " + category + ", " + series + " FROM " + getFromClause();
if (!Util.isEmpty(where)) {
sql += " WHERE " + where;
hasWhere = true;
}
Date currentDate = Env.getContextAsDate(getCtx(), "#Date");
Date startDate = null;
Date endDate = null;
int scope = parent.getTimeScope();
int offset = getTimeOffset();
if (parent.isTimeSeries() && scope != 0) {
offset += -scope;
startDate = increment(currentDate, parent.getTimeUnit(), offset);
endDate = increment(startDate, parent.getTimeUnit(), scope);
}
if (startDate != null && endDate != null) {
sql += hasWhere ? " AND " : " WHERE ";
sql += category + ">=TRUNC(" + DB.TO_DATE(new Timestamp(startDate.getTime())) + ", '" + unit + "') AND ";
sql += category + "<=TRUNC(" + DB.TO_DATE(new Timestamp(endDate.getTime())) + ", '" + unit + "') ";
}
MRole role = MRole.getDefault(getCtx(), false);
sql = role.addAccessSQL(sql, null, true, false);
if (hasSeries)
sql += " GROUP BY " + series + ", " + category + " ORDER BY " + series + ", " + category;
else
sql += " GROUP BY " + category + " ORDER BY " + category;
log.log(Level.FINE, sql);
PreparedStatement pstmt = null;
ResultSet rs = null;
TimeSeries tseries = null;
Dataset dataset = parent.getDataset();
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
String key = rs.getString(2);
String seriesName = rs.getString(3);
if (seriesName == null)
seriesName = getName();
String queryWhere = "";
if (hasWhere)
queryWhere += where + " AND ";
queryWhere += series + " = " + DB.TO_STRING(seriesName) + " AND " + category + " = ";
if (parent.isTimeSeries() && dataset instanceof TimeSeriesCollection) {
if (tseries == null || !tseries.getKey().equals(seriesName)) {
if (tseries != null)
((TimeSeriesCollection) dataset).addSeries(tseries);
tseries = new TimeSeries(seriesName);
}
Date date = rs.getDate(2);
RegularTimePeriod period = null;
if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Day))
period = new Day(date);
else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Week))
period = new Week(date);
else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Month))
period = new Month(date);
else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Quarter))
period = new Quarter(date);
else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Year))
period = new Year(date);
tseries.add(period, rs.getBigDecimal(1));
key = period.toString();
queryWhere += DB.TO_DATE(new Timestamp(date.getTime()));
} else {
queryWhere += DB.TO_STRING(key);
}
MQuery query = new MQuery(getAD_Table_ID());
String keyCol = MTable.get(getCtx(), getAD_Table_ID()).getKeyColumns()[0];
String whereClause = keyCol + " IN (SELECT " + getKeyColumn() + " FROM " + getFromClause() + " WHERE " + queryWhere + " )";
query.addRestriction(whereClause.toString());
query.setRecordCount(1);
HashMap<String, MQuery> map = parent.getQueries();
if (dataset instanceof DefaultPieDataset) {
((DefaultPieDataset) dataset).setValue(key, rs.getBigDecimal(1));
map.put(key, query);
} else if (dataset instanceof DefaultCategoryDataset) {
((DefaultCategoryDataset) dataset).addValue(rs.getBigDecimal(1), seriesName, key);
map.put(seriesName + "__" + key, query);
} else if (dataset instanceof TimeSeriesCollection) {
map.put(seriesName + "__" + key, query);
}
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (tseries != null)
((TimeSeriesCollection) dataset).addSeries(tseries);
}
use of org.jfree.data.category.DefaultCategoryDataset in project jgnash by ccavanaugh.
the class BudgetSparkline method getSparklineImage.
public static Icon getSparklineImage(final List<BigDecimal> amounts) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
final boolean[] negate = new boolean[amounts.size()];
for (int i = 0; i < amounts.size(); i++) {
dataset.addValue(amounts.get(i), CATEGORY, i);
negate[i] = amounts.get(i).signum() == -1;
}
CategoryAxis xAxis = new CategoryAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarksVisible(false);
xAxis.setAxisLineVisible(false);
xAxis.setVisible(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickMarksVisible(false);
yAxis.setAxisLineVisible(false);
yAxis.setNegativeArrowVisible(false);
yAxis.setPositiveArrowVisible(false);
yAxis.setAutoRangeIncludesZero(true);
yAxis.setAutoRange(true);
yAxis.setVisible(false);
BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(final int row, final int column) {
return negate[column] ? Color.RED : Color.BLACK;
}
};
renderer.setShadowVisible(false);
renderer.setBarPainter(new StandardBarPainter());
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
plot.setInsets(INSETS);
plot.setDomainGridlinesVisible(false);
plot.setDomainCrosshairVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setRangeCrosshairVisible(false);
plot.setBackgroundPaint(CLEAR);
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBorderVisible(false);
chart.setBackgroundPaint(CLEAR);
Icon icon = EMPTY_ICON;
try {
byte[] image = ENCODER.encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
icon = new ImageIcon(image);
} catch (IOException ex) {
Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
}
return icon;
}
use of org.jfree.data.category.DefaultCategoryDataset in project hudson-2.x by hudson.
the class DataSetBuilder method build.
public CategoryDataset build() {
DefaultCategoryDataset ds = new DefaultCategoryDataset();
TreeSet<Row> rowSet = new TreeSet<Row>(rows);
TreeSet<Column> colSet = new TreeSet<Column>(columns);
Comparable[] _rows = rowSet.toArray(new Comparable[rowSet.size()]);
Comparable[] _cols = colSet.toArray(new Comparable[colSet.size()]);
// insert rows and columns in the right order
for (Comparable r : _rows) ds.setValue(null, r, _cols[0]);
for (Comparable c : _cols) ds.setValue(null, _rows[0], c);
for (int i = 0; i < values.size(); i++) ds.addValue(values.get(i), rows.get(i), columns.get(i));
return ds;
}
use of org.jfree.data.category.DefaultCategoryDataset in project ice by Netflix.
the class BasicWeeklyCostEmailService method createImage.
private File createImage(ApplicationGroup appgroup) throws IOException {
Map<String, Double> costs = Maps.newHashMap();
DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
Interval interval = new Interval(end.minusWeeks(numWeeks), end);
for (Product product : products) {
List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
if (resourceGroups.size() == 0) {
continue;
}
DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
if (dataManager == null) {
continue;
}
TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups);
Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false);
for (Tag tag : data.keySet()) {
for (int week = 0; week < numWeeks; week++) {
String key = tag + "|" + week;
if (costs.containsKey(key))
costs.put(key, data.get(tag)[week] + costs.get(key));
else
costs.put(key, data.get(tag)[week]);
}
}
}
boolean hasData = false;
for (Map.Entry<String, Double> entry : costs.entrySet()) {
if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
hasData = true;
break;
}
}
if (!hasData)
return null;
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (Product product : products) {
for (int week = 0; week < numWeeks; week++) {
String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
}
}
JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
renderer.setItemLabelAnchorOffset(10.0);
TextTitle title = chart.getTitle();
title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
return costFormatter.format(dataset.getValue(row, column));
}
});
renderer.setBaseItemLabelsVisible(true);
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setNumberFormatOverride(costFormatter);
BufferedImage image = chart.createBufferedImage(1200, 400);
File outputfile = File.createTempFile("awscost", "png");
ImageIO.write(image, "png", outputfile);
return outputfile;
}
Aggregations