Statistics And Calculations

Chart Tutorials  

Statistics And Calculations

Describes how to perform calculations on data in the chart.

🔗Intro

There are ways to easily generate statistical information about the chart data.  

🔗Evaluating Tokens and Expressions using replaceTokens()

One way of doing this is to call the chart.replaceTokens(string) method. It takes a string parameter in which tokens are specified and it returns the same string but with tokens replaced with actual values. For example,

{
  var chart = new JSC.Chart(/*Chart Settings*/);
  var str = chart.replaceTokens("%sum - %average"); /*str == '10,000 - 435'*/
}

chart.replaceTokens('%sum - %average') will return something like: '10,000 - 435'. The above approach utilizes series collection tokens. But it is also available on series and point objects:

{
  var chart = new JSC.Chart(/*Chart Settings*/);
  var str = chart
    .series("Series1")
    .replaceTokens("%sum - %average"); /*str == '450 - 35'*/
}
In which case the specific series is retrieved and the string is processed on the series relaceTokens() function. Other replaceTokens methods include series.replaceTokens() and point.replaceTokens()  


Token Reference Tutorial Tokens available to create dynamic label content.

Token expressions can also be used in the replaceTokens() method. Such as:

{
  var str = chart.replaceTokens("{%sum-%average}"); /*str == '9,565'*/
}

Expressions Tutorial Create dynamic labels using expressions.

🔗Evaluating Token Values using tokenValue()

The other approach is by using the chart.tokenValue(string) method.

This method has the same signature and basic functionality as replaceTokens() and also includes series.tokenValue() and point.tokenValue() versions.

The difference is that this method supports only a single token in the string parameter without any additional text, and returns the value the token represents in it's native data type, rather than a formatted string.

{
  var chart = new JSC.Chart(/*Chart Settings*/);
  var numericVal = chart.tokenValue("%sum"); /*numericVal == 10000*/
}
 

🔗Get user selected data

Data points can be selected on the chart by the user. The selected elements can be retrieved from the chart and processed to show calculations based on that selection. The series.pointSelection property must be set to true in order for the chart to allow point selection.
Get Selected Data Sample Programmatically acquire multiple user selected data points.