forked from academiadocodigo/TBGWebCharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChartJSScript.pas
79 lines (65 loc) · 1.87 KB
/
ChartJSScript.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
unit ChartJSScript;
interface
uses
Interfaces;
Type
TChartJSScript = class(TInterfacedObject, iModelJS)
private
public
constructor Create;
destructor Destroy; override;
class function New : iModelJS;
function PackJS: String;
function CDN(Value: Boolean): iModelJS;
function Credenciais(Value : iModelCredenciais) : iModelJS;
end;
implementation
{ TChartJSScript }
function TChartJSScript.CDN(Value: Boolean): iModelJS;
begin
Result := Self;
end;
constructor TChartJSScript.Create;
begin
end;
function TChartJSScript.Credenciais(Value: iModelCredenciais): iModelJS;
begin
Result := Self;
end;
destructor TChartJSScript.Destroy;
begin
inherited;
end;
class function TChartJSScript.New : iModelJS;
begin
Result := Self.Create;
end;
function TChartJSScript.PackJS: String;
begin
Result := Result + '<script>' +
'var beforeInitChart = function (chart) {'
+ 'if (chart.options.hideLabelEmptyData || chart.options.skipEmptyData) {'
+ 'let datasetContent = new Array(chart.data.labels.length);'
+ 'chart.data.datasets.forEach(function (dataset, i) {'
+ 'dataset.data.forEach(function (item, indice) {'
+ 'let dataNumber = numeral(item);'
+ 'datasetContent[indice] = datasetContent[indice] || dataNumber.value() > 0;'
+ '});'
+ '});'
+ 'for (x = datasetContent.length - 1; x > -1; x--) {'
+ 'if (!datasetContent[x]) {'
+ 'if (chart.options.hideLabelEmptyData) {'
+ 'chart.data.labels[x] = "";'
+ '}'
+ 'if (chart.options.skipEmptyData) {'
+ 'chart.data.labels.splice(x, 1);'
+ 'chart.data.datasets.forEach(function (dataset) {'
+ 'dataset.data.splice(x, 1);'
+ '});'
+ '}'
+ '}'
+ '}'
+ '}'
+ '};</script>';
end;
end.