本文整理匯總了Java中org.jfree.data.time.TimeSeries.addOrUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java TimeSeries.addOrUpdate方法的具體用法?Java TimeSeries.addOrUpdate怎麽用?Java TimeSeries.addOrUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jfree.data.time.TimeSeries
的用法示例。
在下文中一共展示了TimeSeries.addOrUpdate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createVolumeDataset
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
private IntervalXYDataset createVolumeDataset() {
List<IRate> rates = rateProvider.getRates(base, quote);
TimeSeries series = new TimeSeries("Volume");
boolean non_zero_found = false;
if (rates != null) {
for (IRate rate : rates) {
Date date = new Date(rate.getTimestamp());
double vol = rate.getTotalVol();
series.addOrUpdate(new Hour(date), vol);
if (vol > 0)
non_zero_found = true;
}
}
if (non_zero_found == false)
return null;
TimeSeriesCollection dataset = new TimeSeriesCollection(series);
dataset.setDomainIsPointsInTime(true);
return dataset;
}
示例2: testAddOrUpdate4
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Some more checks for the addOrUpdate() method.
*/
public void testAddOrUpdate4() {
TimeSeries ts = new TimeSeries("S");
TimeSeriesDataItem overwritten = ts.addOrUpdate(new Year(2009), 20.09);
assertNull(overwritten);
overwritten = ts.addOrUpdate(new Year(2009), 1.0);
assertEquals(new Double(20.09), overwritten.getValue());
assertEquals(new Double(1.0), ts.getValue(new Year(2009)));
// changing the overwritten record shouldn't affect the series
overwritten.setValue(null);
assertEquals(new Double(1.0), ts.getValue(new Year(2009)));
TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10);
overwritten = ts.addOrUpdate(item);
assertNull(overwritten);
assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
// changing the item that was added should not change the series
item.setValue(null);
assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
}
示例3: testGetMinY
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Some checks for the getMinY() method.
*/
public void testGetMinY() {
TimeSeries s1 = new TimeSeries("S1");
assertTrue(Double.isNaN(s1.getMinY()));
s1.add(new Year(2008), 1.1);
assertEquals(1.1, s1.getMinY(), EPSILON);
s1.add(new Year(2009), 2.2);
assertEquals(1.1, s1.getMinY(), EPSILON);
s1.add(new Year(2000), 99.9);
assertEquals(1.1, s1.getMinY(), EPSILON);
s1.add(new Year(2002), -1.1);
assertEquals(-1.1, s1.getMinY(), EPSILON);
s1.add(new Year(2003), null);
assertEquals(-1.1, s1.getMinY(), EPSILON);
s1.addOrUpdate(new Year(2002), null);
assertEquals(1.1, s1.getMinY(), EPSILON);
}
示例4: testGetMaxY
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Some checks for the getMaxY() method.
*/
public void testGetMaxY() {
TimeSeries s1 = new TimeSeries("S1");
assertTrue(Double.isNaN(s1.getMaxY()));
s1.add(new Year(2008), 1.1);
assertEquals(1.1, s1.getMaxY(), EPSILON);
s1.add(new Year(2009), 2.2);
assertEquals(2.2, s1.getMaxY(), EPSILON);
s1.add(new Year(2000), 99.9);
assertEquals(99.9, s1.getMaxY(), EPSILON);
s1.add(new Year(2002), -1.1);
assertEquals(99.9, s1.getMaxY(), EPSILON);
s1.add(new Year(2003), null);
assertEquals(99.9, s1.getMaxY(), EPSILON);
s1.addOrUpdate(new Year(2000), null);
assertEquals(2.2, s1.getMaxY(), EPSILON);
}
示例5: addData
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* This method adds the specified stream elements to the timeSeries of the
* appropriate plot.
*
* @param streamElement
*/
public synchronized void addData ( StreamElement streamElement ) {
for ( int i = 0 ; i < streamElement.getFieldNames( ).length ; i++ ) {
TimeSeries timeSeries = dataForTheChart.get( streamElement.getFieldNames( )[ i ] );
if ( timeSeries == null ) {
dataForTheChart.put( streamElement.getFieldNames( )[ i ] , timeSeries = new TimeSeries( streamElement.getFieldNames( )[ i ] , org.jfree.data.time.FixedMillisecond.class ) );
if(isTimeBased){
timeSeries.setMaximumItemAge(historySize);
}else{
timeSeries.setMaximumItemCount(historySize);
}
dataCollectionForTheChart.addSeries( timeSeries );
}
try {
timeSeries.addOrUpdate( new FixedMillisecond( new Date( streamElement.getTimeStamp( ) ) ) , Double.parseDouble( streamElement.getData( )[ i ].toString( ) ) );
} catch ( SeriesException e ) {
logger.warn( e.getMessage( ) , e );
}
}
changed = true;
}
示例6: testAddOrUpdate
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Some checks for the addOrUpdate() method.
*/
public void testAddOrUpdate() {
TimeSeries s1 = new TimeSeries("S1", Year.class);
s1.setMaximumItemCount(2);
s1.addOrUpdate(new Year(2000), 100.0);
assertEquals(1, s1.getItemCount());
s1.addOrUpdate(new Year(2001), 101.0);
assertEquals(2, s1.getItemCount());
s1.addOrUpdate(new Year(2001), 102.0);
assertEquals(2, s1.getItemCount());
s1.addOrUpdate(new Year(2002), 103.0);
assertEquals(2, s1.getItemCount());
}
示例7: addItem
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
@Override
public void addItem(final Series series, final DataItem item)
{
final TimeSeries ns = (TimeSeries) series;
final long time = (long) item.getIndependentVal();
final Millisecond milli = new Millisecond(new Date(time));
ns.addOrUpdate(milli, item.getDependentVal());
}
示例8: createPriceDataset
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
private XYDataset createPriceDataset() {
List<IRate> rates = rateProvider.getRates(base, quote);
TimeSeries series = new TimeSeries("Price");
if (rates != null) {
for (IRate rate : rates) {
Date date = new Date(rate.getTimestamp());
series.addOrUpdate(new Hour(date), rate.getPrice());
}
}
TimeSeriesCollection dataset = new TimeSeriesCollection(series);
dataset.setDomainIsPointsInTime(true);
return dataset;
}
示例9: createPriceDataset
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
private XYDataset createPriceDataset() {
TimeSeries series = new TimeSeries("Price");
List<Trade> trades = Trade.getTrades(asset.getId());
for (Trade trade : trades) {
Date date = new Date(((trade.getTimestamp()) * 1000l)
+ (Constants.EPOCH_BEGINNING - 500L));
series.addOrUpdate(new Minute(date),
Double.valueOf(trade.getPrice()) / 100);
}
TimeSeriesCollection dataset = new TimeSeriesCollection(series);
dataset.setDomainIsPointsInTime(true);
return dataset;
}
示例10: testAddOrUpdate
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Some checks for the addOrUpdate() method.
*/
public void testAddOrUpdate() {
TimeSeries s1 = new TimeSeries("S1");
s1.setMaximumItemCount(2);
s1.addOrUpdate(new Year(2000), 100.0);
assertEquals(1, s1.getItemCount());
s1.addOrUpdate(new Year(2001), 101.0);
assertEquals(2, s1.getItemCount());
s1.addOrUpdate(new Year(2001), 102.0);
assertEquals(2, s1.getItemCount());
s1.addOrUpdate(new Year(2002), 103.0);
assertEquals(2, s1.getItemCount());
}
示例11: testAddOrUpdate2
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Test the add branch of the addOrUpdate() method.
*/
public void testAddOrUpdate2() {
TimeSeries s1 = new TimeSeries("S1");
s1.setMaximumItemCount(2);
s1.addOrUpdate(new Year(2010), 1.1);
s1.addOrUpdate(new Year(2011), 2.2);
s1.addOrUpdate(new Year(2012), 3.3);
assertEquals(2, s1.getItemCount());
assertEquals(2.2, s1.getMinY(), EPSILON);
assertEquals(3.3, s1.getMaxY(), EPSILON);
}
示例12: testAddOrUpdate3
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Test that the addOrUpdate() method won't allow multiple time period
* classes.
*/
public void testAddOrUpdate3() {
TimeSeries s1 = new TimeSeries("S1");
s1.addOrUpdate(new Year(2010), 1.1);
assertEquals(Year.class, s1.getTimePeriodClass());
boolean pass = false;
try {
s1.addOrUpdate(new Month(1, 2009), 0.0);
}
catch (SeriesException e) {
pass = true;
}
assertTrue(pass);
}
示例13: createTimeSeries
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
/**
* Create a time series.
*
* @param description
* Description for the series.
* @param series
* values of the series.
*/
protected TimeSeries createTimeSeries(String description,
DateValueSeries series) {
TimeSeries timeSeries = new TimeSeries(description);
Map<Date, Double> values = series.getValues();
for (Date date : CollectionUtils.sort(values.keySet())) {
RegularTimePeriod period = resolution.createTimePeriod(date);
double value = values.get(date);
timeSeries.addOrUpdate(period, value);
}
return timeSeries;
}
示例14: computeSingleTimeSeries
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
private TimeSeries computeSingleTimeSeries(InsituRecord[] insituRecords, String insituName) {
TimeSeries timeSeries = new TimeSeries(insituName);
for (InsituRecord insituRecord : insituRecords) {
final ProductData.UTC startTime = ProductData.UTC.create(insituRecord.time, 0);
final Millisecond timePeriod = new Millisecond(startTime.getAsDate(),
ProductData.UTC.UTC_TIME_ZONE,
Locale.getDefault());
timeSeries.addOrUpdate(timePeriod, insituRecord.value);
}
return timeSeries;
}
示例15: createChart
import org.jfree.data.time.TimeSeries; //導入方法依賴的package包/類
public JFreeChart createChart(Collection<Data> datas) {
TimeSeries t1 = new TimeSeries("S1");
Iterator<Data> iter = datas.iterator() ;
Data data ;
while (iter.hasNext()) {
data = iter.next();
t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long)data.getP2()), TimeZone.getDefault()), data.getValue());
}
XYDataset dataset = new TimeSeriesCollection(t1);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
null,
null,
null,
dataset,
false,
false,
false
);
chart.setAntiAlias(true);
chart.setTextAntiAlias(true);
chart.setBackgroundPaint(Color.WHITE);
//
XYPlot plot = (XYPlot) chart.getPlot();
plot.setNoDataMessage("No Data to Display");
plot.setDomainGridlinesVisible(true);
plot.setBackgroundPaint(Color.WHITE);
plot.setInsets(new RectangleInsets(5,14,0,5));
//
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(ssdf);
axis.setTickLabelFont(TICK_FONT);
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setTickLabelFont(TICK_FONT);
//
return chart;
}