List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.HorizontalBarChartBuilder.java
License:Open Source License
protected void setupElements(Chart c, Node root, IPentahoResultSet data) { HorizontalBarChart hbc = new HorizontalBarChart(); for (int i = 0; i < data.getRowCount(); i++) { double d = ((Number) data.getValueAt(i, 1)).doubleValue(); hbc.addBars(new HorizontalBarChart.Bar(d)); }//from ww w .j a va2 s . c om if (getValue(root.selectSingleNode("/chart/color-palette")) != null) { List colors = root.selectNodes("/chart/color-palette/color"); String colour = getNodeValue((Node) colors.get(0)); hbc.setColour(colour); } else hbc.setColour("#86BBEF"); c.addElements(hbc); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.LineChartBuilder.java
License:Open Source License
protected void setupElements(Chart c, Node root, IPentahoResultSet data) { Style lineStyle = setupLineStyle(root); int columnCount = data.getMetaData().getColumnCount(); LineChart[] elements = null;// w w w .j av a2s. c o m if (columnCount > 1) { elements = new LineChart[columnCount - 1]; int rowCount = data.getRowCount(); List colors = root.selectNodes("/chart/color-palette/color"); for (int i = 1; i <= columnCount - 1; i++) { LineChart e = new LineChart(lineStyle); Number[] datas = new Number[rowCount]; for (int j = 0; j < rowCount; j++) { datas[j] = (Number) data.getValueAt(j, i); e.addValues(datas[j].doubleValue()); } String colour; if (colors != null && colors.size() > 1) { colour = ((Node) colors.get(i - 1)).getText().trim(); e.setColour(colour); } e.setText((String) data.getMetaData().getColumnHeaders()[0][i]); setLink(e, root, "/chart/link"); setOnClick(e, root, "/chart/on-click"); elements[i - 1] = e; } setupXAxisLabels(data, c, rowCount); } else { elements = new LineChart[columnCount]; LineChart e = new LineChart(setupLineStyle(root)); Node chartBackGround = root.selectSingleNode("/chart/chart-background"); if (chartBackGround != null) { e.setColour(chartBackGround.getText()); } int rowCount = data.getRowCount(); Number[] datas = new Number[rowCount]; for (int i = 0; i < rowCount; i++) { datas[i] = (Number) data.getValueAt(i, 0); } e.addValues(datas); elements[0] = e; setLink(e, root, "/chart/link"); setOnClick(e, root, "/chart/on-click"); } c.addElements(elements); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.LineChartBuilder.java
License:Open Source License
protected Style setupLineStyle(Node root) { LineChart.Style.Type t = LineChart.Style.Type.DOT; Style style = new LineChart.Style(t); if (getValue(root.selectSingleNode("/chart/dot-style")) != null) { String stylestring = getNodeValue(root.selectSingleNode("/chart/dot-style")); // TODO: Need to check to make sure stylestring in TYPEs style.setType(stylestring);//w w w. j a va2 s . com return style; } return style; }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.OFC4JHelper.java
License:Open Source License
public static String generateChartJson(Node chartNode, IPentahoResultSet data, boolean byRow, Log log) { Chart c = new Chart(); Node root = chartNode; IPentahoResultSet chartdata;//from w w w . j av a 2 s . c o m if (byRow) { chartdata = PentahoDataTransmuter.pivot(data); } else { chartdata = data; } Node chartType = root.selectSingleNode("/chart/chart-type"); String cType = chartType.getText().trim(); Node is_3DNode = root.selectSingleNode("/chart/is-3D"); Node is_glassNode = root.selectSingleNode("/chart/is-glass"); Node is_sketchNode = root.selectSingleNode("/chart/is-sketch"); if (cType.equalsIgnoreCase("BarChart")) { boolean isDone = false; if (is_3DNode != null && is_3DNode.getText().length() > 0) { String str = is_3DNode.getText().trim(); if (str.equalsIgnoreCase("true")) { ThreeDBarChartBuilder builder = new ThreeDBarChartBuilder(); c = builder.build(root, chartdata); isDone = true; } } if (isDone != true && is_glassNode != null && is_glassNode.getText().length() > 0) { String str = is_glassNode.getText().trim(); if (str.equalsIgnoreCase("true")) { GlassBarChartBuilder builder = new GlassBarChartBuilder(); c = builder.build(root, chartdata); isDone = true; } } if (isDone != true && is_sketchNode != null && is_sketchNode.getText().length() > 0) { String str = is_sketchNode.getText().trim(); if (str.equalsIgnoreCase("true")) { SketchBarChartBuilder builder = new SketchBarChartBuilder(); c = builder.build(root, chartdata); isDone = true; } } Node isStackedNode = root.selectSingleNode("/chart/is-stacked"); if (isDone != true && isStackedNode != null && isStackedNode.getText().length() > 0) { String str = isStackedNode.getText().trim(); if (str.equalsIgnoreCase("true")) { StackedBarChartBuilder builder = new StackedBarChartBuilder(); c = builder.build(root, chartdata); isDone = true; } } Node orientationNode = root.selectSingleNode("/chart/orientation"); if (isDone != true && orientationNode != null && orientationNode.getText().length() > 0) { String str = orientationNode.getText().trim(); if (str.equalsIgnoreCase("horizontal")) { HorizontalBarChartBuilder builder = new HorizontalBarChartBuilder(); c = builder.build(root, chartdata); isDone = true; } } if (isDone != true) { BarChartBuilder builder = new BarChartBuilder(); c = builder.build(root, chartdata); } } else if (cType.equalsIgnoreCase("AreaChart")) { AreaChartBuilder builder = new AreaChartBuilder(); c = builder.build(root, chartdata); } else if (cType.equalsIgnoreCase("LineChart")) { LineChartBuilder builder = new LineChartBuilder(); c = builder.build(root, chartdata); } else if (cType.equalsIgnoreCase("PieChart")) { PieChartBuilder builder = new PieChartBuilder(); c = builder.build(root, chartdata); } else if (cType.equalsIgnoreCase("BarLineChart")) { BarLineChartBuilder builder = new BarLineChartBuilder(); c = builder.build(root, chartdata); } else if (cType.equalsIgnoreCase("ScatterChart")) { ScatterChartBuilder builder = new ScatterChartBuilder(); c = builder.build(root, chartdata); } return c.toString(); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.PieChartBuilder.java
License:Open Source License
protected void setupElements(Chart c, Node root, IPentahoResultSet data) { PieChart e = new PieChart(); int rowCount = data.getRowCount(); Node colIndexNode = root.selectSingleNode("/chart/slice/datas/sql-column-index"); Node labelIndexNode = root.selectSingleNode("/chart/slice/labels/sql-column-index"); if (colIndexNode != null && colIndexNode.getText().length() > 0) { int index = Integer.parseInt(colIndexNode.getText().trim()); int labelindex = Integer.parseInt(labelIndexNode.getText().trim()); for (int j = 0; j < rowCount; j++) { Object obj = data.getValueAt(j, labelindex - 1); Number value = (Number) data.getValueAt(j, index - 1); if (obj instanceof java.sql.Timestamp || obj instanceof java.util.Date) { e.addSlice(value.doubleValue(), sf.format(obj)); } else { Slice s = new Slice(value.doubleValue(), obj.toString()); e.addSlices(s);/*from ww w. j av a 2s. c om*/ } } } c.addElements(e); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.PieChartBuilder.java
License:Open Source License
protected void setTooltip(Node root, Element e) { Node tooltipNode = root.selectSingleNode("/chart/tooltip"); if (tooltipNode != null && tooltipNode.getText().length() > 0) { String tooltip = tooltipNode.getText().trim(); e.setTooltip(tooltip);/*from w w w .j a v a 2 s. c o m*/ } else { e.setTooltip("#val# of #total#<br>#percent# of 100%"); } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.PieChartBuilder.java
License:Open Source License
protected void setColorPalette(Node root, PieChart e) { Node colorsNode = root.selectSingleNode("/chart/slice/color-palette"); if (colorsNode != null && colorsNode.getText().length() > 0) { String[] colors = null;//from www.j a v a 2s. com colors = fillLabels(colorsNode); e.setColours(colors); } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.PieChartBuilder.java
License:Open Source License
protected void setIsAnimated(Node root, PieChart e) { Node isAnimateNode = root.selectSingleNode("/chart/isAnimate"); if (isAnimateNode != null && isAnimateNode.getText().length() > 0) { String str = isAnimateNode.getText().trim(); if ("true".equalsIgnoreCase(str)) { e.setAnimate(true);//from w w w .j a v a2 s. c o m } else e.setAnimate(false); } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.PieChartBuilder.java
License:Open Source License
protected void setStartAngle(Node root, PieChart e) { Node startAngleNode = root.selectSingleNode("/chart/start-angle"); if (startAngleNode != null && startAngleNode.getText().length() > 0) { e.setStartAngle(Integer.parseInt(startAngleNode.getText().trim())); } else/*from www.j a v a2 s.co m*/ e.setStartAngle(35); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.ScatterChartBuilder.java
License:Open Source License
private void setupColors(Node root, ScatterChart se, int i) { if (getValue(root.selectSingleNode("/chart/color-palette")) != null) { List colors = root.selectNodes("/chart/color-palette/color"); String colour = getNodeValue((Node) colors.get(i)); se.setColour(colour);/*from ww w .j ava2s . c om*/ } else se.setColour("#86BBEF"); }