Previous sections explained how to modify the data binding and element properties of an existing chart. This section explains how to create a new chart from the ground-up using Chart API commands.
In this example, you will create a new chart, define the chart data, and display the data on the chart. Follow the steps below.
importPackage(inetsoft.graph) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.guide.form) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.schema)
When you import a package, you can refer to its classes by their simple class names, e.g., HeatColorFrame(). If you do not import the package, then you need to use the fully-qualified class names, for example, inetsoft.graph.aesthetic.HeatColorFrame().
Tip: To reference chart data, use the DataSet object.
data = runQuery("sales by state");
In most cases, you will obtain the data from a query or data model by using runQuery(). You can also define your own dataset by passing a JavaScript array to the DefaultDataSet() method. EGraph is the global chart object, including all axes, legends, visual elements, etc.
graph = new EGraph();
graph.addElement(elem);
These are the basic operations required to create a chart from the ground-up using the Chart API. The complete script is shown below, along with the resulting chart.
importPackage(inetsoft.graph) importPackage(inetsoft.graph.aesthetic) importPackage(inetsoft.graph.coord) importPackage(inetsoft.graph.data) importPackage(inetsoft.graph.element) importPackage(inetsoft.graph.guide.form) importPackage(inetsoft.graph.scale) importPackage(inetsoft.graph.schema) data = runQuery("sales by state"); graph = new EGraph(); var elem = new IntervalElement("State", "Sales"); graph.addElement(elem);
Copyright © 2024, InetSoft Technology Corp.