use of org.jfree.chart.axis.CategoryAxis in project violations-plugin by jenkinsci.
the class SeverityTypeDataSet method createChart.
/**
* Create a JFree chart for this dataset.
*
* @return the chart.
*/
public JFreeChart createChart() {
CategoryDataset dataset = buildDataSet();
JFreeChart chart = // chart
ChartFactory.createStackedAreaChart(// 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();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(ALPHA);
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());
if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setAutoRangeMinimumSize(50);
}
StackedAreaRenderer renderer = new StackedAreaRenderer2();
plot.setRenderer(renderer);
renderer.setSeriesPaint(2, RED);
renderer.setSeriesPaint(1, VIOLET);
renderer.setSeriesPaint(0, YELLOW);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
return chart;
}
use of org.jfree.chart.axis.CategoryAxis in project hudson-2.x by hudson.
the class Job method getBuildTimeGraph.
public Graph getBuildTimeGraph() {
return new Graph(getLastBuild().getTimestamp(), 500, 400) {
@Override
protected JFreeChart createGraph() {
class ChartLabel implements Comparable<ChartLabel> {
final Run run;
public ChartLabel(Run r) {
this.run = r;
}
public int compareTo(ChartLabel that) {
return Run.ORDER_BY_DATE.compare(that.run, run);
}
@Override
public boolean equals(Object o) {
// on (c instanceof ChartLabel)
if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) {
return false;
}
ChartLabel that = (ChartLabel) o;
return run == that.run;
}
public Color getColor() {
// TODO: consider gradation. See
// http://www.javadrive.jp/java2d/shape/index9.html
Result r = run.getResult();
if (r == Result.FAILURE)
return ColorPalette.RED;
else if (r == Result.UNSTABLE)
return ColorPalette.YELLOW;
else if (r == Result.ABORTED || r == Result.NOT_BUILT)
return ColorPalette.GREY;
else
return ColorPalette.BLUE;
}
@Override
public int hashCode() {
return run.hashCode();
}
@Override
public String toString() {
String l = run.getDisplayName();
if (run instanceof Build) {
String s = ((Build) run).getBuiltOnStr();
if (s != null)
l += ' ' + s;
}
return l;
}
}
DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
for (Run r : getBuilds()) {
if (r.isBuilding())
continue;
data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
}
final CategoryDataset dataset = data.build();
final JFreeChart chart = // chart
ChartFactory.createStackedAreaChart(// chart
null, // unused
null, // range axis label
Messages.Job_minutes(), // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
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();
ChartUtil.adjustChebyshev(dataset, rangeAxis);
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
StackedAreaRenderer ar = new StackedAreaRenderer2() {
@Override
public Paint getItemPaint(int row, int column) {
ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
return key.getColor();
}
@Override
public String generateURL(CategoryDataset dataset, int row, int column) {
ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
return String.valueOf(label.run.number);
}
@Override
public String generateToolTip(CategoryDataset dataset, int row, int column) {
ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
return label.run.getDisplayName() + " : " + label.run.getDurationString();
}
};
plot.setRenderer(ar);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
return chart;
}
};
}
use of org.jfree.chart.axis.CategoryAxis in project libresonic by Libresonic.
the class UserChartController method createChart.
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
CategoryPlot plot = chart.getCategoryPlot();
Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
plot.setBackgroundPaint(background);
plot.setDomainGridlinePaint(Color.white);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.white);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
rangeAxis.setStrictValuesFlag(false);
rangeAxis.setAllowNegativesFlag(true);
plot.setRangeAxis(rangeAxis);
// Disable bar outlines.
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
// Set up gradient paint for series.
GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
renderer.setSeriesPaint(0, gp0);
// Rotate labels.
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
// Set theme-specific colors.
Color bgColor = getBackground(request);
Color fgColor = getForeground(request);
chart.setBackgroundPaint(bgColor);
domainAxis.setTickLabelPaint(fgColor);
domainAxis.setTickMarkPaint(fgColor);
domainAxis.setAxisLinePaint(fgColor);
rangeAxis.setTickLabelPaint(fgColor);
rangeAxis.setTickMarkPaint(fgColor);
rangeAxis.setAxisLinePaint(fgColor);
return chart;
}
use of org.jfree.chart.axis.CategoryAxis in project EnrichmentMapApp by BaderLab.
the class ChartUtil method createHeatStripsLegend.
@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int total = dataSets.size();
int v = total / -2;
for (int i = 0; i < total; i++) {
// Just to make sure there is always a bar for each data set name
if (v == 0.0)
v = 1;
dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
}
final JFreeChart chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(true);
domainAxis.setAxisLineVisible(false);
domainAxis.setTickMarksVisible(false);
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
domainAxis.setMaximumCategoryLabelLines(1);
domainAxis.setCategoryMargin(0.0);
if (total > 4) {
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
} else {
domainAxis.setMaximumCategoryLabelLines(2);
}
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
if (// UP, ZERO, DOWN:
colors == null || colors.size() < 3)
colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
List<Color> itemColors = new ArrayList<>();
for (int i = 0; i < total; i++) {
Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
itemColors.add(ColorUtil.getColor(n.doubleValue(), -total, total, colors.get(2), colors.get(1), colors.get(0)));
}
final BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(int row, int column) {
return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
}
};
plot.setRenderer(renderer);
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(true);
renderer.setShadowVisible(false);
renderer.setItemMargin(0.0);
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
return chart;
}
use of org.jfree.chart.axis.CategoryAxis in project jgnash by ccavanaugh.
the class BudgetSparkline method getSparklineImage.
public static Icon getSparklineImage(final List<BigDecimal> amounts) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
final boolean[] negate = new boolean[amounts.size()];
for (int i = 0; i < amounts.size(); i++) {
dataset.addValue(amounts.get(i), CATEGORY, i);
negate[i] = amounts.get(i).signum() == -1;
}
CategoryAxis xAxis = new CategoryAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarksVisible(false);
xAxis.setAxisLineVisible(false);
xAxis.setVisible(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickMarksVisible(false);
yAxis.setAxisLineVisible(false);
yAxis.setNegativeArrowVisible(false);
yAxis.setPositiveArrowVisible(false);
yAxis.setAutoRangeIncludesZero(true);
yAxis.setAutoRange(true);
yAxis.setVisible(false);
BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(final int row, final int column) {
return negate[column] ? Color.RED : Color.BLACK;
}
};
renderer.setShadowVisible(false);
renderer.setBarPainter(new StandardBarPainter());
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
plot.setInsets(INSETS);
plot.setDomainGridlinesVisible(false);
plot.setDomainCrosshairVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setRangeCrosshairVisible(false);
plot.setBackgroundPaint(CLEAR);
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBorderVisible(false);
chart.setBackgroundPaint(CLEAR);
Icon icon = EMPTY_ICON;
try {
byte[] image = ENCODER.encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
icon = new ImageIcon(image);
} catch (IOException ex) {
Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
}
return icon;
}
Aggregations