use of org.jfree.chart.renderer.category.StackedAreaRenderer in project java-examples by urvanov-ru.
the class MainClass method main.
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(new Dimension(600, 400));
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.6, "roKey1", "columnKey1");
dataset.addValue(0.3, "roKey1", "columnKey2");
dataset.addValue(2.3, "roKey1", "columnKey3");
JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
"Serial Data", // domain axis label
"Domain", // range axis label
"Range", // initial series
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips?
true, // URLs?
false);
// set chart background
chart.setBackgroundPaint(Color.white);
// set a few custom plot features
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(0xffffe0));
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.lightGray);
// set the plot's axes to display integers
// TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
// CategoryAxis domain = (CategoryAxis) plot.getDomainAxis();
// NumberAxis range = (NumberAxis) plot.getRangeAxis();
// range.setStandardTickUnits(ticks);
// render shapes and lines
StackedAreaRenderer renderer = new StackedAreaRenderer();
plot.setRenderer(renderer);
// set the renderer's stroke
// Stroke stroke = new BasicStroke(
// 3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
// renderer.setBaseOutlineStroke(stroke);
// label the points
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(2);
StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator(StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, format, format);
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(640, 480));
frame.add(chartPanel);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
use of org.jfree.chart.renderer.category.StackedAreaRenderer in project hudson-2.x by hudson.
the class AbstractTestResultAction method createChart.
private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {
final String relPath = getRelPath(req);
final JFreeChart chart = ChartFactory.createStackedAreaChart(// chart title
null, // unused
null, // range axis label
"count", // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart...
// final StandardLegend legend = (StandardLegend) chart.getLegend();
// legend.setAnchor(StandardLegend.SOUTH);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(0.8f);
// plot.setDomainGridlinesVisible(true);
// plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
StackedAreaRenderer ar = new StackedAreaRenderer2() {
@Override
public String generateURL(CategoryDataset dataset, int row, int column) {
NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
return relPath + label.build.getNumber() + "/testReport/";
}
@Override
public String generateToolTip(CategoryDataset dataset, int row, int column) {
NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
AbstractTestResultAction a = label.build.getAction(AbstractTestResultAction.class);
switch(row) {
case 0:
return String.valueOf(Messages.AbstractTestResultAction_fail(label.build.getDisplayName(), a.getFailCount()));
case 1:
return String.valueOf(Messages.AbstractTestResultAction_skip(label.build.getDisplayName(), a.getSkipCount()));
default:
return String.valueOf(Messages.AbstractTestResultAction_test(label.build.getDisplayName(), a.getTotalCount()));
}
}
};
plot.setRenderer(ar);
// Failures.
ar.setSeriesPaint(0, ColorPalette.RED);
// Skips.
ar.setSeriesPaint(1, ColorPalette.YELLOW);
// Total.
ar.setSeriesPaint(2, ColorPalette.BLUE);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
return chart;
}
use of org.jfree.chart.renderer.category.StackedAreaRenderer in project pentaho-platform by pentaho.
the class JFreeChartEngine method createAreaChart.
private static JFreeChart createAreaChart(final CategoryDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
String categoryAxisLabel = null;
String valueAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
AreaRenderer renderer = chartDefinition.isStacked() ? new StackedAreaRenderer() : new AreaRenderer();
if (tooltips) {
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
}
CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
Aggregations