use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChart.
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
private JFreeChart getJFreeChart(PlotData plotData) {
final CategoryDataset[] dataSets = getCategoryDataSet(plotData);
final CategoryDataset dataSet = dataSets[0];
final BarRenderer barRenderer = getBarRenderer();
final LineAndShapeRenderer lineRenderer = getLineRenderer();
// ---------------------------------------------------------------------
// Plot
// ---------------------------------------------------------------------
CategoryPlot plot;
if (plotData.isType(VisualizationType.LINE.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (plotData.isType(VisualizationType.COLUMN.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.VERTICAL);
} else if (plotData.isType(VisualizationType.BAR.name())) {
plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
plot.setOrientation(PlotOrientation.HORIZONTAL);
} else if (plotData.isType(VisualizationType.AREA.name())) {
return getStackedAreaChart(plotData, dataSet);
} else if (plotData.isType(VisualizationType.PIE.name())) {
return getMultiplePieChart(plotData, dataSets);
} else if (plotData.isType(VisualizationType.STACKED_COLUMN.name())) {
return getStackedBarChart(plotData, dataSet, false);
} else if (plotData.isType(VisualizationType.STACKED_BAR.name())) {
return getStackedBarChart(plotData, dataSet, true);
} else if (plotData.isType(VisualizationType.RADAR.name())) {
return getRadarChart(plotData, dataSet);
} else if (plotData.isType(VisualizationType.GAUGE.name())) {
Number number = dataSet.getValue(0, 0);
ValueDataset valueDataSet = new DefaultValueDataset(number);
return getGaugeChart(plotData, valueDataSet);
} else {
throw new IllegalArgumentException("Illegal or no chart type: " + plotData.getType());
}
if (plotData.isRegression()) {
plot.setDataset(1, dataSets[1]);
plot.setRenderer(1, lineRenderer);
}
JFreeChart jFreeChart = new JFreeChart(plotData.getName(), TITLE_FONT, plot, !plotData.isHideLegend());
setBasicConfig(jFreeChart, plotData);
if (plotData.isTargetLine()) {
plot.addRangeMarker(getMarker(plotData.getTargetLineValue(), plotData.getTargetLineLabel()));
}
if (plotData.isBaseLine()) {
plot.addRangeMarker(getMarker(plotData.getBaseLineValue(), plotData.getBaseLineLabel()));
}
if (plotData.isHideSubtitle()) {
jFreeChart.addSubtitle(getSubTitle(plotData));
}
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
// ---------------------------------------------------------------------
// Category label positions
// ---------------------------------------------------------------------
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
domainAxis.setLabel(plotData.getDomainAxisLabel());
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabel(plotData.getRangeAxisLabel());
return jFreeChart;
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project pentaho-platform by pentaho.
the class JFreeChartEngine method createBarLineChart.
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
String categoryAxisLabel = null;
String valueAxisLabel = null;
String secondValueAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
PlotOrientation orientation = chartDefinition.getOrientation();
// split BarLineChartDefinition in two Definitions
CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition(chartDefinition.getSession(), chartDefinition.getChartAttributes());
CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition(chartDefinition.getSession(), chartDefinition.getChartAttributes());
/*
* try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset =
* (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){}
*/
// get column and row count of the data set
int iColumnCount = chartDefinition.getColumnCount();
int iRowCount = chartDefinition.getRowCount();
if (iRowCount <= 0) {
// $NON-NLS-1$
chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE"));
}
// Loop through columns
for (int r = 0; r < iRowCount; r++) {
// check if measure should be include in bar or line dataset
String strMeasureName = (String) chartDefinition.getRowKey(r);
boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName);
boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName);
// getting all values
for (int c = 0; c < iColumnCount; c++) {
Comparable compColumnName = chartDefinition.getColumnKey(c);
Number nValue = chartDefinition.getValue(strMeasureName, compColumnName);
if (bIsBarColumn) {
barsDataset.addValue(nValue, strMeasureName, compColumnName);
}
if (bIsLineColumn) {
linesDataset.addValue(nValue, strMeasureName, compColumnName);
}
}
}
if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) {
// $NON-NLS-1$
chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"));
}
// Create Axis Objects
CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel);
NumberAxis barsAxis = new NumberAxis(valueAxisLabel);
NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel);
// set title and font for lines Axis
linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle());
linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont());
if (chartDefinition.getLinesRangeTickFormat() != null) {
linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat());
}
// create renderer
BarRenderer barRenderer = null;
LineAndShapeRenderer lineRenderer = null;
// Determine the type of renderer to use
if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
barRenderer = new StackedBarRenderer3D();
lineRenderer = new LineRenderer3D();
} else if (chartDefinition.isStacked()) {
barRenderer = new StackedBarRenderer();
lineRenderer = new LineAndShapeRenderer();
} else {
barRenderer = new BarRenderer3D();
lineRenderer = new LineRenderer3D();
}
} else {
barRenderer = new BarRenderer();
lineRenderer = new LineAndShapeRenderer();
}
if (orientation == PlotOrientation.HORIZONTAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
barRenderer.setPositiveItemLabelPosition(position1);
lineRenderer.setPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
barRenderer.setNegativeItemLabelPosition(position2);
lineRenderer.setNegativeItemLabelPosition(position2);
} else if (orientation == PlotOrientation.VERTICAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
barRenderer.setPositiveItemLabelPosition(position1);
lineRenderer.setPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
barRenderer.setNegativeItemLabelPosition(position2);
lineRenderer.setNegativeItemLabelPosition(position2);
}
if (tooltips) {
barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
}
if (chartDefinition.getMaxBarWidth() != null) {
barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue());
}
// setting some line attributes
lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible());
lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());
/*
* Create plot and make necessary adjustments for overlaid chart
*/
// create the plot with bar chart
CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer);
// add line renderer
plot.setRenderer(1, lineRenderer);
// add lines dataset, renderer and axis to plot
plot.setDataset(1, linesDataset);
plot.setRangeAxis(1, linesAxis);
// map lines to second axis
plot.mapDatasetToRangeAxis(1, 1);
// set rendering order
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
// set location of second axis
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
// standard settings for plots
JFreeChartEngine.updatePlot(plot, barsDataset);
// additional settings for second axis
ValueAxis secondValueAxis = plot.getRangeAxis(1);
if (secondValueAxis != null) {
if (chartDefinition.getLinesRangeTitle() != null) {
secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle());
}
if (chartDefinition.getLinesRangeTitleFont() != null) {
secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont());
}
if (chartDefinition.getLinesRangeTickFont() != null) {
secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont());
}
if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum());
}
if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum());
}
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer 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.renderer.category.LineAndShapeRenderer 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.renderer.category.LineAndShapeRenderer 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;
}
Aggregations