The standard Metrici instance invokes mchart for all elements that contain the class mchart, using something like.
The element with mchart on it should contain a table coded in Microformat.
mchart will parse the table options and invoke a chart type according to the value of options.type within the table.
The standard Metrici instance supports four types:
- "bar" invokes Bar chart
- "pie" invokes Pie chart
- "scatter" invokes Scatter chart
- "line" invokes Line chart
Other Metrici instances may replace these chart types, or offer other chart types.
Registering a new chart type
New chart types can be registed using browser-based scripts.
A new type is registered (or an existing one replaced), using:
: chart code goes here
The function is passed a chart object, which is described below.
The chart object contains the following properties:
The data passed in the microformat. This will have undergone a number of transformations:
If there are errors interpreting the table data, mchart will show an error.
|options||A reference to table.options.|
|element||The element which contains the micoformat, after which the chart should be inserted.|
An empty container inserted after the element which can be replaced with the chart, or into which the chart can be inserted.
The container has a unique id and a class of mchart-container.
The width and height of the container will be set according to options.width and options.height, though chart drivers may choose to override these.
|autoWidth||Set to true if the width of the container has not been set by the options.|
|autoHeight||Set to true if the height of the container has not been set by the options.|
The chart object provides the following utility methods:
|booleanValue(value [,defaultValue])||Returns the boolean value of v, where v may be a boolean or a string.|
|color(colorValue)||Return a color for a value. This attempts to translate using chart.options.colors. If not found, the value is returned.|