本文整理匯總了Java中org.jfree.chart.plot.CategoryPlot.setDataset方法的典型用法代碼示例。如果您正苦於以下問題:Java CategoryPlot.setDataset方法的具體用法?Java CategoryPlot.setDataset怎麽用?Java CategoryPlot.setDataset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jfree.chart.plot.CategoryPlot
的用法示例。
在下文中一共展示了CategoryPlot.setDataset方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visualizarSerieChartAsignRescateVict
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
public void visualizarSerieChartAsignRescateVict(Color color,CategoryDataset dataset) {
ChartPanel chartPanel = new ChartPanel(chartNotifAsigResc);
chartNotifAsigResc.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot) chartNotifAsigResc.getPlot();
plot.setBackgroundPaint(color);
plot.setDataset(dataset);
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));
setContentPane(chartPanel);
this.pack();
RefineryUtilities.centerFrameOnScreen(this);
this.setVisible(true);
}
示例2: testReplaceDataset
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的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: testReplaceDataset
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的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);
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);
}
示例4: testReplaceDataset
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的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);
}
示例5: testReplaceDataset
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的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);
}
示例6: testAutoRange3
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* A simple test for the auto-range calculation looking at a
* NumberAxis used as the range axis for a CategoryPlot. In this
* case, the 'autoRangeIncludesZero' flag is set to false AND the
* original dataset is replaced with a new dataset.
*/
public void testAutoRange3() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(100.0, "Row 1", "Column 1");
dataset.setValue(200.0, "Row 1", "Column 2");
JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
"Value", dataset, PlotOrientation.VERTICAL, false, false,
false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
NumberAxis axis = (NumberAxis) plot.getRangeAxis();
axis.setAutoRangeIncludesZero(false);
assertEquals(axis.getLowerBound(), 95.0, EPSILON);
assertEquals(axis.getUpperBound(), 205.0, EPSILON);
// now replacing the dataset should update the axis range...
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(900.0, "Row 1", "Column 1");
dataset2.setValue(1000.0, "Row 1", "Column 2");
plot.setDataset(dataset2);
assertEquals(axis.getLowerBound(), 895.0, EPSILON);
assertEquals(axis.getUpperBound(), 1005.0, EPSILON);
}
示例7: testAxisRange
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* A test for a bug reported in the forum.
*/
public void testAxisRange() {
DefaultCategoryDataset datasetA = new DefaultCategoryDataset();
DefaultCategoryDataset datasetB = new DefaultCategoryDataset();
datasetB.addValue(50.0, "R1", "C1");
datasetB.addValue(80.0, "R1", "C1");
CategoryPlot plot = new CategoryPlot(
datasetA, new CategoryAxis(null), new NumberAxis(null), new LineAndShapeRenderer()
);
plot.setDataset(1, datasetB);
plot.setRenderer(1, new LineAndShapeRenderer());
Range r = plot.getRangeAxis().getRange();
assertEquals(84.0, r.getUpperBound(), 0.00001);
}
示例8: testDrawWithNullInfo2
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* Draws the chart with a <code>null</code> info object to make sure that
* no exceptions are thrown (a problem that was occurring at one point).
*/
public void testDrawWithNullInfo2() {
boolean success = false;
try {
JFreeChart chart = createGanttChart();
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setDataset(createDataset());
/* BufferedImage img =*/ chart.createBufferedImage(300, 200, null);
success = true;
}
catch (NullPointerException e) {
success = false;
}
assertTrue(success);
}
示例9: testReplaceDataset
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* Replaces the chart's dataset and then checks that the new dataset is OK.
*/
public void testReplaceDataset() {
LocalListener l = new LocalListener();
this.chart.addChangeListener(l);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
plot.setDataset(null);
assertEquals(true, l.flag);
}
示例10: testAxisRange
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* A test for a bug reported in the forum.
*/
public void testAxisRange() {
DefaultCategoryDataset datasetA = new DefaultCategoryDataset();
DefaultCategoryDataset datasetB = new DefaultCategoryDataset();
datasetB.addValue(50.0, "R1", "C1");
datasetB.addValue(80.0, "R1", "C1");
CategoryPlot plot = new CategoryPlot(datasetA, new CategoryAxis(null),
new NumberAxis(null), new LineAndShapeRenderer());
plot.setDataset(1, datasetB);
plot.setRenderer(1, new LineAndShapeRenderer());
Range r = plot.getRangeAxis().getRange();
assertEquals(84.0, r.getUpperBound(), 0.00001);
}
示例11: test1169972
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* A test for bug report 1169972.
*/
public void test1169972() {
CategoryPlot plot = new CategoryPlot(null, null, null, null);
plot.setDomainAxis(new CategoryAxis("C"));
plot.setRangeAxis(new NumberAxis("Y"));
plot.setRenderer(new BarRenderer());
plot.setDataset(new DefaultCategoryDataset());
assertTrue(plot != null);
}
示例12: createChart
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
private JFreeChart createChart() {
if (data.getItemCount() > 0) {
// get cumulative percentages
KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);
CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(
"Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data);
// create the chart...
final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
this.dataTable.getColumnName(this.groupByColumn), // domain axis label
"Count", // range axis label
categoryDataset, // data
PlotOrientation.VERTICAL, true, // include legend
true, false);
// set the background color for the chart...
chart.setBackgroundPaint(Color.WHITE);
// get a reference to the plot for further customization...
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLowerMargin(0.02);
domainAxis.setUpperMargin(0.02);
domainAxis.setLabelFont(LABEL_FONT_BOLD);
domainAxis.setTickLabelFont(LABEL_FONT);
// set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
rangeAxis.setLabelFont(LABEL_FONT_BOLD);
rangeAxis.setTickLabelFont(LABEL_FONT);
// second data set (cumulative percentages)
CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative);
LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker());
NumberAxis axis2 = new NumberAxis("Percent of " + countValue);
axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
axis2.setLabelFont(LABEL_FONT_BOLD);
axis2.setTickLabelFont(LABEL_FONT);
plot.setRangeAxis(1, axis2);
plot.setDataset(1, dataset2);
plot.setRenderer(1, renderer2);
plot.mapDatasetToRangeAxis(1, 1);
axis2.setTickUnit(new NumberTickUnit(0.1));
// show grid lines
plot.setRangeGridlinesVisible(true);
// bring cumulative line to front
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
if (isLabelRotating()) {
domainAxis.setTickLabelsVisible(true);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
}
return chart;
} else {
return null;
}
}
示例13: testAutoRange4
import org.jfree.chart.plot.CategoryPlot; //導入方法依賴的package包/類
/**
* A check for the interaction between the 'autoRangeIncludesZero' flag
* and the base setting in the BarRenderer.
*/
public void testAutoRange4() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(100.0, "Row 1", "Column 1");
dataset.setValue(200.0, "Row 1", "Column 2");
JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",
"Value", dataset, PlotOrientation.VERTICAL, false, false,
false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
NumberAxis axis = (NumberAxis) plot.getRangeAxis();
axis.setAutoRangeIncludesZero(false);
BarRenderer br = (BarRenderer) plot.getRenderer();
br.setIncludeBaseInRange(false);
assertEquals(95.0, axis.getLowerBound(), EPSILON);
assertEquals(205.0, axis.getUpperBound(), EPSILON);
br.setIncludeBaseInRange(true);
assertEquals(0.0, axis.getLowerBound(), EPSILON);
assertEquals(210.0, axis.getUpperBound(), EPSILON);
axis.setAutoRangeIncludesZero(true);
assertEquals(0.0, axis.getLowerBound(), EPSILON);
assertEquals(210.0, axis.getUpperBound(), EPSILON);
br.setIncludeBaseInRange(true);
assertEquals(0.0, axis.getLowerBound(), EPSILON);
assertEquals(210.0, axis.getUpperBound(), EPSILON);
// now replacing the dataset should update the axis range...
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(900.0, "Row 1", "Column 1");
dataset2.setValue(1000.0, "Row 1", "Column 2");
plot.setDataset(dataset2);
assertEquals(0.0, axis.getLowerBound(), EPSILON);
assertEquals(1050.0, axis.getUpperBound(), EPSILON);
br.setIncludeBaseInRange(false);
assertEquals(0.0, axis.getLowerBound(), EPSILON);
assertEquals(1050.0, axis.getUpperBound(), EPSILON);
axis.setAutoRangeIncludesZero(false);
assertEquals(895.0, axis.getLowerBound(), EPSILON);
assertEquals(1005.0, axis.getUpperBound(), EPSILON);
}