本文整理汇总了Java中de.erichseifert.gral.data.DataSource.getColumnCount方法的典型用法代码示例。如果您正苦于以下问题:Java DataSource.getColumnCount方法的具体用法?Java DataSource.getColumnCount怎么用?Java DataSource.getColumnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.erichseifert.gral.data.DataSource
的用法示例。
在下文中一共展示了DataSource.getColumnCount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMapping
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Sets the mapping of data source columns to axis names. The column index
* is taken from the order of the axis names, i.e. the first column of
* {@code source} will be mapped to first element of {@code axisNames}.
* Axis names with value {@code null} will be ignored.
* @param source Data source.
* @param axisNames Sequence of axis names in the order of the columns.
*/
public void setMapping(DataSource source, String... axisNames) {
if (!contains(source)) {
throw new IllegalArgumentException(
"Data source does not exist in plot."); //$NON-NLS-1$
}
if (axisNames.length > source.getColumnCount()) {
throw new IllegalArgumentException(MessageFormat.format(
"Data source only has {0,number,integer} column, {1,number,integer} values given.", //$NON-NLS-1$
source.getColumnCount(), axisNames.length));
}
Map<Integer, String> columnToAxisMapping = new HashMap<>();
for (int col = 0; col < axisNames.length; col++) {
String axisName = axisNames[col];
if (axisName != null) {
columnToAxisMapping.put(col, axisName);
}
}
columnToAxisMappingByDataSource.put(source, columnToAxisMapping);
invalidateAxisExtrema();
}
示例2: write
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Stores the specified data source.
* @param data DataSource to be stored.
* @param output OutputStream to be written to.
* @throws IOException if writing the data failed
*/
public void write(DataSource data, OutputStream output) throws IOException {
Character separator = getSetting(SEPARATOR_CHAR);
OutputStreamWriter writer = new OutputStreamWriter(output);
int i = 0;
int colCount = data.getColumnCount();
for (Comparable<?> cell : data) {
writer.write(String.valueOf(cell));
int col = i % colCount;
if (col < colCount - 1) {
writer.write(separator);
} else {
writer.write("\r\n"); //$NON-NLS-1$
}
i++;
}
writer.close();
}
示例3: createBoxData
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Extracts statistics from the columns of an data source that are commonly
* used for box-and-whisker plots. The result is a new data source
* containing <i>column index</i>, <i>median</i>, <i>mininum</i>, <i>first
* quartile</i>, <i>third quartile</i>, and <i>maximum</i> for each column.
* @param data Original data source
* @return New data source with (columnIndex, median, min, quartile1,
* quartile3, max)
*/
@SuppressWarnings("unchecked")
public static DataSource createBoxData(DataSource data) {
if (data == null) {
throw new NullPointerException(
"Cannot extract statistics from null data source.");
}
DataTable stats = new DataTable(Integer.class, Double.class,
Double.class, Double.class, Double.class, Double.class);
// Generate statistical values for each column
for (int c = 0; c < data.getColumnCount(); c++) {
Column col = data.getColumn(c);
if (!col.isNumeric()) {
continue;
}
stats.add(
c + 1,
col.getStatistics(Statistics.MEDIAN),
col.getStatistics(Statistics.MIN),
col.getStatistics(Statistics.QUARTILE_1),
col.getStatistics(Statistics.QUARTILE_3),
col.getStatistics(Statistics.MAX)
);
}
return stats;
}
示例4: getColumnTypesFor
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
private List<Class<? extends Comparable<?>>> getColumnTypesFor(DataSource data) {
List<Class<? extends Comparable<?>>> columnTypes = new LinkedList<>();
for (int colIndex = 0; colIndex < data.getColumnCount(); colIndex++) {
Column<?> column = data.getColumn(colIndex);
if (column.isNumeric()) {
columnTypes.add(Double.class);
columnTypes.add(Double.class);
columnTypes.add(Boolean.class);
} else {
columnTypes.add(column.getType());
}
}
return columnTypes;
}
示例5: createRasterData
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Takes a matrix of values and creates a new data source that stores the
* values in (x, y, value) format.
* @param data Original data source with values in each cell.
* @return New data source with (x, y, value) columns
*/
@SuppressWarnings("unchecked")
public static DataSource createRasterData(DataSource data) {
if (data == null) {
throw new NullPointerException("Cannot convert null data source.");
}
DataTable coordsValueData =
new DataTable(Double.class, Double.class, Double.class);
// Generate pixel data with (x, y, value)
double min = ((Number) data.getRowStatistics(Statistics.MIN).
getColumnStatistics(Statistics.MIN).get(0, 0)).doubleValue();
double max = ((Number) data.getRowStatistics(Statistics.MAX).
getColumnStatistics(Statistics.MAX).get(0, 0)).doubleValue();
double range = max - min;
int i = 0;
for (Comparable<?> cell : data) {
int x = i%data.getColumnCount();
int y = -i/data.getColumnCount();
double v = Double.NaN;
if (cell instanceof Number) {
Number numericCell = (Number) cell;
v = (numericCell.doubleValue() - min) / range;
}
coordsValueData.add((double) x, (double) y, v);
i++;
}
return coordsValueData;
}
示例6: write
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Stores the specified data source.
* @param data DataSource to be stored.
* @param output OutputStream to be written to.
* @throws IOException if writing the data failed
*/
public void write(DataSource data, OutputStream output) throws IOException {
int w = data.getColumnCount();
int h = data.getRowCount();
double factor = this.<Number>getSetting("factor").doubleValue(); //$NON-NLS-1$
double offset = this.<Number>getSetting("offset").doubleValue(); //$NON-NLS-1$
byte[] pixelData = new byte[w*h];
int pos = 0;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
Comparable<?> cell = data.get(x, y);
if (!(cell instanceof Number)) {
continue;
}
Number numericCell = (Number) cell;
double value = numericCell.doubleValue()*factor + offset;
byte v = (byte) Math.round(MathUtils.limit(value, 0.0, 255.0));
pixelData[pos++] = v;
}
}
BufferedImage image =
new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
image.getRaster().setDataElements(0, 0, w, h, pixelData);
Iterator<javax.imageio.ImageWriter> writers =
ImageIO.getImageWritersByMIMEType(getMimeType());
try {
javax.imageio.ImageWriter writer = writers.next();
writer.setOutput(ImageIO.createImageOutputStream(output));
writer.write(image);
} catch (NoSuchElementException e) {
throw new IOException(MessageFormat.format(
"No writer found for MIME type {0}.", getMimeType())); //$NON-NLS-1$
}
}
示例7: getMapping
import de.erichseifert.gral.data.DataSource; //导入方法依赖的package包/类
/**
* Returns the mapping of data source columns to axis names. The elements
* of returned array equal the column indexes, i.e. the first element (axis
* name) matches the first column of {@code source}. If no mapping exists
* {@code null} will be stored in the array.
* @param source Data source.
* @return Array containing axis names in the order of the columns,
* or {@code null} if no mapping exists for the column.
*/
public String[] getMapping(DataSource source) {
String[] mapping = new String[source.getColumnCount()];
for (int col = 0; col < mapping.length; col++) {
mapping[col] = getMapping(source, col);
}
return mapping;
}