List of usage examples for org.jfree.chart.plot SpiderWebPlot SpiderWebPlot
public SpiderWebPlot()
From source file:org.qsos.radar.GenerateRadar.java
/** * This class creates a composite in which the radar char will be * implemented/*from w w w. j av a2 s . com*/ * * @param parent * Composite where the chart will be seen * @param Categories * String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize * @param Scores * Double[] that contains the average score of each category * @return Control * */ public static Control createChart(Composite parent, String[] Categories, double[] Scores) { Composite Charcomposite = new Composite(parent, SWT.EMBEDDED); Charcomposite.setLayout(new FillLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // for (int i = 0; i < CatNumber; i++) { dataset.addValue(Scores[i], getTitle(), Categories[i]); } String BackGroundMire = null; //Configuration of the spiderwebplot SpiderWebPlot plot = new SpiderWebPlot(); plot.setDataset(dataset); plot.setMaxValue(JQConst.RADAR_MAX_VALUE); plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT); plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP); plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT); plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP); plot.setWebFilled(true); //The backgroundpicture used as a spiderweb is chosen according to the //number of categories selected switch (CatNumber) { case 4: BackGroundMire = JQConst.RADAR_SPIDERWEB_4; break; case 5: BackGroundMire = JQConst.RADAR_SPIDERWEB_5; break; case 6: BackGroundMire = JQConst.RADAR_SPIDERWEB_6; break; case 7: BackGroundMire = JQConst.RADAR_SPIDERWEB_7; break; } javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire); plot.setBackgroundImage(icon.getImage()); //chart creation JFreeChart chart = new JFreeChart(plot); //Here the background color from the shell is taken in order to match AWT and SWT backgrounds Color backgroundColor = parent.getBackground(); //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite); chartPanel.setLayout(new java.awt.GridLayout()); ChartPanel jfreeChartPanel = new ChartPanel(chart); chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); chartPanel.add(jfreeChartPanel); chartPanel.pack(); return parent; }
From source file:org.toobsframework.pres.chart.ChartBuilder.java
private Plot configurePlot(IRequest componentRequest, String id, BasePlot plotDef, Map params, boolean isSubPlot, int parentPlotType, BasePlot parentPlot) throws ChartException { boolean is3D = (ParameterUtil.resolveParam(componentRequest, plotDef.getIs3D(), params, "false")[0] .equals("false") ? false : true); Integer plotType = ChartUtil.getSupportedPlots() .get(ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); if (plotType == null) { throw new ChartException("Unsupported Plot type " + ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); }//w w w . j av a 2s . co m Plot plot = null; switch (plotType) { case ChartUtil.PLOT_CATEGORY_TYPE: DomainAxisDef domainAxis = null; RangeAxisDef rangeAxis = null; plot = new CategoryPlot(); if (isSubPlot) { if (plotDef.getDomainAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = plotDef.getDomainAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = parentPlot.getDomainAxisDef(); } if (plotDef.getRangeAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = plotDef.getRangeAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = parentPlot.getRangeAxisDef(); } } else { domainAxis = plotDef.getDomainAxisDef(); rangeAxis = plotDef.getRangeAxisDef(); } ((CategoryPlot) plot) .setDomainAxis(ChartUtil.createCategoryAxis(componentRequest, domainAxis, params, is3D)); ((CategoryPlot) plot).setRangeAxis(createValueAxis(componentRequest, rangeAxis, params, is3D)); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); CategoryItemRenderer renderer = (CategoryItemRenderer) ChartUtil.getRenderer(componentRequest, plotDef, group, params); if (group.getUrlBase() != null) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } ((CategoryPlot) plot).setRenderer(g, renderer); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); generateCategoryDataset(componentRequest, id, categoryDataset, dataset, params); this.setValueAxisBounds(componentRequest, ((CategoryPlot) plot).getRangeAxis(), rangeAxis, params); } ((CategoryPlot) plot).setDataset(g, categoryDataset); } ChartUtil.configurePlot(componentRequest, plot, plotDef, domainAxis, rangeAxis, params); break; case ChartUtil.PLOT_XY_TYPE: plot = new XYPlot(); break; case ChartUtil.PLOT_SPIDER_TYPE: plot = new SpiderWebPlot(); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); if (group.getUrlBase() != null) { ((SpiderWebPlot) plot).setURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); //generateCategoryDataset(id, categoryDataset, dataset, params); for (int s = 0; s < dataset.getDatasetSeriesCount(); s++) { DatasetSeries series = dataset.getDatasetSeries(s); if (series.getColor() != null) { ((SpiderWebPlot) plot).setSeriesPaint(i + s, ChartUtil.getColor(series.getColor())); } } } } ((SpiderWebPlot) plot).setDataset(categoryDataset); ChartUtil.configurePlot(componentRequest, plot, plotDef, null, null, params); break; } return plot; }