List of usage examples for org.jfree.util TableOrder BY_ROW
TableOrder BY_ROW
To view the source code for org.jfree.util TableOrder BY_ROW.
Click Source Link
From source file:org.jfree.data.category.CategoryToPieDataset.java
/** * Returns the value for a given key. If the key is not recognised, the * method should return <code>null</code> (but note that <code>null</code> * can be associated with a valid key also). * * @param key the key.//from w w w.j a v a 2 s . co m * * @return The value (possibly <code>null</code>). */ @Override public Number getValue(Comparable key) { Number result = null; int keyIndex = getIndex(key); if (keyIndex != -1) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getValue(this.index, keyIndex); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getValue(keyIndex, this.index); } } return result; }
From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java
private int getIterationCount(CategoryToPieDataset cds) { if (order == TableOrder.BY_ROW) { return cds.getUnderlyingDataset().getRowCount(); }/*from ww w .jav a 2s . co m*/ if (order == TableOrder.BY_COLUMN) { return cds.getUnderlyingDataset().getColumnCount(); } return 0; }
From source file:com.smhdemo.common.report.generate.factory.ChartFactory.java
public byte[] export(Chart report, Map<String, String> pageParams) throws Exception { if (report == null) { return null; }/*ww w .j a v a 2s . c o m*/ DefaultCategoryDataset dataset = buildDataset(report, pageParams); java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(), report.getFontSize()); String chartTitle = report.getChartTitle(); chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false); String horizAxisLabel = report.getHorizAxisLabel(); horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false); String vertAxisLabel = report.getVertAxisLabel(); vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false); Boolean showLegend = report.getShowLegend(); Boolean showTooltips = report.getShowTooltips(); Boolean drillThroughEnabled = false; Chart.Type chartType = report.getType(); CategoryURLGenerator urlGenerator = null; JFreeChart chart = null; switch (chartType) { case VERTBAR: chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTBAR3D: chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZBAR: chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZBAR3D: chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDVERTBAR: chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDVERTBAR3D: chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDHORIZBAR: chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDHORIZBAR3D: chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTLINE: chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZLINE: chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTAREA: chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZAREA: chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTSTACKEDAREA: chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZSTACKEDAREA: chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case PIEBYCOLUMN: chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYROW: chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYCOLUMN3D: chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYROW3D: chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, null); break; default: throw new BaseException("", ""); } try { Integer bgColorR = report.getBgColorR(); Integer bgColorG = report.getBgColorG(); Integer bgColorB = report.getBgColorB(); chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB)); String axisFontName = report.getAxisFontName(); Integer axisFontStyle = report.getAxisFontStyle(); Integer axisFontSize = report.getAxisFontSize(); java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize); String axisTickFontName = report.getAxisTickFontName(); Integer axisTickFontStyle = report.getAxisTickFontStyle(); Integer axisTickFontSize = report.getAxisTickFontSize(); java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize); String legendFontName = report.getLegendFontName(); Integer legendFontStyle = report.getLegendFontStyle(); Integer legendFontSize = report.getLegendFontSize(); java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize); Integer tickLabelRotate = report.getTickLabelRotate(); String dataFontName = report.getDataFontName(); Integer dataFontStyle = report.getDataFontStyle(); Integer dataFontSize = report.getDataFontSize(); java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize); Plot plot = chart.getPlot(); if (!(plot instanceof MultiplePiePlot)) { CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0)); renderer.setBaseItemLabelFont(dataFont); renderer.setBaseItemLabelsVisible(true); if (chartType == Chart.Type.VERTLINE || chartType == Chart.Type.HORIZLINE) { LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer(); lineRenderer.setBaseShapesVisible(true); lineRenderer.setDrawOutlines(true); lineRenderer.setUseFillPaint(true); } } if (plot instanceof CategoryPlot) { CategoryPlot catPlot = (CategoryPlot) plot; catPlot.getDomainAxis().setLabelFont(axisFont); catPlot.getRangeAxis().setLabelFont(axisFont); catPlot.getDomainAxis().setTickLabelFont(axisTickFont); catPlot.getRangeAxis().setTickLabelFont(axisTickFont); catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f); double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate; CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions(); CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f), oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT)); catPlot.getDomainAxis().setCategoryLabelPositions(newp); } else if (plot instanceof PiePlot3D) { PiePlot3D piePlot = (PiePlot3D) plot; piePlot.setLabelFont(axisFont); piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE); piePlot.setForegroundAlpha(0.5f); piePlot.setNoDataMessage("?"); } else if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(axisFont); } LegendTitle legend = (LegendTitle) chart.getLegend(); if (legend != null) { legend.setItemFont(legendFont); RectangleEdge legendRectEdge = RectangleEdge.BOTTOM; Integer legendPosition = report.getLegendPosition(); switch (legendPosition) { case 0: legendRectEdge = RectangleEdge.LEFT; break; case 1: legendRectEdge = RectangleEdge.TOP; break; case 2: legendRectEdge = RectangleEdge.RIGHT; break; case 3: legendRectEdge = RectangleEdge.BOTTOM; break; } legend.setPosition(legendRectEdge); } } catch (Exception e) { logger.error("Chart Export Exception", e); } ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight()); return out.toByteArray(); }
From source file:com.ewcms.plugin.report.generate.factory.ChartFactory.java
public byte[] export(ChartReport report, Map<String, String> pageParams) throws Exception { if (report == null) { return null; }// w ww . jav a 2s. c o m DefaultCategoryDataset dataset = buildDataset(report, pageParams); java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(), report.getFontSize()); String chartTitle = report.getChartTitle(); chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false); String horizAxisLabel = report.getHorizAxisLabel(); horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false); String vertAxisLabel = report.getVertAxisLabel(); vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false); Boolean showLegend = report.getShowLegend(); Boolean showTooltips = report.getShowTooltips(); Boolean drillThroughEnabled = false; ChartReport.Type chartType = report.getType(); CategoryURLGenerator urlGenerator = null; JFreeChart chart = null; switch (chartType) { case VERTBAR: chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTBAR3D: chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZBAR: chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZBAR3D: chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDVERTBAR: chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDVERTBAR3D: chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDHORIZBAR: chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case STACKEDHORIZBAR3D: chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTLINE: chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZLINE: chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTAREA: chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZAREA: chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case VERTSTACKEDAREA: chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case HORIZSTACKEDAREA: chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case PIEBYCOLUMN: chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYROW: chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYCOLUMN3D: chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, null); break; case PIEBYROW3D: chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, null); break; default: throw new BaseException("", ""); } try { Integer bgColorR = report.getBgColorR(); Integer bgColorG = report.getBgColorG(); Integer bgColorB = report.getBgColorB(); chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB)); String axisFontName = report.getAxisFontName(); Integer axisFontStyle = report.getAxisFontStyle(); Integer axisFontSize = report.getAxisFontSize(); java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize); String axisTickFontName = report.getAxisTickFontName(); Integer axisTickFontStyle = report.getAxisTickFontStyle(); Integer axisTickFontSize = report.getAxisTickFontSize(); java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize); String legendFontName = report.getLegendFontName(); Integer legendFontStyle = report.getLegendFontStyle(); Integer legendFontSize = report.getLegendFontSize(); java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize); Integer tickLabelRotate = report.getTickLabelRotate(); String dataFontName = report.getDataFontName(); Integer dataFontStyle = report.getDataFontStyle(); Integer dataFontSize = report.getDataFontSize(); java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize); Plot plot = chart.getPlot(); if (!(plot instanceof MultiplePiePlot)) { CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0)); renderer.setBaseItemLabelFont(dataFont); renderer.setBaseItemLabelsVisible(true); if (chartType == ChartReport.Type.VERTLINE || chartType == ChartReport.Type.HORIZLINE) { LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer(); lineRenderer.setBaseShapesVisible(true); lineRenderer.setDrawOutlines(true); lineRenderer.setUseFillPaint(true); } } if (plot instanceof CategoryPlot) { CategoryPlot catPlot = (CategoryPlot) plot; catPlot.getDomainAxis().setLabelFont(axisFont); catPlot.getRangeAxis().setLabelFont(axisFont); catPlot.getDomainAxis().setTickLabelFont(axisTickFont); catPlot.getRangeAxis().setTickLabelFont(axisTickFont); catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f); double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate; CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions(); CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f), oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT)); catPlot.getDomainAxis().setCategoryLabelPositions(newp); } else if (plot instanceof PiePlot3D) { PiePlot3D piePlot = (PiePlot3D) plot; piePlot.setLabelFont(axisFont); piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE); piePlot.setForegroundAlpha(0.5f); piePlot.setNoDataMessage("?"); } else if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(axisFont); } LegendTitle legend = (LegendTitle) chart.getLegend(); if (legend != null) { legend.setItemFont(legendFont); RectangleEdge legendRectEdge = RectangleEdge.BOTTOM; Integer legendPosition = report.getLegendPosition(); switch (legendPosition) { case 0: legendRectEdge = RectangleEdge.LEFT; break; case 1: legendRectEdge = RectangleEdge.TOP; break; case 2: legendRectEdge = RectangleEdge.RIGHT; break; case 3: legendRectEdge = RectangleEdge.BOTTOM; break; } legend.setPosition(legendRectEdge); } } catch (Exception e) { logger.error("Chart Export Exception", e); } ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight()); return out.toByteArray(); }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Creates a new spider web plot with the given dataset, with each row * representing a series.// ww w.java2 s .c om * * @param dataset the dataset (<code>null</code> permitted). */ public EnhancedSpiderWebPlot(CategoryDataset dataset) { this(dataset, TableOrder.BY_ROW); }
From source file:org.exist.xquery.modules.jfreechart.Configuration.java
/** * Read configuration from node and initialize configuration. * @throws XPathException Thrown when an element cannot be read. *//*from www . java 2 s . c o m*/ public void parse(Node configuration) throws XPathException { if (configuration.getNodeType() == Node.ELEMENT_NODE && configuration.getLocalName().equals("configuration")) { //Get the First Child Node child = configuration.getFirstChild(); while (child != null) { //Parse each of the child nodes if (child.getNodeType() == Node.ELEMENT_NODE && child.hasChildNodes()) { if (child.getLocalName().equals("title")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'title' cannot be parsed"); } else { title = value; } } else if (child.getLocalName().equals("categoryAxisLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'categoryAxisLabel' cannot be parsed"); } else { categoryAxisLabel = value; } } else if (child.getLocalName().equals("categoryAxisColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'categoryAxisColor' cannot be parsed"); } else { categoryAxisColor = value; } } else if (child.getLocalName().equals("valueAxisLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'valueAxisLabel' cannot be parsed"); } else { valueAxisLabel = value; } } else if (child.getLocalName().equals("valueAxisColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'valueAxisColor' cannot be parsed"); } else { valueAxisColor = value; } } else if (child.getLocalName().equals("timeAxisLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'timeAxisLabel' cannot be parsed"); } else { timeAxisLabel = value; } } else if (child.getLocalName().equals("timeAxisColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'timeAxisColor' cannot be parsed"); } else { timeAxisColor = value; } } else if (child.getLocalName().equals("domainAxisLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'domainAxisLabel' cannot be parsed"); } else { domainAxisLabel = value; } } else if (child.getLocalName().equals("rangeAxisLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'rangeAxisLabel' cannot be parsed"); } else { rangeAxisLabel = value; } } else if (child.getLocalName().equals("pieSectionLabel")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'pieSectionLabel' cannot be parsed"); } else { pieSectionLabel = value; } } else if (child.getLocalName().equals("pieSectionNumberFormat")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'pieSectionNumberFormat' cannot be parsed"); } else { pieSectionNumberFormat = value; } } else if (child.getLocalName().equals("pieSectionPercentFormat")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'pieSectionPercentFormat' cannot be parsed"); } else { pieSectionPercentFormat = value; } } else if (child.getLocalName().equals("orientation")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'orientation' cannot be parsed"); } else if ("HORIZONTAL".equalsIgnoreCase(value)) { orientation = PlotOrientation.HORIZONTAL; } else if ("VERTICAL".equalsIgnoreCase(value)) { orientation = PlotOrientation.VERTICAL; } else { throw new XPathException("Wrong value for 'orientation'"); } } else if (child.getLocalName().equals("tableOrder")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'tableOrder' cannot be parsed"); } else if ("COLUMN".equalsIgnoreCase(value)) { order = TableOrder.BY_COLUMN; } else if ("ROW".equalsIgnoreCase(value)) { order = TableOrder.BY_ROW; } else { throw new XPathException("Wrong value for 'tableOrder'"); } } else if (child.getLocalName().equals("legend")) { Boolean value = parseBoolean(getValue(child)); if (value == null) { throw new XPathException("Value for 'legend' cannot be parsed"); } else { generateLegend = value; } } else if (child.getLocalName().equals("tooltips")) { Boolean value = parseBoolean(getValue(child)); if (value == null) { throw new XPathException("Value for 'tooltips' cannot be parsed"); } else { generateTooltips = value; } } else if (child.getLocalName().equals("urls")) { Boolean value = parseBoolean(getValue(child)); if (value == null) { throw new XPathException("Value for 'urls' cannot be parsed"); } else { generateUrls = value; } } else if (child.getLocalName().equals("width")) { Integer value = parseInteger(getValue(child)); if (value == null) { throw new XPathException("Value for 'width' cannot be parsed"); } else { imageWidth = value; } } else if (child.getLocalName().equals("height")) { Integer value = parseInteger(getValue(child)); if (value == null) { throw new XPathException("Value for 'height' cannot be parsed"); } else { imageHeight = value; } } else if (child.getLocalName().equals("titleColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'titleColor' cannot be parsed"); } else { titleColor = value; } } else if (child.getLocalName().equals("chartBackgroundColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'chartBackgroundColor' cannot be parsed"); } else { chartBackgroundColor = value; } } else if (child.getLocalName().equals("plotBackgroundColor")) { Color value = Colour.getColor(getValue(child)); if (value == null) { throw new XPathException("Value for 'plotBackgroundColor' cannot be parsed"); } else { plotBackgroundColor = value; } } else if (child.getLocalName().equals("seriesColors")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'seriesColors' cannot be parsed"); } else { seriesColors = value; } } else if (child.getLocalName().equals("sectionColors")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'sectionColors' cannot be parsed"); } else { sectionColors = value; } } else if (child.getLocalName().equals("sectionColorsDelimiter")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'sectionColorsDelimiter' cannot be parsed"); } else { sectionColorsDelimiter = value; } } else if (child.getLocalName().equals("rangeLowerBound")) { Double value = parseDouble(getValue(child)); if (value == null) { throw new XPathException("Value for 'rangeLowerBound' cannot be parsed"); } else { rangeLowerBound = value; } } else if (child.getLocalName().equals("rangeUpperBound")) { Double value = parseDouble(getValue(child)); if (value == null) { throw new XPathException("Value for 'rangeUpperBound' cannot be parsed"); } else { rangeUpperBound = value; } } else if (child.getLocalName().equals("categoryItemLabelGeneratorClass")) { String value = getValue(child); if (value == null) { throw new XPathException( "Value for 'categoryItemLabelGeneratorClass' cannot be parsed"); } else { categoryItemLabelGeneratorClass = value; } } else if (child.getLocalName().equals("categoryItemLabelGeneratorParameter")) { String value = getValue(child); if (value == null) { throw new XPathException( "Value for 'categoryItemLabelGeneratorParameter' cannot be parsed"); } else { categoryItemLabelGeneratorParameter = value; } } else if (child.getLocalName().equals("categoryItemLabelGeneratorNumberFormat")) { String value = getValue(child); if (value == null) { throw new XPathException( "Value for 'categoryItemLabelGeneratorNumberFormat' cannot be parsed"); } else { categoryItemLabelGeneratorNumberFormat = value; } } else if (child.getLocalName().equals("imageType")) { String value = getValue(child); if (value == null) { throw new XPathException("Value for 'imageType' cannot be parsed"); } else { imageType = value; } } } //next node child = child.getNextSibling(); } } }
From source file:spinworld.gui.RadarPlot.java
/** * Creates a new spider web plot with the given dataset, with each row * representing a series./*from www . j a va 2 s . co m*/ * * @param dataset the dataset (<code>null</code> permitted). */ public RadarPlot(CategoryDataset dataset) { this(dataset, TableOrder.BY_ROW); }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating charts and is split off as it does * only the chart creation and tweaking of a category chart. All of the * decisions for what columns are defined as what and how the data is stored * should be done in the method that calls this. * <p>/* w ww .jav a 2 s. com*/ * Given a dataset and other chart properties this will create an * appropriate JFreeChart. * @param c * * @param dataset * The data to create a chart from. * @param chartType * The type of chart to create for the category dataset. * @param legendPosition * The position where the legend should appear. * @param chartName * The title of the chart. * @param yaxisName * The title of the Y axis. * @param xaxisName * The title of the X axis. * @return A JFreeChart that represents the dataset given. */ private static JFreeChart createCategoryChartFromDataset(Chart c, CategoryDataset dataset, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { if (chartType == null || dataset == null) { return null; } boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarRenderer.setDefaultBarPainter(new StandardBarPainter()); if (chartType == ChartType.BAR) { chart = ChartFactory.createBarChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType == ChartType.PIE) { chart = createPieChart(chartName, dataset, TableOrder.BY_ROW, showLegend, true, false); } else if (chartType == ChartType.CATEGORY_LINE) { chart = ChartFactory.createLineChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for a category dataset."); } if (chart == null) return null; if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); //chart.getTitle().setPadding(4,4,15,4); } if (chart.getPlot() instanceof MultiplePiePlot) { MultiplePiePlot mplot = (MultiplePiePlot) chart.getPlot(); PiePlot plot = (PiePlot) mplot.getPieChart().getPlot(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); if (showLegend) { // for now, legend and items labels are mutually exclusive. Could make this a user pref. plot.setLabelGenerator(null); } } if (!c.isAutoYAxisRange()) { CategoryPlot plot = chart.getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } return chart; }
From source file:ca.sqlpower.architect.swingui.ProfileGraphPanel.java
public static JFreeChart createTopNChart(ColumnProfileResult cr, int rowCount) { JFreeChart chart;/*from w ww . j a v a 2 s . co m*/ List<ColumnValueCount> valueCounts = cr.getValueCount(); SQLColumn col = cr.getProfiledObject(); DefaultCategoryDataset catDataset = new DefaultCategoryDataset(); long otherDataCount = rowCount; for (ColumnValueCount vc : valueCounts) { catDataset.addValue(vc.getCount(), col.getName(), vc.getValue() == null ? "null" : vc.getValue().toString()); otherDataCount -= vc.getCount(); } int numberOfTopValues = catDataset.getColumnCount(); if (otherDataCount > 0) { catDataset.addValue(otherDataCount, col.getName(), "Other Values"); } String chartTitle; if (numberOfTopValues == 10) { chartTitle = "Top " + numberOfTopValues + " most common values"; } else { chartTitle = "All " + numberOfTopValues + " values"; } chart = ChartFactory.createPieChart(chartTitle, new CategoryToPieDataset(catDataset, TableOrder.BY_ROW, 0), false, true, false); if (chart.getPlot() instanceof PiePlot) { ((PiePlot) chart.getPlot()).setLabelGenerator(new StandardPieSectionLabelGenerator("{0} [{1}]")); } return chart; }
From source file:com.tonbeller.jpivot.chart.ChartComponent.java
/** * Entry point for producing charts, called by wcf render tag. * Produces a jfreechart dataset from olap model, then creates a chart and * writes it to the servlet container temp directory. * Returns a DOM document for Renderer to transform into html. * Requires that jfreechart servlet is installed in this application context. *//*w w w. j ava 2 s .c o m*/ public Document render(RequestContext context) throws Exception { // check if we need to produce a new chart if (dirty) { // clear old listeners dispatcher.clear(); this.result = olapModel.getResult(); this.cellIterator = result.getCells().iterator(); this.dimCount = result.getAxes().length; DefaultCategoryDataset dataset = null; switch (dimCount) { case 1: logger.info("1-dim data"); dataset = build1dimDataset(); break; case 2: logger.info("2-dim data"); dataset = build2dimDataset(); break; default: logger.error("less than 1 or more than 2 dimensions"); throw new IllegalArgumentException("ChartRenderer requires a 1 or 2 dimensional result"); } // re-set dirty flag dirty = false; // create font titleFont = new java.awt.Font(fontName, fontStyle, fontSize); CategoryURLGenerator urlGenerator = new jpivotCategoryURLGenerator(webControllerURL); // Create the chart object JFreeChart chart = null; switch (chartType) { case 1: chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 2: chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 3: chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 4: chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 5: chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 6: chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 7: chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 8: chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 9: chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 10: chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 11: chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 12: chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 13: chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 14: chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 15: chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL)); break; case 16: chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL)); break; case 17: chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL)); break; case 18: chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL)); break; default: throw new Exception("An unknown Chart Type was requested"); } try { chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB)); java.awt.Font slicerFont = new java.awt.Font(slicerFontName, slicerFontStyle, slicerFontSize); java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize); java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize); java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize); Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { CategoryPlot catPlot = (CategoryPlot) plot; catPlot.getDomainAxis().setLabelFont(axisFont); catPlot.getRangeAxis().setLabelFont(axisFont); catPlot.getDomainAxis().setTickLabelFont(axisTickFont); catPlot.getRangeAxis().setTickLabelFont(axisTickFont); catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f); double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate; CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions(); CategoryLabelPositions newp = new CategoryLabelPositions( oldp.getLabelPosition(RectangleEdge.TOP), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f), oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT)); catPlot.getDomainAxis().setCategoryLabelPositions(newp); } else if (plot instanceof PiePlot3D) { PiePlot3D piePlot = (PiePlot3D) plot; //piePlot.setSectionLabelFont(axisFont); piePlot.setLabelFont(axisFont); //piePlot.setSeriesLabelFont(axisTickFont); //piePlot.setSectionLabelType(piePlot.NO_LABELS); piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE); piePlot.setForegroundAlpha(0.5f); piePlot.setNoDataMessage("No data to display"); } else if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; //piePlot.setSectionLabelFont(axisFont); //piePlot.setSeriesLabelFont(axisTickFont); piePlot.setLabelFont(axisFont); //piePlot.setSectionLabelType(piePlot.NO_LABELS); } LegendTitle legend = (LegendTitle) chart.getLegend(); if (legend != null) { legend.setItemFont(legendFont); /* RectangleAnchor legendRectAnchor=RectangleAnchor.BOTTOM; switch (legendPosition){ case 0: legendRectAnchor = RectangleAnchor.LEFT; break; case 1: legendRectAnchor = RectangleAnchor.TOP; break; case 2: legendRectAnchor = RectangleAnchor.RIGHT; break; case 3: legendRectAnchor = RectangleAnchor.BOTTOM; break; } legend.setLegendItemGraphicAnchor(legendRectAnchor); */ RectangleEdge legendRectEdge = RectangleEdge.BOTTOM; switch (legendPosition) { case 0: legendRectEdge = RectangleEdge.LEFT; break; case 1: legendRectEdge = RectangleEdge.TOP; break; case 2: legendRectEdge = RectangleEdge.RIGHT; break; case 3: legendRectEdge = RectangleEdge.BOTTOM; break; } legend.setPosition(legendRectEdge); } if (showSlicer) { RectangleEdge slicerRectPos = RectangleEdge.BOTTOM; HorizontalAlignment slicerHorizAlignment = HorizontalAlignment.LEFT; switch (slicerPosition) { case 0: slicerRectPos = RectangleEdge.TOP; break; case 1: slicerRectPos = RectangleEdge.BOTTOM; break; case 2: slicerRectPos = RectangleEdge.RIGHT; break; case 3: slicerRectPos = RectangleEdge.LEFT; break; } switch (slicerAlignment) { case 4: slicerHorizAlignment = HorizontalAlignment.CENTER; break; case 3: slicerHorizAlignment = HorizontalAlignment.LEFT; break; case 2: slicerHorizAlignment = HorizontalAlignment.RIGHT; break; } TextTitle slicer = new TextTitle(buildSlicer(), slicerFont, Color.BLACK, slicerRectPos, slicerHorizAlignment, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); slicer.setPosition(slicerRectPos); chart.addSubtitle(slicer); } info = new ChartRenderingInfo(new StandardEntityCollection()); // Write the chart image to the temporary directory HttpSession session = context.getSession(); filename = ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, info, session); } catch (Exception e) { filename = "public_error_500x300.png"; dirty = true; } } // new DOM document DocumentBuilder parser = XmlUtils.getParser(); // get an image map for the chart, wrap it in xchart tags String xchart = "<xchart>" + writeImageMap(filename, info, false) + "</xchart>"; /* if (logger.isDebugEnabled()) { logger.debug("Chart XML"); logger.debug(xchart); } */ // create an InputStream from the DOM document InputStream stream = new ByteArrayInputStream(xchart.getBytes("UTF-8")); document = parser.parse(stream); Element root = document.getDocumentElement(); // create url for img tag String graphURL = getGraphURL(context); Element img = document.createElement("img"); img.setAttribute("src", graphURL); img.setAttribute("width", new Integer(chartWidth).toString()); img.setAttribute("height", new Integer(chartHeight).toString()); img.setAttribute("style", "border:0;"); img.setAttribute("usemap", "#" + filename); root.appendChild(img); return document; }