new ludo.chart.DataSource(config)
Data source for charts
The chart data source expects an array of objects, example:
[
{ id: 1, label:'John', value:100 },
{ id: 2, label:'Jane', value:245 },
{ id: 3, label:'Martin', value:37 },
{ id: 4, label:'Mary', value:99 },
{ id: 5, label:'Johnny', value:127 },
{ id: 6, label:'Catherine', value:55 },
{ id: 7, label:'Tommy', value:18 }
]
Some charts(example bar charts) accepts nested data, example:
[
{
"country": "United Kingdom",
"children": [
{ "name":"0-14", "people" : 5000 }, { "name":"15-64", "people" : 20000 }, { "name":"65-", "people" : 4000 }
]
},
{
"country": "Germany",
"children": [
{ "name":"0-14", "people" : 6000 }, { "name":"15-64", "people" : 29000 }, { "name":"65-", "people" : 4000 }
]
}
]
The chart data source will add some special properties and functions to the records.
Example: "Jane" in the data above will be something like:
{
id:'1', name: 'Jane', value, 245,
__color: '#4719D2'
__colorOver: '#5629E1'
__count : 7,
__fraction:0.35976505139500736,
__sum : 681
__index: 1,
__percent: 36,
__angle : 0.92264101427013,
__radians : 2.2604704849618193,
__uid : "chart-node-iw7znu0v"
__min : 18
__minAgr : 18
__max : 245
__maxAggr : 245
__parent: undefined
__indexStartVal: undefined
__indexFraction: undefined
__indexSum: undefined
getChildren:function()
getParent():function()
}
where __color is the records assigned color and __colorOver is it's color when highlighted.
You can set this properties manually in your data. When not set, LudoJS will use colors from a color scheme.
You can also set __stroke and __strokeOver for stroke colors.
__count is the total number or records in the array.
__sum is sum(values) in the array.
__fraction is record.value / record.__sum
__index is the index of Jane in the array(John has index 0, Jane index 1, Martin index 2 and so on).
__percent is the rounded value of __fraction 100
__angle is mostly for internal use and represents this records start angle in radians when all records fill a circle.
__radians is how many radians of a circle this record fills. A circle has Math.PI 2 radians. __angle and radians
are only set when values are numeric.
__min is the minimum value found in the data set
__max is the max value found in the data set.
__maxAggr is useful for nested data sets. It is set to max(child values) in the data set. For non-nested sets, it will
have the same value as __max. Example: for
[
{
"country": "United Kingdom",
"children": [
{ "name":"0-14", "people" : 5000 }, { "name":"15-64", "people" : 20000 }, { "name":"65-", "people" : 4000 }
]
},
{
"country": "Germany",
"children": [
{ "name":"0-14", "people" : 6000 }, { "name":"15-64", "people" : 29000 }, { "name":"65-", "people" : 4000 }
]
}
]
__maxAggr will be 39000(Sum children of Germany), while __max will be 29000.
__parent will for child items contain a reference to parent id which can be retrieved using dataSource.byId(id)
__indexStartVal stores the sum of previous records with the same index as this one. In the example with countries above,
, the value for { "name":"0-14", "people" : 6000 } will be 5000, since the first child of United Kingdom has value 5000.
This value is used when rendering stacked area charts.
__indexFraction stores the size of this record divided by the sum of all records with the same index.
getParent() returns a reference to parent record if set, it will return undefined otherwise.
getChildren() returns reference to child data array, example the children array of Germany in the example above
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
- Source:
Example
var dataSource = new ludo.chart.DataSource({ data:[ { id: 1, label:'John', value:100 }, { id: 2, label:'Jane', value:245 }, { id: 3, label:'Martin', value:37 }, { id: 4, label:'Mary', value:99 }, { id: 5, label:'Johnny', value:127 }, { id: 6, label:'Catherine', value:55 }, { id: 7, label:'Tommy', value:18 } ], textOf:function(record, caller){ if(caller.type == 'chart.Tooltip'){ // Text for the tooltip return record.label + ': '+ record.value + ' (' + record.__percent + '%)'; } // Default text return record.label; }, valueOf:function(record, caller){ return record.value; } });
Members
-
maxVal
-
Max value in data array
- Source:
Properties:
Name Type Description maxVal
Number -
maxValAggr
-
Aggregated max value in the data array. Sum value of child data.
- Source:
Properties:
Name Type Description maxValAggr
Number Example
[ { "country": "United Kingdom", "children": [ { "name":"0-14", "people" : 5000 }, { "name":"15-64", "people" : 20000 }, { "name":"65-", "people" : 4000 } ] }, { "country": "Germany", "children": [ { "name":"0-14", "people" : 6000 }, { "name":"15-64", "people" : 29000 }, { "name":"65-", "people" : 4000 } ] } ] // maxValAggr will here be 39000 (Sum children of "Germany").
-
minVal
-
Min value in data array
- Source:
Properties:
Name Type Description minVal
Number