use of org.jfree.chart.plot.CategoryPlot in project violations-plugin by jenkinsci.
the class AbstractViolationsBuildAction method createChart.
// FIXME this should be in a utility class
protected JFreeChart createChart(CategoryDataset dataset) {
final JFreeChart chart = // chart
ChartFactory.createLineChart(// chart
null, // unused
null, // range axis label
"count", // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
if (useLog) {
final NumberAxis rangeAxis2 = new LogarithmicAxis("Log(y)");
plot.setRangeAxis(rangeAxis2);
}
// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
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());
// rangeAxis.setUpperBound(100);
if (Boolean.getBoolean(VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setAutoRangeMinimumSize(50);
} else {
rangeAxis.setLowerBound(0);
}
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setStroke(new BasicStroke(2.0f));
ColorPalette.apply(renderer);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(PADDING, 0, 0, PADDING));
return chart;
}
use of org.jfree.chart.plot.CategoryPlot 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.plot.CategoryPlot in project gephi by gephi.
the class ChartsUtils method buildBoxPlot.
/**
* Build a new box-plot from an array of numbers using a default title and yLabel.
* String dataName will be used for xLabel.
* @param numbers Numbers for building box-plot
* @param dataName Name of the numbers data
* @return Prepared box-plot
*/
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
if (numbers == null || numbers.length == 0) {
return null;
}
DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
final ArrayList<Number> list = new ArrayList<>();
list.addAll(Arrays.asList(numbers));
final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
dataset.add(list, valuesString, "");
final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
renderer.setMeanVisible(false);
renderer.setFillBox(false);
renderer.setMaximumBarWidth(0.5);
final CategoryAxis xAxis = new CategoryAxis(dataName);
final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
yAxis.setAutoRangeIncludesZero(false);
renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
plot.setRenderer(renderer);
JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
return boxPlot;
}
use of org.jfree.chart.plot.CategoryPlot in project hudson-2.x by hudson.
the class LoadStatistics method createChart.
/**
* Creates a trend chart.
*/
public JFreeChart createChart(CategoryDataset ds) {
final JFreeChart chart = // chart title
ChartFactory.createLineChart(// chart title
null, // unused
null, // range axis label
null, // data
ds, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseStroke(new BasicStroke(3));
configureRenderer(renderer);
final CategoryAxis domainAxis = new NoOverlapCategoryAxis(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());
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
return chart;
}
use of org.jfree.chart.plot.CategoryPlot in project ice by Netflix.
the class BasicWeeklyCostEmailService method createImage.
private File createImage(ApplicationGroup appgroup) throws IOException {
Map<String, Double> costs = Maps.newHashMap();
DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
Interval interval = new Interval(end.minusWeeks(numWeeks), end);
for (Product product : products) {
List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
if (resourceGroups.size() == 0) {
continue;
}
DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
if (dataManager == null) {
continue;
}
TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups);
Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false);
for (Tag tag : data.keySet()) {
for (int week = 0; week < numWeeks; week++) {
String key = tag + "|" + week;
if (costs.containsKey(key))
costs.put(key, data.get(tag)[week] + costs.get(key));
else
costs.put(key, data.get(tag)[week]);
}
}
}
boolean hasData = false;
for (Map.Entry<String, Double> entry : costs.entrySet()) {
if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
hasData = true;
break;
}
}
if (!hasData)
return null;
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (Product product : products) {
for (int week = 0; week < numWeeks; week++) {
String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
}
}
JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
renderer.setItemLabelAnchorOffset(10.0);
TextTitle title = chart.getTitle();
title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
return costFormatter.format(dataset.getValue(row, column));
}
});
renderer.setBaseItemLabelsVisible(true);
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setNumberFormatOverride(costFormatter);
BufferedImage image = chart.createBufferedImage(1200, 400);
File outputfile = File.createTempFile("awscost", "png");
ImageIO.write(image, "png", outputfile);
return outputfile;
}
Aggregations