To create a pie chart from this data, just convert the chart to a stacked bar, and then convert to polar coordinates. Follow the steps below:
importPackage(inetsoft.graph) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) var arr = [["State", "Revenue"], ["CA", 200], ["NY",300],["PA",150]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new IntervalElement(null,"Revenue"); var xscale = new CategoricalScale("State") var yscale = new LinearScale("Revenue"); var rect = new RectCoord(null, yscale); var cframe = new CategoricalColorFrame("State"); elem.setColorFrame(cframe); graph.setCoordinate(rect); graph.addElement(elem);
elem.setCollisionModifier(GraphElement.STACK_SYMMETRIC); yscale.setScaleRange(new StackRange());
var polar = new PolarCoord(rect); polar.setType(PolarCoord.THETA);
graph.setCoordinate(polar);
var yspec = new AxisSpec(); yspec.setLabelVisible(false); yspec.setLineVisible(false); yspec.setTickVisible(false); yscale.setAxisSpec(yspec);
var tframe = new DefaultTextFrame("State"); elem.setTextFrame(tframe); var legend = new LegendSpec(); legend.setVisible(false); cframe.setLegendSpec(legend);
elem.setHint(GraphElement.HINT_EXPLODED,'true');
The final script for the pie chart is shown below:
importPackage(inetsoft.graph) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) var arr = [["State", "Revenue"], ["CA", 200], ["NY",300],["PA",150]]; dataset = new DefaultDataSet(arr); graph = new EGraph(); var elem = new IntervalElement(null,"Revenue"); var xscale = new CategoricalScale("State") var yscale = new LinearScale("Revenue"); var rect = new RectCoord(null, yscale); var cframe = new CategoricalColorFrame("State"); elem.setColorFrame(cframe); elem.setCollisionModifier(GraphElement.STACK_SYMMETRIC); yscale.setScaleRange(new StackRange()); var polar = new PolarCoord(rect); polar.setType(PolarCoord.THETA); var yspec = new AxisSpec(); yspec.setLabelVisible(false); yspec.setLineVisible(false); yspec.setTickVisible(false); yscale.setAxisSpec(yspec); var tframe = new DefaultTextFrame("State"); elem.setTextFrame(tframe); var legend = new LegendSpec(); legend.setVisible(false); cframe.setLegendSpec(legend); elem.setHint(GraphElement.HINT_EXPLODED,'true'); graph.setCoordinate(polar); graph.addElement(elem);
Copyright © 2024, InetSoft Technology Corp.