Skip to content

Webcharts API

jwildfire edited this page Aug 31, 2015 · 4 revisions

Everything in this library is scoped under the webCharts namespace:

webCharts

object

the webCharts namespace represented as an object whose properties and methods provide access to the functions needed to create and modify charts, tables, and controls

webCharts.createChart(element, config, controls)

a factory to create chart objects.

returns: chart

Param Type Description
element string CSS selector identifying the element in which to create the chart; defaults to "body"
config object config object specifying all options for how the chart is to appear and behave; see Chart Configuration
controls controls controls instance that will be linked to this chart instance

webCharts.createControls(element, config)

a factory to create controls objects

returns: controls

Param Type Description
element string CSS selector identifying the element in which to create the controls; defaults to "body"
config object configuration object describing the inputs to be rendered

webCharts.createTable(element, config, controls)

a factory to create table objects

returns: table

Param Type Description
element string CSS selector identifying the element in which to create the table
config object simple configuration object specifying all options for how the table is to appear and behave
controls controls controls instance that will be linked to this chart instance

webCharts.multiply(chart, data, split_by, order)

a shortcut for creating many charts at once
given a chart object and a variable from its dataset, a new chart is created for each unique value of that variable; each new chart is rendered using a filtered version of the original dataset

Param Type Description
chart chart the chart object used as a template
data array dataset used to draw the charts
split_by string a header from the chart's dataset, the values of which are used to panel the resulting charts
order array an array of the values defined by split_by, the order of which defines the order of the charts

webCharts.objects

object

an object containing references to the three main objects that Webcharts can create

objects.chart

points to the base chart object
allows access to the object for extending it with new methods, such as:

Object.defineProperties(webCharts.objects.chart, {
  'myFunction': {
    value: function(){
      console.log("hello!");
    }
  }
  //more properties
});

objects.table

points to the base table object

objects.controls

points to the base controls object

webCharts.dataOps

object

an object containing several utility functions for working with data

dataOps.getValType(data, variable)

determines what type of data is contained in a given column from a given dataset

returns: string - "continuous" or "categorical"

Param Type Description
data array a dataset to evaluate
variable string a column from the dataset

dataOps.lengthenRaw(data, columns)

expands a dataset to include one record per each column in the given array of columns

returns: array - a new, "longer" dataset

Param Type Description
data array the dataset to be transformed, in the form of an array of object, such as the one returned by d3.csv
columns array an array of column names

dataOps.naturalSorter(a, b)

an alphanumeric sort function that can be passed to the native Array.sort() method http://www.davekoelle.com/files/alphanum.js

Param Type Description
a String | Number the first of a couplet of items to compare
b String | Number the second of a couplet of items to compare

dataOps.summarize(vals, operation)

performs a mathematic operation on a set of values

returns: number

Param Type Description
vals array the values to be evaluated
operation string the type of evaluation to perform
You can’t perform that action at this time.