Search in sources :

Example 6 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem in project qpid-broker-j by apache.

the class TimeSeriesBuilderCallbackTest method testAddPointToSeries.

@Test
public void testAddPointToSeries() {
    TimeSeriesHolder timeSeriesHolder = new TimeSeriesHolder();
    SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
    when(seriesDefinition.getSeriesLegend()).thenReturn(SERIES_LEGEND);
    timeSeriesHolder.beginSeries(seriesDefinition);
    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[0], _values[0]));
    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[1], _values[1]));
    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[2], _values[2]));
    timeSeriesHolder.endSeries(seriesDefinition);
    TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) timeSeriesHolder.getPopulatedDataset();
    TimeSeries actualTimeSeries = timeSeriesCollection.getSeries(SERIES_LEGEND);
    for (int i = 0; i < NUMBER_OF_DATA_POINTS; i++) {
        TimeSeriesDataItem dataItem0 = actualTimeSeries.getDataItem(i);
        assertEquals(_dates[i].getTime(), dataItem0.getPeriod().getMiddleMillisecond());
        assertEquals(_values[i], dataItem0.getValue());
    }
}
Also used : SeriesDefinition(org.apache.qpid.disttest.charting.definition.SeriesDefinition) TimeSeries(org.jfree.data.time.TimeSeries) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) SeriesRow(org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow) Test(org.junit.Test)

Example 7 with TimeSeriesDataItem

use of org.jfree.data.time.TimeSeriesDataItem in project MtgDesktopCompanion by nicho92.

the class HistoryPricesPanel method refresh.

private void refresh() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series1 = new TimeSeries(title);
    if (showAll) {
        for (MTGDashBoard d : MTGControler.getInstance().getDashBoards()) {
            TimeSeries series = new TimeSeries(d.getName());
            Map<Date, Double> mapTime;
            try {
                mapTime = d.getPriceVariation(mc, me);
                if (mapTime != null) {
                    for (Entry<Date, Double> da : mapTime.entrySet()) series.add(new Day(da.getKey()), da.getValue().doubleValue());
                    dataset.addSeries(series);
                }
            } catch (IOException e) {
                MTGLogger.printStackTrace(e);
            }
        }
    } else {
        for (Entry<Date, Double> d : map.entrySet()) series1.add(new Day(d.getKey()), d.getValue().doubleValue());
        dataset.addSeries(series1);
    }
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Price Variation", "Date", "Price", dataset, true, true, false);
    if (showEdition)
        try {
            for (MagicEdition edition : MTGControler.getInstance().getEnabledProviders().loadEditions()) {
                Date d = new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(edition.getReleaseDate() + " 00:00");
                TimeSeriesDataItem item = series1.getDataItem(new Day(d));
                if (item != null) {
                    double x = item.getPeriod().getFirstMillisecond();
                    double y = item.getValue().doubleValue();
                    XYTextAnnotation annot = new XYTextAnnotation(edition.getId(), x, y);
                    annot.setToolTipText(edition.getSet());
                    XYPlot plot = (XYPlot) chart.getPlot();
                    plot.addAnnotation(annot);
                }
            }
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
    pane.setChart(chart);
    pane.addMouseWheelListener(mwe -> {
        if (mwe.getWheelRotation() > 0) {
            pane.zoomOutDomain(0.5, 0.5);
        } else if (mwe.getWheelRotation() < 0) {
            pane.zoomInDomain(1.5, 1.5);
        }
    });
    this.add(pane, BorderLayout.CENTER);
    chart.fireChartChanged();
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MTGDashBoard(org.magic.api.interfaces.MTGDashBoard) MagicEdition(org.magic.api.beans.MagicEdition) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) IOException(java.io.IOException) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) IOException(java.io.IOException) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 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