chart implement min max in js
This commit is contained in:
parent
93157a5aa9
commit
34bf9f9fa0
1 changed files with 10 additions and 3 deletions
|
@ -296,6 +296,12 @@ return exports;
|
|||
|
||||
|
||||
/* chartscss javascript stuff */
|
||||
function MapNum(x, in_min, in_max, out_min = 0, out_max = 100)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
//return result.toFixed(2);
|
||||
}
|
||||
|
||||
function DrawChart() {
|
||||
//fetch('/api/chart/')
|
||||
//.then(function(res) { return res.json(); })
|
||||
|
@ -368,12 +374,13 @@ function DrawChart() {
|
|||
let cssString;
|
||||
/* when it is the first data point, dont draw --start */
|
||||
if(dataIndex == 0) {
|
||||
cssString = '--start: calc( ' + ChartJson.chart[j].data[dataIndex] + ' / 100); --end: calc( ' + ChartJson.chart[j].data[dataIndex] + ' / 100);';
|
||||
var tmpval = MapNum(ChartJson.chart[j].data[dataIndex], ChartJson.chart[j].min, ChartJson.chart[j].max);
|
||||
cssString = '--start: calc( ' + tmpval + ' / 100); --end: calc( ' + tmpval + ' / 100);';
|
||||
} else {
|
||||
cssString = '--start: calc( ' + previousData[j] + ' / 100); --end: calc( ' + ChartJson.chart[j].data[dataIndex] + ' / 100);';
|
||||
cssString = '--start: calc( ' + MapNum(previousData[j], ChartJson.chart[j].min, ChartJson.chart[j].max) + ' / 100); --end: calc( ' + MapNum(ChartJson.chart[j].data[dataIndex], ChartJson.chart[j].min, ChartJson.chart[j].max) + ' / 100);';
|
||||
}
|
||||
cell[j].style.cssText = cssString;
|
||||
|
||||
console.log('normal: ' + ChartJson.chart[j].data[dataIndex] + ' map: ' + MapNum(ChartJson.chart[j].data[dataIndex], ChartJson.chart[j].min, ChartJson.chart[j].max));
|
||||
/* store datapoint as previous data */
|
||||
previousData[j] = ChartJson.chart[j].data[dataIndex];
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue