Search in sources :

Example 1 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem 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));
        }
    }
}
Also used : XYItemEntity(org.jfree.chart.entity.XYItemEntity) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) MQuery(org.compiere.model.MQuery) ChartEntity(org.jfree.chart.entity.ChartEntity) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 2 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem 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);
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) Panelchildren(org.zkoss.zul.Panelchildren) BufferedImage(java.awt.image.BufferedImage) XYItemEntity(org.jfree.chart.entity.XYItemEntity) Panel(org.zkoss.zul.Panel) Area(org.zkoss.zul.Area) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) AImage(org.zkoss.image.AImage) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) Event(org.zkoss.zk.ui.event.Event) MouseEvent(org.zkoss.zk.ui.event.MouseEvent) ChartEntity(org.jfree.chart.entity.ChartEntity) EventListener(org.zkoss.zk.ui.event.EventListener) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Imagemap(org.zkoss.zul.Imagemap)

Example 3 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem in project pentaho-platform by pentaho.

the class TimeSeriesCollectionChartDefinition method setDataByColumn.

private void setDataByColumn(final IPentahoResultSet data) {
    // TODO Make this routine MDX friendly
    if (data == null) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE");
        // No data so we've got nothing to set
        return;
    // TODO come up with some sort of error strategy here.
    }
    boolean firstPass = true;
    // $NON-NLS-1$
    String lastSeries = "";
    // $NON-NLS-1$
    String seriesName = "";
    Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
    Object[] rowData = data.next();
    TimeSeries wrkSeries = null;
    while (rowData != null) {
        seriesName = (String) rowData[0];
        if (firstPass || !seriesName.equalsIgnoreCase(lastSeries)) {
            if (!firstPass) {
                addSeries(wrkSeries);
            }
            wrkSeries = new TimeSeries(seriesName, timePeriodClass);
            lastSeries = seriesName;
            firstPass = false;
        }
        Date keyDate = getValidDate(rowData[1]);
        RegularTimePeriod regularTimePeriod = RegularTimePeriod.createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE);
        TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(regularTimePeriod, ((Number) rowData[2]).doubleValue());
        if (wrkSeries != null) {
            wrkSeries.add(timeSeriesDataItem);
        }
        rowData = data.next();
    }
    if (!firstPass) {
        addSeries(wrkSeries);
    }
    if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT");
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) RegularTimePeriod(org.jfree.data.time.RegularTimePeriod) Date(java.util.Date)

Example 4 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem in project dbeaver by serge-rider.

the class DashboardRendererBase method generateSampleSeries.

protected void generateSampleSeries(DashboardContainer container, TimeSeriesCollection dataset) {
    TimeSeries seriesSin = new TimeSeries("Sin");
    long startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 2;
    for (int i = 0; i < 100; i++) {
        seriesSin.add(new TimeSeriesDataItem(new FixedMillisecond(startTime + i * 60 * 1000), Math.sin(0.1 * i) * 100));
    }
    dataset.addSeries(seriesSin);
    TimeSeries seriesCos = new TimeSeries("Cos");
    for (int i = 0; i < 100; i++) {
        seriesCos.add(new TimeSeriesDataItem(new FixedMillisecond(startTime + i * 60 * 1000), Math.cos(0.1 * i) * 100));
    }
    dataset.addSeries(seriesCos);
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) FixedMillisecond(org.jfree.data.time.FixedMillisecond) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem)

Example 5 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem in project pentaho-platform by pentaho.

the class TimeSeriesCollectionChartDefinition method setDataByRow.

private void setDataByRow(final IPentahoResultSet data) {
    // TODO Make this routine MDX friendly
    if (data == null) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE");
        // No data so we've got nothing to set
        return;
    // TODO come up with some sort of error strategy here.
    }
    Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
    Object[] rowData = data.next();
    while (rowData != null) {
        String seriesName = (String) rowData[0];
        TimeSeries wrkSeries = new TimeSeries(seriesName, timePeriodClass);
        for (int column = 1; column < rowData.length - 1; column = column + 2) {
            Date keyDate = getValidDate(rowData[column]);
            TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(RegularTimePeriod.createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE), ((Number) rowData[column + 1]).doubleValue());
            wrkSeries.add(timeSeriesDataItem);
        }
        addSeries(wrkSeries);
        rowData = data.next();
    }
    if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
        // $NON-NLS-1$
        noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT");
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) Paint(java.awt.Paint) Date(java.util.Date)

Aggregations

TimeSeries (org.jfree.data.time.TimeSeries)8 TimeSeriesDataItem (org.jfree.data.time.TimeSeriesDataItem)8 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)4 Date (java.util.Date)3 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)2 ChartEntity (org.jfree.chart.entity.ChartEntity)2 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)2 XYItemEntity (org.jfree.chart.entity.XYItemEntity)2 FixedMillisecond (org.jfree.data.time.FixedMillisecond)2 Paint (java.awt.Paint)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)1 SeriesDefinition (org.apache.qpid.disttest.charting.definition.SeriesDefinition)1 SeriesRow (org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow)1 MQuery (org.compiere.model.MQuery)1 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)1 JFreeChart (org.jfree.chart.JFreeChart)1 XYTextAnnotation (org.jfree.chart.annotations.XYTextAnnotation)1