/** * Creates a chart. * * @param dataset a dataset. * @return A chart. */ private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) { JFreeChart chart = ChartFactory.createGanttChart( "Solution Gantt", // title "Operators", // x-axis label "Time", // y-axis label null, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); Paint p = getBackgroundColorGradient(); chart.setBackgroundPaint(p); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setOrientation(PlotOrientation.HORIZONTAL); DateAxis xaxis = (DateAxis) plot.getRangeAxis(); xaxis.setDateFormatOverride(new VertexDateFormat()); xaxis.setPositiveArrowVisible(true); DefaultDrawingSupplier d = new DefaultDrawingSupplier(); plot.setDrawingSupplier(d); GanttRenderer ren = new MyGanttRenderer(); for (GanttElement element : gantt.getElementSet()) { ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor()); } ren.setSeriesItemLabelsVisible(0, false); ren.setSeriesVisibleInLegend(0, false); ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator()); ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator()); ren.setAutoPopulateSeriesShape(false); plot.setRenderer(ren); plot.setDataset(dataset); return chart; }
/* (non-Javadoc) * @see com.alpine.datamining.api.impl.visual.ImageVisualizationType#generateOutPut(com.alpine.datamining.api.AnalyticOutPut) */ @Override public VisualizationOutPut generateOutPut(AnalyticOutPut analyzerOutPut) { AnalyzerOutPutBoxWhisker obj = null; if (analyzerOutPut instanceof AnalyzerOutPutBoxWhisker) { obj = (AnalyzerOutPutBoxWhisker) analyzerOutPut; } List<BoxAndWhiskerItem> list = obj.getItemList(); BoxAndWhiskerDataset dataset = new BoxAndWhiskerDataset(); String variableName = null; String seriesName = null; String typeName = null; double[] maxArray = new double[list.size()]; double[] minArray = new double[list.size()]; // find max and min for (int i = 0; i < list.size(); i++) { maxArray[i] = list.get(i).getMax().doubleValue(); minArray[i] = list.get(i).getMin().doubleValue(); } Arrays.sort(maxArray); Arrays.sort(minArray); double max = maxArray[maxArray.length - 1]; double min = minArray[0]; long n = AlpineMath.adjustUnits(min, max); for (BoxAndWhiskerItem item : list) { dataset.add( item.getMean().doubleValue() / n, item.getMedian().doubleValue() / n, item.getQ1().doubleValue() / n, item.getQ3().doubleValue() / n, item.getMin().doubleValue() / n, item.getMax().doubleValue() / n, 0, 0, null, item.getSeries(), item.getType()); } if (list != null && list.size() > 0) { variableName = list.get(0).getVariableName(); if (variableName == null) variableName = ""; seriesName = list.get(0).getSeriesName(); if (seriesName == null) seriesName = ""; typeName = list.get(0).getTypeName(); if (typeName == null) typeName = ""; } String yLabel = n == 1 ? variableName : variableName + " " + VisualLanguagePack.getMessage(VisualLanguagePack.UNITS, locale) + " (" + com.alpine.datamining.api.utility.AlpineMath.powExpression(n) + ")"; final CategoryAxis xAxis = new CategoryAxis(typeName); xAxis.setLabelFont(VisualResource.getChartFont()); final NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setLabelFont(VisualResource.getChartFont()); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); if (list != null && list.size() < 5) { renderer.setMaximumBarWidth(0.2); renderer.setItemMargin(0.7); } renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); DrawingSupplier supplier = new DefaultDrawingSupplier( createPaintArray(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); plot.setDrawingSupplier(supplier); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); final JFreeChart chart = new JFreeChart(" ", VisualResource.getChartFont(), plot, true); chart.removeLegend(); if (!seriesName.trim().equals("")) { final TextTitle subtitle = new TextTitle(seriesName, VisualResource.getChartFont()); chart.addSubtitle(subtitle); chart.addLegend(new LegendTitle(plot)); chart.getLegend().setItemFont(VisualResource.getChartFont()); } JFreeChartImageVisualizationOutPut output = new JFreeChartImageVisualizationOutPut(chart); output.setName(analyzerOutPut.getAnalyticNode().getName()); return output; }
/** * Creates a sample chart. * * @param dataset the dataset. * @return a chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createLineChart( "Line Chart Demo 5", // chart title "Type", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final Shape[] shapes = new Shape[3]; int[] xpoints; int[] ypoints; // right-pointing triangle xpoints = new int[] {-3, 3, -3}; ypoints = new int[] {-3, 0, 3}; shapes[0] = new Polygon(xpoints, ypoints, 3); // vertical rectangle shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6); // left-pointing triangle xpoints = new int[] {-3, 3, 3}; ypoints = new int[] {0, -3, 3}; shapes[2] = new Polygon(xpoints, ypoints, 3); final DrawingSupplier supplier = new DefaultDrawingSupplier( DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes); final CategoryPlot plot = chart.getCategoryPlot(); plot.setDrawingSupplier(supplier); chart.setBackgroundPaint(Color.yellow); // set the stroke for each series... plot.getRenderer() .setSeriesStroke( 0, new BasicStroke( 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {10.0f, 6.0f}, 0.0f)); plot.getRenderer() .setSeriesStroke( 1, new BasicStroke( 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {6.0f, 6.0f}, 0.0f)); plot.getRenderer() .setSeriesStroke( 2, new BasicStroke( 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {2.0f, 6.0f}, 0.0f)); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setItemLabelsVisible(true); // renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.12); return chart; }