Home Elements Boards Recipes

Line Microchart

The Line Microchart displays a series of values using a line on a x/y area with optional axis and reference lines.

It is a pure JavaScript based implementation that uses SVG to display the graph and axis.

The JSON object passed as parameter defines the options for the chart and includes the data of the line chart.

LineChart Screenshot

Global Options

The Line Chart requires not to set the global options.

Add Elements

The Line Chart needs to be created by adding the individual elements:

Draw the data

The data of the line chart must be an array of points with a x and y value;

  var data = [
    { x: 0, y: 2 },
    { x: 1, y: 3 },
    { x: 2, y: 6 },
    { x: 3, y: 5 },
    { x: 4, y: 7 }];

By adding a line element the id of the line is returned this id can be used to draw data using the line element.

  var lineID = chartAPI.add('line', { linetype: 'line', color:'green' });
   chartAPI.draw(lineID, data);

When adding the line element the following options may be used:

Add X-Axis

chartAPI.add('HAxis', options);

The following options may be used:

Add Y-Axis

chartAPI.add('VAxis', options);

Add horizontal line

By adding a horizontal line the y-range will probably be extended to include the line value.

chartAPI.add('hline', options);

Add Indicator

chartAPI.add('indicator', options);

has no additional elements to be added. The add() method is available but without any effect.

Data Formats

The values on given points may be presented using the following formatting options:

SVG implementation remarks

linechart.svg linechart.js

https://atomizedobjects.com/blog/javascript/how-to-create-svg-bar-chart-javascript/

+-----------------------------------------------------------------------+
| (padding at top: height= 4)                                           |
+-----------+-------------------------------------------------------+---+
| (v-labels)|  (panel)                                              |(4)|
| width=12  |  width=128                                            |   |
| height=36 |  height=36                                            |   |
|           |                                                       |   |
|           |                                                       |   |
|           |                                                       |   |
|           |                                                       |   |
+-----------+-------------------------------------------------------+---+
|           | (h-labels)                                            |   |
|           | width=128, height=8                                   |   |
+-----------+-------------------------------------------------------+---+

All regions start 0/0 in the left lower edge, x-offset going right, y-offset going up 

TODO: Add another vertical axis.
 when adding another vertical axis the total width will be extended by another 12 units. 

TODO: horizontal axis as timeline
(up to 4 labels with line) first day + days/4, day, 12 hours, 6 hours  

delta > 4 days : days+ days/4
delta < 4 days : full days
delta < 2 days : full 12 h
delta < 1 days : full 6 h

TODO: horizontal axis numbers (milliseconds)
ranges analog vertical axis implementation.

See also

Tags

Implementation System