use of org.jfree.chart.labels.ItemLabelPosition in project tdq-studio-se by Talend.
the class ChartDecorator method decorateBenfordLawChartByKCD.
/**
* Decorate the benford law chart. in this method the line chart will be overlay on top of bar chart.
*
* @param dataset
* @param barChart
* @param title
* @param categoryAxisLabel
* @param dotChartLabels
* @param formalValues
* @return JFreeChart
*/
@SuppressWarnings("deprecation")
public static JFreeChart decorateBenfordLawChartByKCD(CategoryDataset dataset, Object customerDataset, JFreeChart barChart, String title, String categoryAxisLabel, List<String> dotChartLabels, double[] formalValues) {
CategoryPlot barplot = barChart.getCategoryPlot();
decorateBarChart(barChart, new BenfordLawLineAndShapeRenderer());
// display percentage on top of the bar
DecimalFormat df = new DecimalFormat(PERCENT_FORMAT);
// $NON-NLS-1$
barplot.getRenderer().setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df));
barplot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
// set the display of Y axis
NumberAxis numAxis = (NumberAxis) barplot.getRangeAxis();
numAxis.setNumberFormatOverride(df);
CategoryDataset lineDataset = getLineDataset(dotChartLabels, formalValues);
JFreeChart lineChart = ChartFactory.createLineChart(null, title, categoryAxisLabel, lineDataset, PlotOrientation.VERTICAL, false, false, false);
CategoryPlot plot = lineChart.getCategoryPlot();
if (customerDataset != null) {
barplot.setDataset(2, new EncapsulationCumstomerDataset(dataset, customerDataset));
}
// show the value on the right axis of the chart(keep the comment)
// NumberAxis numberaxis = new NumberAxis(DefaultMessagesImpl.getString("TopChartFactory.Value"));
// plot.setRangeAxis(10, numberaxis);
NumberAxis vn = (NumberAxis) plot.getRangeAxis();
vn.setNumberFormatOverride(df);
// set points format
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setPaint(COLOR_LIST.get(1));
renderer.setSeriesShape(1, new Rectangle2D.Double(-1.5, -1.5, 3, 3));
// show the point shape
renderer.setShapesVisible(true);
// do not show the line
renderer.setBaseLinesVisible(false);
// add the bar chart into the line chart
CategoryItemRenderer barChartRender = barplot.getRenderer();
barplot.setDataset(0, lineDataset);
barplot.setRenderer(0, plot.getRenderer());
barplot.setDataset(1, dataset);
barplot.setRenderer(1, barChartRender);
return barChart;
}
use of org.jfree.chart.labels.ItemLabelPosition in project tdq-studio-se by Talend.
the class ChartDecorator method decorateBarChart.
/**
* create bar chart with customized bar render class which can be adapted in JFreeChart class.
*
* @param chart
* @param barRenderer
*/
public static void decorateBarChart(JFreeChart chart, BarRenderer barRenderer) {
CategoryPlot plot = chart.getCategoryPlot();
plot.getRangeAxis().setUpperMargin(0.08);
plot.setRangeGridlinesVisible(true);
barRenderer.setBaseItemLabelsVisible(true);
barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
barRenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
// MOD klliu 2010-09-25 bug15514: The chart of summary statistic indicators not beautiful
barRenderer.setMaximumBarWidth(0.1);
// renderer.setItemMargin(0.000000005);
// renderer.setBase(0.04);
// ADD yyi 2009-09-24 9243
barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(NEW_TOOL_TIP_FORMAT_STRING, NumberFormat.getInstance()));
// ADD TDQ-5251 msjian 2012-7-31: do not display the shadow
barRenderer.setShadowVisible(false);
// TDQ-5251~
// CategoryAxis domainAxis = plot.getDomainAxis();
// domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
plot.setRenderer(barRenderer);
}
use of org.jfree.chart.labels.ItemLabelPosition in project cytoscape-impl by cytoscape.
the class BarLayer method createChart.
@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
final JFreeChart chart;
if (type == BarChartType.STACKED)
chart = ChartFactory.createStackedBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, plotOrientation, // include legend
false, // tooltips
false, // urls
false);
else
chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, plotOrientation, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
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.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
if (showRangeZeroBaseline) {
plot.setRangeZeroBaselineVisible(true);
plot.setRangeZeroBaselinePaint(axisColor);
plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
}
final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(showDomainAxis);
domainAxis.setAxisLineStroke(axisStroke);
domainAxis.setAxisLinePaint(axisColor);
domainAxis.setTickMarkStroke(axisStroke);
domainAxis.setTickMarkPaint(axisColor);
domainAxis.setTickMarksVisible(true);
domainAxis.setTickLabelsVisible(true);
domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize));
domainAxis.setTickLabelPaint(axisColor);
domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
domainAxis.setCategoryMargin((type == BarChartType.STACKED || singleCategory) ? separation : 0.1);
domainAxis.setLowerMargin(.025);
domainAxis.setUpperMargin(.025);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(showRangeAxis);
rangeAxis.setAxisLineStroke(axisStroke);
rangeAxis.setAxisLinePaint(axisColor);
rangeAxis.setTickMarkStroke(axisStroke);
rangeAxis.setTickMarkPaint(axisColor);
rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
rangeAxis.setTickLabelPaint(axisColor);
rangeAxis.setLowerMargin(0.1);
rangeAxis.setUpperMargin(0.1);
// Set axis range
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
rangeAxis.setLowerBound(range.get(0));
rangeAxis.setUpperBound(range.get(1));
}
if (type != BarChartType.STACKED) {
if (type == BarChartType.HEAT_STRIPS || type == BarChartType.UP_DOWN) {
final Color up = (colors.size() > 0) ? colors.get(0) : Color.LIGHT_GRAY;
final Color zero = (colors.size() > 2) ? colors.get(1) : Color.BLACK;
final Color down = (colors.size() > 2) ? colors.get(2) : (colors.size() > 1 ? colors.get(1) : Color.GRAY);
plot.setRenderer(new UpDownColorBarRenderer(up, zero, down));
} else if (singleCategory) {
plot.setRenderer(new SingleCategoryRenderer());
}
}
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setBarPainter(new StandardBarPainter());
renderer.setShadowVisible(false);
renderer.setDrawBarOutline(true);
renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
renderer.setBaseItemLabelsVisible(showItemLabels);
renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
renderer.setBaseItemLabelPaint(labelColor);
renderer.setItemMargin(separation);
if (type != BarChartType.STACKED && showItemLabels) {
double angle = orientation == Orientation.HORIZONTAL ? 0 : -Math.PI / 2;
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, angle));
}
final BasicStroke borderStroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getRowKeys();
for (int i = 0; i < keys.size(); i++) {
renderer.setSeriesOutlineStroke(i, borderStroke);
renderer.setSeriesOutlinePaint(i, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
if (type != BarChartType.UP_DOWN && type != BarChartType.HEAT_STRIPS) {
Color c = DEFAULT_ITEM_BG_COLOR;
if (colors != null && colors.size() > i)
c = colors.get(i);
renderer.setSeriesPaint(i, c);
}
}
return chart;
}
use of org.jfree.chart.labels.ItemLabelPosition 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