use of org.jfree.chart.entity.CategoryItemEntity in project adempiere by adempiere.
the class WGraph method render.
// loadData
private void render(JFreeChart chart) {
ChartRenderingInfo info = new ChartRenderingInfo();
int width = 560;
int height = 400;
if (zoomFactor > 0) {
width = width * zoomFactor / 100;
height = height * zoomFactor / 100;
}
if (m_hideTitle) {
chart.setTitle("");
}
BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
try {
byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
AImage image = new AImage("", bytes);
Imagemap myImage = new Imagemap();
myImage.setContent(image);
if (panel.getPanelchildren() != null) {
panel.getPanelchildren().getChildren().clear();
panel.getPanelchildren().appendChild(myImage);
} else {
Panelchildren pc = new Panelchildren();
panel.appendChild(pc);
pc.appendChild(myImage);
}
int count = 0;
for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) {
ChartEntity entity = (ChartEntity) it.next();
String key = null;
if (entity instanceof CategoryItemEntity) {
Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
if (colKey != null) {
key = colKey.toString();
}
} else if (entity instanceof PieSectionEntity) {
Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
if (sectionKey != null) {
key = sectionKey.toString();
}
}
if (key == null) {
continue;
}
Area area = new Area();
myImage.appendChild(area);
area.setCoords(entity.getShapeCoords());
area.setShape(entity.getShapeType());
area.setTooltiptext(entity.getToolTipText());
area.setId(count + "_WG_" + key);
count++;
}
myImage.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(Event event) throws Exception {
MouseEvent me = (MouseEvent) event;
String areaId = me.getArea();
if (areaId != null) {
for (int i = 0; i < list.size(); i++) {
String s = "_WG_" + list.get(i).getLabel();
if (areaId.endsWith(s)) {
chartMouseClicked(i);
return;
}
}
}
}
});
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
}
use of org.jfree.chart.entity.CategoryItemEntity in project adempiere by adempiere.
the class VChart method chartMouseClicked.
@Override
public void chartMouseClicked(ChartMouseEvent event) {
if ((event.getEntity() != null) && (event.getTrigger().getClickCount() > 1)) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
ChartEntity entity = event.getEntity();
String key = null;
String seriesName = null;
if (entity instanceof CategoryItemEntity) {
CategoryItemEntity item = ((CategoryItemEntity) entity);
Comparable<?> colKey = item.getColumnKey();
Comparable<?> rowKey = item.getRowKey();
if (colKey != null && rowKey != null) {
key = colKey.toString();
seriesName = rowKey.toString();
}
} else if (entity instanceof PieSectionEntity) {
Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
if (sectionKey != null) {
key = sectionKey.toString();
}
}
if (entity instanceof XYItemEntity) {
XYItemEntity item = ((XYItemEntity) entity);
if (item.getDataset() instanceof TimeSeriesCollection) {
TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
TimeSeries series = data.getSeries(item.getSeriesIndex());
TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
seriesName = series.getKey().toString();
key = dataitem.getPeriod().toString();
}
}
if (key == null)
return;
MQuery query = chartModel.getQuery(seriesName == null ? key : seriesName + "__" + key);
if (query != null)
AEnv.zoom(query);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
}
use of org.jfree.chart.entity.CategoryItemEntity in project adempiere by adempiere.
the class WChartEditor method render.
private void render(JFreeChart chart) {
ChartRenderingInfo info = new ChartRenderingInfo();
int width = 400;
int height = chartModel.getWinHeight();
BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info);
try {
byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
AImage image = new AImage("", bytes);
Imagemap myImage = new Imagemap();
Panel panel = getComponent();
myImage.setContent(image);
if (panel.getPanelchildren() != null) {
panel.getPanelchildren().getChildren().clear();
panel.getPanelchildren().appendChild(myImage);
} else {
Panelchildren pc = new Panelchildren();
panel.appendChild(pc);
pc.appendChild(myImage);
}
int count = 0;
for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext(); ) {
ChartEntity entity = (ChartEntity) it.next();
String key = null;
String seriesName = null;
if (entity instanceof CategoryItemEntity) {
CategoryItemEntity item = ((CategoryItemEntity) entity);
Comparable<?> colKey = item.getColumnKey();
Comparable<?> rowKey = item.getRowKey();
if (colKey != null && rowKey != null) {
key = colKey.toString();
seriesName = rowKey.toString();
}
} else if (entity instanceof PieSectionEntity) {
Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
if (sectionKey != null) {
key = sectionKey.toString();
}
}
if (entity instanceof XYItemEntity) {
XYItemEntity item = ((XYItemEntity) entity);
if (item.getDataset() instanceof TimeSeriesCollection) {
TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset();
TimeSeries series = data.getSeries(item.getSeriesIndex());
TimeSeriesDataItem dataitem = series.getDataItem(item.getItem());
seriesName = series.getKey().toString();
key = dataitem.getPeriod().toString();
}
}
if (key == null)
continue;
Area area = new Area();
myImage.appendChild(area);
area.setCoords(entity.getShapeCoords());
area.setShape(entity.getShapeType());
area.setTooltiptext(entity.getToolTipText());
area.setId(count + "_WG__" + seriesName + "__" + key);
count++;
}
myImage.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(Event event) throws Exception {
MouseEvent me = (MouseEvent) event;
String areaId = me.getArea();
if (areaId != null) {
String[] strs = areaId.split("__");
if (strs.length == 3) {
chartMouseClicked(strs[2], strs[1]);
}
}
}
});
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
}
use of org.jfree.chart.entity.CategoryItemEntity in project adempiere by adempiere.
the class Graph method getGraphColumn.
// setY_TargetLabel
/**
* Get BarGraphColumn for ChartEntity
* @param event
* @return BarGraphColumn or null if not found
*/
private GraphColumn getGraphColumn(ChartMouseEvent event) {
ChartEntity entity = event.getEntity();
String key = null;
if (entity instanceof CategoryItemEntity) {
Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey();
if (colKey != null) {
key = colKey.toString();
}
} else if (entity instanceof PieSectionEntity) {
Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey();
if (sectionKey != null) {
key = sectionKey.toString();
}
}
if (key == null) {
return null;
}
for (int i = 0; i < list.size(); i++) {
final String label = list.get(i).getLabel();
if (key.equals(label)) {
return list.get(i);
}
}
//
return null;
}
Aggregations