本文整理汇总了Java中org.jfree.chart.renderer.category.BarRenderer类的典型用法代码示例。如果您正苦于以下问题:Java BarRenderer类的具体用法?Java BarRenderer怎么用?Java BarRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BarRenderer类属于org.jfree.chart.renderer.category包,在下文中一共展示了BarRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureBarRenderer
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
private static void configureBarRenderer(BarRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
StandardBarPainter barPainter = new StandardBarPainter();
renderer.setBarPainter(barPainter);
renderer.setGradientPaintTransformer(null);
ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
int seriesCount = valueSourceData.getSeriesCount();
DimensionConfig domainConfig = valueSource.getDomainConfig();
DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
PlotDimension.COLOR);
SeriesFormat seriesFormat = valueSource.getSeriesFormat();
// Loop all series and set series format.
// Format based on dimension configs will be set later on in initFormatDelegate().
for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
// configure series paint if necessary
if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
}
// configure general style of the bars
renderer.setShadowVisible(false);
renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
}
renderer.setDrawBarOutline(true);
}
示例2: createBarChart
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Creates the histogram chart.
*
* @return
*/
private JFreeChart createBarChart() {
JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL,
false, false, false);
AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
chart.setBackgroundPaint(null);
chart.setBackgroundImageAlpha(0.0f);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
plot.setOutlineVisible(false);
plot.setRangeZeroBaselineVisible(false);
plot.setDomainGridlinesVisible(false);
plot.setBackgroundPaint(COLOR_INVISIBLE);
plot.setBackgroundImageAlpha(0.0f);
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL));
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(true);
renderer.setShadowVisible(false);
return chart;
}
示例3: createChart
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private static JFreeChart createChart(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart(
"Performance: JFreeSVG vs Batik", null /* x-axis label*/,
"Milliseconds" /* y-axis label */, dataset);
chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG "
+ "format (lower bars = better performance)"));
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
chart.getLegend().setFrame(BlockBorder.NONE);
return chart;
}
示例4: createChart
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private static JFreeChart createChart(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart(
"Performance: JFreeSVG vs Batik", null /* x-axis label*/,
"Milliseconds" /* y-axis label */, dataset, PlotOrientation.HORIZONTAL,false,false,false);
chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG "
+ "format (lower bars = better performance)"));
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
// ******************************************************************
// More than 150 demo applications are included with the JFreeChart
// Developer Guide...for more information, see:
//
// > http://www.object-refinery.com/jfreechart/guide.html
//
// ******************************************************************
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
// chart.getLegend().setFrame(BlockBorder.NONE);
return chart;
}
示例5: createPlot
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Creates a sample plot.
*
* @return A sample plot.
*/
private CombinedDomainCategoryPlot createPlot() {
CategoryDataset dataset1 = createDataset1();
NumberAxis rangeAxis1 = new NumberAxis("Value");
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
subplot1.setDomainGridlinesVisible(true);
CategoryDataset dataset2 = createDataset2();
NumberAxis rangeAxis2 = new NumberAxis("Value");
rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
subplot2.setDomainGridlinesVisible(true);
CategoryAxis domainAxis = new CategoryAxis("Category");
CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
plot.add(subplot1, 2);
plot.add(subplot2, 1);
return plot;
}
示例6: createPlot
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Creates a sample plot.
*
* @return A plot.
*/
private CombinedRangeCategoryPlot createPlot() {
CategoryDataset dataset1 = createDataset1();
NumberAxis rangeAxis1 = new NumberAxis("Value");
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
subplot1.setDomainGridlinesVisible(true);
CategoryDataset dataset2 = createDataset2();
NumberAxis rangeAxis2 = new NumberAxis("Value");
rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
subplot2.setDomainGridlinesVisible(true);
NumberAxis rangeAxis = new NumberAxis("Value");
CombinedRangeCategoryPlot plot = new CombinedRangeCategoryPlot(rangeAxis);
plot.add(subplot1, 2);
plot.add(subplot2, 1);
return plot;
}
示例7: testRangeMarkerIndices
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
@Test
public void testRangeMarkerIndices() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
// add a second dataset, plotted against a second axis
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(1, "R1", "C1");
plot.setDataset(99, dataset);
NumberAxis yAxis2 = new NumberAxis("Y2");
plot.setRangeAxis(1, yAxis2);
LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
plot.setRenderer(99, renderer2);
plot.mapDatasetToRangeAxis(99, 1);
ValueMarker yMarker1 = new ValueMarker(123);
plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND);
assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains(
yMarker1));
}
示例8: testDomainMarkerIndices
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
@Test
public void testDomainMarkerIndices() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
// add a second dataset, plotted against a second x axis
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(1, "R1", "C1");
plot.setDataset(99, dataset);
CategoryAxis xAxis2 = new CategoryAxis("X2");
plot.setDomainAxis(1, xAxis2);
LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
plot.setRenderer(99, renderer2);
plot.mapDatasetToDomainAxis(99, 1);
CategoryMarker xMarker1 = new CategoryMarker(123);
plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
xMarker1));
}
示例9: testSerialization
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Serialize an instance, restore it, and check for equality. In addition,
* test for a bug that was reported where the listener list is 'null' after
* deserialization.
*/
@Test
public void testSerialization() {
BarRenderer r1 = new BarRenderer();
r1.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 4));
r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.green));
r1.setBaseLegendShape(new Line2D.Double(1.0, 2.0, 3.0, 4.0));
BarRenderer r2 = (BarRenderer) TestUtilities.serialised(r1);
assertEquals(r1, r2);
try {
r2.notifyListeners(new RendererChangeEvent(r2));
}
catch (NullPointerException e) {
fail("No exception should be thrown."); // failed
}
}
示例10: testFillPaintLookup
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Some checks for the fill paint lookup mechanism.
*/
@Test
public void testFillPaintLookup() {
BarRenderer r = new BarRenderer();
assertEquals(Color.white, r.getBaseFillPaint());
// first check that autoPopulate==false works as expected
r.setAutoPopulateSeriesFillPaint(false);
assertEquals(Color.white, r.lookupSeriesFillPaint(0));
assertNull(r.getSeriesFillPaint(0));
// now check autoPopulate==true
r.setAutoPopulateSeriesFillPaint(true);
/*CategoryPlot plot =*/ new CategoryPlot(null, new CategoryAxis(
"Category"), new NumberAxis("Value"), r);
assertEquals(DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE[0],
r.lookupSeriesFillPaint(0));
assertNotNull(r.getSeriesFillPaint(0));
}
示例11: testGetRendererForDataset2
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
@Test
public void testGetRendererForDataset2() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
// add a second dataset
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(1, "R1", "C1");
plot.setDataset(99, dataset2);
// by default, the renderer with index 0 is used
assertEquals(renderer, plot.getRendererForDataset(dataset2));
// add a second renderer with the same index as dataset2, now it will
// be used
CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
plot.setRenderer(99, renderer2);
assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
示例12: testAxisIndices
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
@Test
public void testAxisIndices() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
assertEquals(xAxis, plot.getDomainAxis(0));
assertEquals(yAxis, plot.getRangeAxis(0));
CategoryAxis xAxis2 = new CategoryAxis("X2");
plot.setDomainAxis(99, xAxis2);
assertEquals(xAxis2, plot.getDomainAxis(99));
NumberAxis yAxis2 = new NumberAxis("Y2");
plot.setRangeAxis(99, yAxis2);
assertEquals(yAxis2, plot.getRangeAxis(99));
}
示例13: testDatasetIndices
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* Datasets are now stored in a Map, and it should be possible to assign
* them an arbitrary key (index).
*/
@Test
public void testDatasetIndices() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
assertEquals(dataset, plot.getDataset(0));
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(1, "R1", "C1");
// we should be able to give a dataset an arbitrary index
plot.setDataset(99, dataset2);
assertEquals(2, plot.getDatasetCount());
assertEquals(dataset2, plot.getDataset(99));
assertEquals(0, plot.indexOf(dataset));
assertEquals(99, plot.indexOf(dataset2));
}
示例14: testAxisLocationIndices
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
@Test
public void testAxisLocationIndices() {
CategoryDataset dataset = new DefaultCategoryDataset();
CategoryAxis xAxis = new CategoryAxis("X");
NumberAxis yAxis = new NumberAxis("Y");
CategoryItemRenderer renderer = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
CategoryAxis xAxis2 = new CategoryAxis("X2");
NumberAxis yAxis2 = new NumberAxis("Y2");
plot.setDomainAxis(99, xAxis2);
plot.setRangeAxis(99, yAxis2);
plot.setDomainAxisLocation(99, AxisLocation.BOTTOM_OR_RIGHT);
assertEquals(AxisLocation.BOTTOM_OR_RIGHT,
plot.getDomainAxisLocation(99));
plot.setRangeAxisLocation(99, AxisLocation.BOTTOM_OR_LEFT);
assertEquals(AxisLocation.BOTTOM_OR_LEFT,
plot.getRangeAxisLocation(99));
}
示例15: setMargins
import org.jfree.chart.renderer.category.BarRenderer; //导入依赖的package包/类
/**
* This method sets the width of the bars, and the spacing between the bars. It sets a general, hard coded standard for this. In JFreeChart, you
* cannot set the bar width. In stead, you set the gaps: - lowerMargin is the gap between the start of the x-axis and the first bar - upperMargin
* is the gap between the end of the x-axis and the last bar - categoryMargin is the gap between the categories. Note that the number you provide
* here, is divided over all the gaps. So if you set this margin to 0.5 (is 50%) and there are 6 categories, this means that there are 5 gaps, so
* each gap will get 10%. - itemMargin is the gap between the bars within a category. Again, this number is divided over all the itemgaps in the
* whole graph. The method also takes care that extreme cases (with a very small amount of bars) still look acceptable.
* @param plot
*/
private void setMargins(final CategoryPlot plot) {
final CategoryAxis axis = plot.getDomainAxis();
axis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 9));
final int categoryCount = plot.getCategories().size();
final int seriesCount = plot.getDataset().getRowCount();
axis.setCategoryMargin(0.23); // sets spacing between categories on x%
// set spacing between bars inside a catgory (in fractions, so 1 = 100%)
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
if (categoryCount == 1) {
renderer.setItemMargin(0.15);
} else {
renderer.setItemMargin(0.03);
}
// extreme cases
if (categoryCount * seriesCount < 4) {
final double outerMargins = (4.0 - (categoryCount * seriesCount)) / 10.0;
axis.setLowerMargin(outerMargins);
axis.setUpperMargin(outerMargins);
}
}