Search in sources :

Example 1 with EncapsulationCumstomerDataset

use of org.talend.dataprofiler.chart.util.EncapsulationCumstomerDataset 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;
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) DecimalFormat(java.text.DecimalFormat) Rectangle2D(java.awt.geom.Rectangle2D) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) EncapsulationCumstomerDataset(org.talend.dataprofiler.chart.util.EncapsulationCumstomerDataset) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)1 DecimalFormat (java.text.DecimalFormat)1 JFreeChart (org.jfree.chart.JFreeChart)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)1 StandardCategoryItemLabelGenerator (org.jfree.chart.labels.StandardCategoryItemLabelGenerator)1 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)1 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)1 CategoryDataset (org.jfree.data.category.CategoryDataset)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1 EncapsulationCumstomerDataset (org.talend.dataprofiler.chart.util.EncapsulationCumstomerDataset)1