Java Code Examples for org.jfree.data.xy.XYDataset#getY()

The following examples show how to use org.jfree.data.xy.XYDataset#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XYChartHyperlinkProvider.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public JRPrintHyperlink getEntityHyperlink(ChartEntity entity)
{
	JRPrintHyperlink printHyperlink = null;
	if (hasHyperlinks() && entity instanceof XYItemEntity)
	{
		XYItemEntity itemEntity = (XYItemEntity) entity;
		XYDataset dataset = itemEntity.getDataset();
		Comparable<?> serie = dataset.getSeriesKey(itemEntity.getSeriesIndex());
		Map<Pair, JRPrintHyperlink> serieHyperlinks = itemHyperlinks.get(serie);
		if (serieHyperlinks != null)
		{
			Number x = dataset.getX(itemEntity.getSeriesIndex(), itemEntity.getItem());
			Number y = dataset.getY(itemEntity.getSeriesIndex(), itemEntity.getItem());
			Pair<Number,Number> xyKey = new Pair<Number,Number>(x, y);
			printHyperlink = serieHyperlinks.get(xyKey);
		}
	}
	return printHyperlink;
}
 
Example 2
Source File: FormulaXYZURLGenerator.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Generates a URL for a particular item within a series.
 *
 * @param dataset the dataset.
 * @param series  the series number (zero-based index).
 * @param item    the item number (zero-based index).
 * @return The generated URL.
 */
public String generateURL( final XYDataset dataset, final int series, final int item ) {
  if ( dataset instanceof XYZDataset ) {
    return generateURL( (XYZDataset) dataset, series, item );
  }
  try {
    final Object[] values = new Object[] {
      dataset.getX( series, item ), dataset.getY( series, item ), null,
      IntegerCache.getInteger( series ), dataset.getSeriesKey( series ),
      IntegerCache.getInteger( dataset.getSeriesCount() ),
      IntegerCache.getInteger( item ), IntegerCache.getInteger( dataset.getItemCount( series ) )
    };
    formulaExpression.setRuntime( new WrapperExpressionRuntime
      ( new StaticDataRow( ADDITIONAL_COLUMN_KEYS, values ), runtime ) );
    final Object o = formulaExpression.getValue();
    if ( o == null ) {
      return null;
    }
    return String.valueOf( o );
  } finally {
    formulaExpression.setRuntime( null );
  }
}
 
Example 3
Source File: AbstractXYItemLabelGenerator.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 4
Source File: AbstractXYItemLabelGenerator.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 5
Source File: AbstractXYItemLabelGenerator.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 6
Source File: AbstractXYItemLabelGenerator.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 7
Source File: XYItemLabelGenerator.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
protected Object[] createItemArray(XYDataset dataset, int series, int item) {
	Object[] result = new Object[5];
	result[0] = dataset.getSeriesKey(series).toString();
	
	double x = dataset.getXValue(series, item);
	if (Double.isNaN(x) && dataset.getX(series, item) == null) {
		result[1] = "null";	//this.nullXString;
	}
	else {
		if (this.getXDateFormat() != null) {
			result[1] = this.getXDateFormat().format(new Date((long) x));   
		}
		else {
			result[1] = this.getXFormat().format(x);
		}
	}
	
	double y = dataset.getYValue(series, item);
	if (Double.isNaN(y) && dataset.getY(series, item) == null) {
		result[2] = "null";	//this.nullYString;
	}
	else {
		if (this.getYDateFormat() != null) {
			result[2] = this.getYDateFormat().format(new Date((long) y));   
		}
		else {
			result[2] = this.getYFormat().format(y);
		}
		double total = calculateYTotal(dataset, series);
		double percent = y / total;
		result[3] = NumberFormat.getPercentInstance().format(percent);
		if (this.getYFormat() != null) {
			result[4] = this.getYFormat().format(total);
		}
		else if (this.getYDateFormat() != null) {
			//result[4] = this.getDateFormat().format(total);
		}
	}
	return result;
}
 
Example 8
Source File: XYURLGenerator.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a URL for a particular item within a series.
 * 
 * @param dataset
 *          the dataset.
 * @param series
 *          the series index (zero-based).
 * @param category
 *          the category index (zero-based).
 * 
 * @return The generated URL.
 */
@SuppressWarnings("deprecation")
public String generateURL(XYDataset dataset, int series, int item) {
	String seriesKey = dataset.getSeriesKey(series).toString();
	Number xValue = dataset.getX(series, item);
	Number yValue = dataset.getY(series, item);
	String value;
	if (yValue == null)
		value = "";
	else if (dateFormat != null)
		value = this.dateFormat.format(yValue);
	else
		value = this.numberFormat.format(yValue);

	StringBuilder generatedURL = new StringBuilder(urlLower.length());
	for (int i = 0; i < urlLower.length();) {
		char ch = urlLower.charAt(i);
		if (ch == '$') {
			if (urlLower.regionMatches(i, "$serieslabel$", 0, "$serieslabel$".length())) {
				generatedURL.append(URLEncoder.encode(seriesKey));
				i = i + "$serieslabel$".length();
			} else if (urlLower.regionMatches(i, "$itemlabel$", 0, "$itemlabel$".length())) {
				generatedURL.append(xValue);
				i = i + "$itemlabel$".length();
			} else if (urlLower.regionMatches(i, "$value$", 0, "$value$".length())) {
				generatedURL.append(value);
				i = i + "$value$".length();
			} else {
				// Preserve case by retrieving char from original URL
				generatedURL.append(url.charAt(i));
				i++;
			}
		} else {
			// Preserve case by retrieving char from original URL
			generatedURL.append(url.charAt(i));
			i++;
		}
	}
	return generatedURL.toString();
}
 
Example 9
Source File: AbstractXYItemLabelGenerator.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 10
Source File: AbstractXYItemLabelGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 11
Source File: AbstractXYItemLabelGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series, 
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();
    
    double x = dataset.getXValue(series, item);
    if (Double.isNaN(x) && dataset.getX(series, item) == null) {
        result[1] = this.nullXString;
    }
    else {
        if (this.xDateFormat != null) {
            result[1] = this.xDateFormat.format(new Date((long) x));   
        }
        else {
            result[1] = this.xFormat.format(x);
        }
    }
    
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));   
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 12
Source File: AbstractXYItemLabelGenerator.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series,
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (this.xDateFormat != null) {
        result[1] = this.xDateFormat.format(new Date((long) x));
    }
    else {
        result[1] = this.xFormat.format(x);
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 13
Source File: AbstractXYItemLabelGenerator.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of three items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
protected Object[] createItemArray(XYDataset dataset, int series, 
                                   int item) {
    Object[] result = new Object[3];
    result[0] = dataset.getSeriesKey(series).toString();
    
    double x = dataset.getXValue(series, item);
    if (Double.isNaN(x) && dataset.getX(series, item) == null) {
        result[1] = this.nullXString;
    }
    else {
        if (this.xDateFormat != null) {
            result[1] = this.xDateFormat.format(new Date((long) x));   
        }
        else {
            result[1] = this.xFormat.format(x);
        }
    }
    
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = this.nullYString;
    }
    else {
        if (this.yDateFormat != null) {
            result[2] = this.yDateFormat.format(new Date((long) y));   
        }
        else {
            result[2] = this.yFormat.format(y);
        }
    }
    return result;
}
 
Example 14
Source File: MovingAverage.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source,
        int series, String name, double period, double skip) {

    ParamChecks.nullNotPermitted(source, "source");
    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");
    }
    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");
    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 15
Source File: MovingAverage.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source,
        int series, String name, double period, double skip) {

    ParamChecks.nullNotPermitted(source, "source");
    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");
    }
    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");
    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 16
Source File: MovingAverage.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one 
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source, 
                                           int series, String name,
                                           double period, double skip) {

                                           
    // check arguments
    if (source == null) {
        throw new IllegalArgumentException("Null source (XYDataset).");
    }

    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");

    }

    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");

    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then 
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 17
Source File: MovingAverage.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source,
        int series, String name, double period, double skip) {

    if (source == null) {
        throw new IllegalArgumentException("Null source (XYDataset).");
    }
    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");
    }
    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");
    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 18
Source File: MovingAverage.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source,
        int series, String name, double period, double skip) {

    ParamChecks.nullNotPermitted(source, "source");
    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");
    }
    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");
    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 19
Source File: MovingAverage.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new {@link XYSeries} containing the moving averages of one
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset.
 * @param series  the series index (zero based).
 * @param name  the name for the new series.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYSeries createMovingAverage(XYDataset source,
        int series, String name, double period, double skip) {

    ParamChecks.nullNotPermitted(source, "source");
    if (period < Double.MIN_VALUE) {
        throw new IllegalArgumentException("period must be positive.");
    }
    if (skip < 0.0) {
        throw new IllegalArgumentException("skip must be >= 0.0.");
    }

    XYSeries result = new XYSeries(name);

    if (source.getItemCount(series) > 0) {

        // if the initial averaging period is to be excluded, then
        // calculate the lowest x-value to have an average calculated...
        double first = source.getXValue(series, 0) + skip;

        for (int i = source.getItemCount(series) - 1; i >= 0; i--) {

            // get the current data item...
            double x = source.getXValue(series, i);

            if (x >= first) {
                // work out the average for the earlier values...
                int n = 0;
                double sum = 0.0;
                double limit = x - period;
                int offset = 0;
                boolean finished = false;

                while (!finished) {
                    if ((i - offset) >= 0) {
                        double xx = source.getXValue(series, i - offset);
                        Number yy = source.getY(series, i - offset);
                        if (xx > limit) {
                            if (yy != null) {
                                sum = sum + yy.doubleValue();
                                n = n + 1;
                            }
                        }
                        else {
                            finished = true;
                        }
                    }
                    else {
                        finished = true;
                    }
                    offset = offset + 1;
                }
                if (n > 0) {
                    result.add(x, sum / n);
                }
                else {
                    result.add(x, null);
                }
            }

        }
    }

    return result;

}
 
Example 20
Source File: LogXYItemLabelGenerator.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Creates the array of items that can be passed to the {@link java.text.MessageFormat} class for creating labels.
 *
 * @param dataset the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item    the item (zero-based index).
 * @return An array of three items from the dataset formatted as <code>String</code> objects (never
 * <code>null</code>).
 */
protected Object[] createItemArray( final XYDataset dataset, final int series, final int item ) {
  final Object[] objects = super.createItemArray( dataset, series, item );
  final Number value = dataset.getY( series, item );
  objects[ 2 ] = LogCategoryItemLabelGenerator.formatValue( value );
  return objects;
}