com.ijchart.xychart.util
Class DatasetUtil

java.lang.Object
  extended by com.ijchart.xychart.util.DatasetUtil

public abstract class DatasetUtil
extends java.lang.Object

Title: IJChart

Description: a chart library for the Java(tm) platform.

A util class for dataset.

Copyright: Copyright (c) 2013

Company:

Version:
1.0
Author:
zhang feng min,shanghai china. Contract me by email.

Constructor Summary
DatasetUtil()
           
 
Method Summary
static double calculateDatasetTotalForPieChart(SingleRowDataset dataset)
           Calculates the total of all the values in a SingleRowDataset.If the dataset contains negative or null values, they are ignored.
static XYNumberChartData[] calculateDateMovingAverageDatas(java.util.List xyNumberData, int skipDays, int averageLen)
           Calculate the month moving average datas.
static XYNumberChartData[] calculateMovingAverageDatas(java.util.List xyNumberData, int skip, int averageLen)
           Calculate moving average datas.
static IntervalXYNumberChartData[] convertToHistogramData(double[] values, int bins, double minimum, double maximum, HistogramType type)
           Calculate histogram datas.
static IntervalXYNumberChartData[] convertToHistogramData(double[] values, int bins, HistogramType type)
           Calculate histogram datas.
static IMatrixDataset convertToHistogramDataset(IMatrixDataset dataset, int bins, double minimum, double maximum, HistogramType type)
           Convert a number dataset to histogram datasete.
static IMatrixDataset convertToHistogramDataset(IMatrixDataset dataset, int bins, HistogramType type)
           Convert a number dataset to histogram datasete.
static IMatrixDataset createMovingAverageOHLCDataset(IMatrixDataset sourceDataset, java.lang.String rowKeyPrefix, java.lang.String rowKeySuffix, int averageLen)
           Creates a new IMatrixDataset containing the moving averages of each series in the source dataset,and each data is OHLCChartData object in source dataset,
static int[] findDataPosition(IMatrixDataset dataset, IChartData data)
           Find the position for specified data.
static IChartData[] findMinAndMaxChartData(IMatrixDataset dataset)
           Find the minimum and maximum data of the dataset.
static XYNumberChartData[] getDatasByFunction(IFunction function, double start, double end, int samples)
           Calculate chart datas by a function.
static NumberRange getDatasetYRangeForStackBarRender(IMatrixDataset dataset)
           Calculate the range of y value,this dataset used for XYStackedBarRender.
static IChartData[] getMinAndMaxValue(IMatrixDataset dataset, java.util.Comparator comp)
           Calculate the minimum and maximum value of dataset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatasetUtil

public DatasetUtil()
Method Detail

getDatasetYRangeForStackBarRender

public static NumberRange getDatasetYRangeForStackBarRender(IMatrixDataset dataset)
Calculate the range of y value,this dataset used for XYStackedBarRender.

Parameters:
dataset - IMatrixDataset The dataset,each data is NumberChartData object in dataset.
Returns:
NumberRange The value range of a dataset (never null).

getMinAndMaxValue

public static IChartData[] getMinAndMaxValue(IMatrixDataset dataset,
                                             java.util.Comparator comp)
Calculate the minimum and maximum value of dataset.

Parameters:
dataset - IMatrixDataset The dataset.
comp - Comparator The comparator with which to determine the minimum element.A null value indicates that the elements' natural ordering should be used (null permitted).
Returns:
IChartData[] The data array (maybe null),first is minimum value,second is maximum value.

createMovingAverageOHLCDataset

public static IMatrixDataset createMovingAverageOHLCDataset(IMatrixDataset sourceDataset,
                                                            java.lang.String rowKeyPrefix,
                                                            java.lang.String rowKeySuffix,
                                                            int averageLen)
Creates a new IMatrixDataset containing the moving averages of each series in the source dataset,and each data is OHLCChartData object in source dataset,

Parameters:
sourceDataset - IMatrixDataset The source dataset (null permitted).
rowKeyPrefix - String The string to added in front of thesource rowKey to create new rowKey names (null permitted).
rowKeySuffix - String The string to append to source rowKey to create new rowKey names (null permitted).
averageLen - int The length of average datas.
Returns:
IMatrixDataset The new dataset,each data is DateNumberChartData object in new dataset.

findMinAndMaxChartData

public static IChartData[] findMinAndMaxChartData(IMatrixDataset dataset)
Find the minimum and maximum data of the dataset.

Parameters:
dataset - IMatrixDataset The dataset (null not permitted).
Returns:
IChartData[] The first is the minimum data,the second is the maximum data.

calculateDatasetTotalForPieChart

public static double calculateDatasetTotalForPieChart(SingleRowDataset dataset)
Calculates the total of all the values in a SingleRowDataset.If the dataset contains negative or null values, they are ignored.

Parameters:
dataset - SingleRowDataset The dataset (null not permitted).
Returns:
double The total of all the values.

convertToHistogramDataset

public static IMatrixDataset convertToHistogramDataset(IMatrixDataset dataset,
                                                       int bins,
                                                       HistogramType type)
Convert a number dataset to histogram datasete.

Parameters:
dataset - IMatrixDataset A dataset,each data is NumberChartData object in dataset. (null not permitted).
bins - int The number of bins,must be greater than 0.
type - HistogramType The histogram type (null not permitted).
Returns:
IMatrixDataset The result dataset.

convertToHistogramDataset

public static IMatrixDataset convertToHistogramDataset(IMatrixDataset dataset,
                                                       int bins,
                                                       double minimum,
                                                       double maximum,
                                                       HistogramType type)
Convert a number dataset to histogram datasete.

Parameters:
dataset - IMatrixDataset A dataset,each data is NumberChartData object in dataset. (null not permitted).
bins - int The number of bins,must be greater than 0.
minimum - double The lower bound of the bin range.
maximum - double The upper bound of the bin range.
type - HistogramType The histogram type (null not permitted).
Returns:
IMatrixDataset The result dataset.

convertToHistogramData

public static IntervalXYNumberChartData[] convertToHistogramData(double[] values,
                                                                 int bins,
                                                                 HistogramType type)
Calculate histogram datas.

Parameters:
values - double[] The values.
bins - int The number of bins,must be greater than 0.
type - HistogramType The histogram type (null not permitted).
Returns:
IMatrixDataset The result dataset.

convertToHistogramData

public static IntervalXYNumberChartData[] convertToHistogramData(double[] values,
                                                                 int bins,
                                                                 double minimum,
                                                                 double maximum,
                                                                 HistogramType type)
Calculate histogram datas.

Parameters:
values - double[] The values.
bins - int The number of bins,must be greater than 0.
minimum - double The lower bound of the bin range.
maximum - double The upper bound of the bin range.
type - HistogramType The histogram type (null not permitted).
Returns:
IMatrixDataset The result dataset.

getDatasByFunction

public static XYNumberChartData[] getDatasByFunction(IFunction function,
                                                     double start,
                                                     double end,
                                                     int samples)
Calculate chart datas by a function.

Parameters:
function - IFunction The function (null not permitted).
start - double The start value for the range.
end - double The end value for the range.
samples - int The number of sample points.
Returns:
XYNumberChartData[]

calculateMovingAverageDatas

public static XYNumberChartData[] calculateMovingAverageDatas(java.util.List xyNumberData,
                                                              int skip,
                                                              int averageLen)
Calculate moving average datas.

Parameters:
xyNumberData - List The list of XYNumberChartData data (null not permitted).
skip - int The number of datas to skip.
averageLen - int The length of average datas.
Returns:
XYNumberChartData[] The average datas.

calculateDateMovingAverageDatas

public static XYNumberChartData[] calculateDateMovingAverageDatas(java.util.List xyNumberData,
                                                                  int skipDays,
                                                                  int averageLen)
Calculate the month moving average datas.

Parameters:
xyNumberData - List The list of XYNumberChartData data (null not permitted).
skipDays - int The number of days to skip.
averageLen - int The length of average datas.
Returns:
XYNumberChartData[] The average datas.

findDataPosition

public static int[] findDataPosition(IMatrixDataset dataset,
                                     IChartData data)
Find the position for specified data.

Parameters:
dataset - IMatrixDataset The dataset,each data is NumberChartData object in dataset.
data - IChartData The specified data object (null permitted).
Returns:
int[] The length of the array is 2, the first value indicates the number of rows, the second value is the number of columns,or null if not found.