JavaScript Chart Scripting Techniques

The following appendices discuss general JavaScript functions and chart scripting techniques that are useful across multiple Style Intelligence products

Appendix JS: General JavaScript Functions

Describes functions for processing and comparing text, dates, and numbers, and discusses iteration and flow control structures available in the JavaScript language.

Appendix CT: Chart Tutorial (API)

Describes scripting techniques for creating charts, specifying sub-series, setting axis information, decoration, and annotation.

Appendix CR: Chart Reference (API)

Reference to objects, properties, and methods available for scripting charts.

BI DemoRegister

Appendix JS: General JavaScript Functions

JavaScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. An object is a collection of properties and functions. A property can be a primitive type, a host object type, or a Java object.

The primitive types are standard in every JavaScript runtime and are independent of the host environment. These primitive object types include the following:

  • Global Object Functions
  • String Object Functions
  • Number Object Functions
  • Date Object Functions
  • Array Object Functions
  • Math Object Functions
  • Regular Expression Object Functions

In addition to the primitive types, this Appendix describes a number of other functions and JavaScript constructs. Some of these functions require knowledge of JavaScript arrays. See Array Object Functions for information on how to use arrays. Columns within a table or Data Worksheet can also be treated as arrays.

view gallery
View live interactive examples in InetSoft's dashboard and visualization gallery.

Global Object Functions

The Global object contains the properties and functions available for the entire scripting environment. The values and functions can be accessed anywhere as top-level properties and functions without any qualifier.

// convert a text field to an integer 
var val = parseInt(TextField1.text); 
// assign the half of the value to another text element 
Text2.text = (val * 1 / 2).toString();

String Object Functions

String is a built-in type in JavaScript. It holds a sequence of characters in the Unicode character set. A string literal is created using a double quote or a single quote strings.

 var txt = 'Hello world';
 // or "Hello world"

Two strings can be concatenated using the plus operator.

var txt = "Hello " + 'world';

Number Object Functions

Related Functions & Properties toString([radix]) toFixed(fractionDigits) toexponential(fractionDigits) toLocaleString() toPrecision(precision) All numeric values are number objects. The values are normally used for computation using language operators such as multiplication, addition, subtraction and division. There are a few useful methods for converting a number to a string.

view demo icon
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Date Object Functions

Related Functions & Properties getMilliseconds() toString() toDateString() toTimeString() dateAdd(interval, amount, date) dateDiff(interval, date1, date2) datePart(interval, date) The JavaScript Date object is very similar to Java Date object. It stores the time and date and can be used to manipulate dates and perform date conversions. There are several ways to create a date object. Invoked without arguments, the new date object contains the time and date of its creation:

var now = new Date()  // Thu Jun 12 15:14:51 EDT 2009

You can also create a Date object by specifying elapsed milliseconds from January 1, 1970:

var due_date = new Date(800000000000); 
// Tue May 09 02:13:20 EDT 1995

Alternatively, create the Date object from individual date components:

var due_date = new Date(1988,0,10); // Sun Jan 10 00:00:00 EST 1988

There are a number of methods in the Date object for manipulating date fields. Since the scripts in Style Intelligence are primarily used to work with Java objects, it is more common for a script to work with the java.util.Date object. The use of Java objects is covered in Appendix JS.9, Java Objects (LiveConnect).

Previous: Reporting API Tag Library