本文整理汇总了Java中org.jfree.data.category.CategoryDataset类的典型用法代码示例。如果您正苦于以下问题:Java CategoryDataset类的具体用法?Java CategoryDataset怎么用?Java CategoryDataset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CategoryDataset类属于org.jfree.data.category包,在下文中一共展示了CategoryDataset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCategoryDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Creates a {@link CategoryDataset} that contains a copy of the data in an
* array (instances of <code>Double</code> are created to represent the
* data items).
* <p>
* Row and column keys are created by appending 0, 1, 2, ... to the
* supplied prefixes.
*
* @param rowKeyPrefix the row key prefix.
* @param columnKeyPrefix the column key prefix.
* @param data the data.
*
* @return The dataset.
*/
public static CategoryDataset createCategoryDataset(String rowKeyPrefix,
String columnKeyPrefix,
double[][] data) {
DefaultCategoryDataset result = new DefaultCategoryDataset();
for (int r = 0; r < data.length; r++) {
String rowKey = rowKeyPrefix + (r + 1);
for (int c = 0; c < data[r].length; c++) {
String columnKey = columnKeyPrefix + (c + 1);
result.addValue(new Double(data[r][c]), rowKey, columnKey);
}
}
return result;
}
示例2: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the dataset and checks that it has changed as expected.
*/
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
"C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
plot.setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = plot.getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例3: getDataSet
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
private static CategoryDataset getDataSet() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "北京", "苹果");
dataset.addValue(100, "上海", "苹果");
dataset.addValue(100, "广州", "苹果");
dataset.addValue(200, "北京", "梨子");
dataset.addValue(200, "上海", "梨子");
dataset.addValue(200, "广州", "梨子");
dataset.addValue(300, "北京", "葡萄");
dataset.addValue(300, "上海", "葡萄");
dataset.addValue(300, "广州", "葡萄");
dataset.addValue(400, "北京", "香蕉");
dataset.addValue(400, "上海", "香蕉");
dataset.addValue(400, "广州", "香蕉");
dataset.addValue(500, "北京", "荔枝");
dataset.addValue(500, "上海", "荔枝");
dataset.addValue(500, "广州", "荔枝");
return dataset;
}
示例4: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the chart's dataset and then checks that the new dataset is OK.
*/
public void testReplaceDataset() {
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset(
"S", "C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
plot.setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = plot.getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例5: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the chart's dataset and then checks that the new dataset is OK.
*/
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
"C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
plot.setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = plot.getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例6: readCategoryDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Reads a {@link CategoryDataset} from a CSV file or input source.
*
* @param in the input source.
*
* @return a category dataset.
*
* @throws IOException if there is an I/O problem.
*/
public CategoryDataset readCategoryDataset(Reader in) throws IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
BufferedReader reader = new BufferedReader(in);
List columnKeys = null;
int lineIndex = 0;
String line = reader.readLine();
while (line != null) {
if (lineIndex == 0) { // first line contains column keys
columnKeys = extractColumnKeys(line);
}
else { // remaining lines contain a row key and data values
extractRowKeyAndData(line, dataset, columnKeys);
}
line = reader.readLine();
lineIndex++;
}
return dataset;
}
示例7: visualizarSeriesTiemposRescateVictPorRobots
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
public void visualizarSeriesTiemposRescateVictPorRobots(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart(
"Tiempos de Rescate de Victimas por cada robot ", // chart title
"Robots en el entorno", // domain axis label
"Tiempo milisegundos", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
ChartPanel chartPanel = new ChartPanel(chart);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setUpperMargin(0.15);
CategoryItemRenderer renderer = plot.getRenderer();
renderer.setItemLabelGenerator(new LabelGenerator(50.0));
renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 8));
renderer.setItemLabelsVisible(true);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
this.visualizar(chartPanel);
}
示例8: createLineChart3D
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Create a line chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createLineChart3D() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-3), new Integer(-2)},
{new Integer(-1), new Integer(1)},
{new Integer(2), new Integer(3)}};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
"C", data);
// create the chart...
return ChartFactory.createLineChart3D(
"Line Chart",
"Domain", "Range",
dataset,
PlotOrientation.HORIZONTAL,
true, // include legend
true,
true
);
}
示例9: createItemArray
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* 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 row the row index (zero-based).
* @param column the column index (zero-based).
*
* @return The items (never <code>null</code>).
*/
protected Object[] createItemArray(CategoryDataset dataset,
int row, int column) {
Object[] result = new Object[4];
result[0] = dataset.getRowKey(row).toString();
result[1] = dataset.getColumnKey(column).toString();
Number value = dataset.getValue(row, column);
if (value != null) {
if (this.numberFormat != null) {
result[2] = this.numberFormat.format(value);
}
else if (this.dateFormat != null) {
result[2] = this.dateFormat.format(value);
}
}
else {
result[2] = this.nullValueString;
}
if (value != null) {
double total = DataUtilities.calculateColumnTotal(dataset, column);
double percent = value.doubleValue() / total;
result[3] = this.percentFormat.format(percent);
}
return result;
}
示例10: createCategoryDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Creates a {@link CategoryDataset} by copying the data from the supplied {@link KeyedValues}
* instance.
*
* @param rowKey the row key (<code>null</code> not permitted).
* @param rowData the row data (<code>null</code> not permitted).
*
* @return A dataset.
*/
public static CategoryDataset createCategoryDataset(String rowKey,
KeyedValues rowData) {
if (rowKey == null) {
throw new IllegalArgumentException("Null 'rowKey' argument.");
}
if (rowData == null) {
throw new IllegalArgumentException("Null 'rowData' argument.");
}
DefaultCategoryDataset result = new DefaultCategoryDataset();
for (int i = 0; i < rowData.getItemCount(); i++) {
result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i));
}
return result;
}
示例11: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the dataset and checks that the data range is as expected.
*/
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
this.chart.getCategoryPlot().setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = this.chart.getCategoryPlot().getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例12: createBarChart3D
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Create a horizontal bar chart with sample data in the range -3 to +3.
*
* @return the chart.
*/
private static JFreeChart createBarChart3D() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-3), new Integer(-2)},
{new Integer(-1), new Integer(1)},
{new Integer(2), new Integer(3)}};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data);
// create the chart...
return ChartFactory.createBarChart3D(
"Bar Chart 3D",
"Domain",
"Range",
dataset,
PlotOrientation.HORIZONTAL,
true, // include legend
true,
false
);
}
示例13: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the dataset and checks that it has changed as expected.
*/
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
this.chart.getCategoryPlot().setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = this.chart.getCategoryPlot().getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例14: testReplaceDataset
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Replaces the chart's dataset and then checks that the new dataset is OK.
*/
public void testReplaceDataset() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-30), new Integer(-20)},
{new Integer(-10), new Integer(10)},
{new Integer(20), new Integer(30)}};
CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
this.chart.getCategoryPlot().setDataset(newData);
assertEquals(true, l.flag);
ValueAxis axis = this.chart.getCategoryPlot().getRangeAxis();
Range range = axis.getRange();
assertTrue("Expecting the lower bound of the range to be around -30: "
+ range.getLowerBound(), range.getLowerBound() <= -30);
assertTrue("Expecting the upper bound of the range to be around 30: "
+ range.getUpperBound(), range.getUpperBound() >= 30);
}
示例15: isEmptyOrNull
import org.jfree.data.category.CategoryDataset; //导入依赖的package包/类
/**
* Returns <code>true</code> if the dataset is empty (or <code>null</code>),
* and <code>false</code> otherwise.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @return A boolean.
*/
public static boolean isEmptyOrNull(CategoryDataset dataset) {
if (dataset == null) {
return true;
}
int rowCount = dataset.getRowCount();
int columnCount = dataset.getColumnCount();
if (rowCount == 0 || columnCount == 0) {
return true;
}
for (int r = 0; r < rowCount; r++) {
for (int c = 0; c < columnCount; c++) {
if (dataset.getValue(r, c) != null) {
return false;
}
}
}
return true;
}