Wiki source code of ChartJS
Last modified by Vincent Massol on 2024/10/30
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | == Description == | ||
2 | |||
3 | Creates various types of charts using [[Chart.js>>http://www.chartjs.org/]]. | ||
4 | |||
5 | === Usage === | ||
6 | |||
7 | {{code language="none"}} | ||
8 | {{chartjs type="..." options="{...}"}} | ||
9 | { | ||
10 | "labels": [...], | ||
11 | "datasets": [...] | ||
12 | } | ||
13 | {{/chartjs}} | ||
14 | {{/code}} | ||
15 | |||
16 | === Parameters === | ||
17 | |||
18 | {{velocity}} | ||
19 | #set ($parameters = $doc.getObjects('XWiki.WikiMacroParameterClass')) | ||
20 | #set ($headers = '|=Name|=Description|=Mandatory|=Default') | ||
21 | #set ($body = '') | ||
22 | #foreach ($parameter in $parameters) | ||
23 | #set ($isMandatory = ${parameter.getProperty('mandatory').value}) | ||
24 | #if ($isMandatory == 1) #set ($isMandatory = "Yes") #else #set ($isMandatory = "No") #end | ||
25 | #set ($body = "$body|${parameter.getProperty('name').value}|(((${parameter.getProperty('description').value})))|$isMandatory|$parameter.getProperty('defaultValue').value | ||
26 | ") | ||
27 | #end | ||
28 | ## This option is handy for generating the code to be pasted to the online extension.xwiki.org page for documenting the parameters statically (i.e. without having the macro object attached to the page). | ||
29 | #if ($request.debug) | ||
30 | {{code}} | ||
31 | $headers | ||
32 | $body | ||
33 | {{/code}} | ||
34 | #end | ||
35 | |||
36 | $headers | ||
37 | $body | ||
38 | {{/velocity}} | ||
39 | |||
40 | === Examples === | ||
41 | {{velocity filter="none"}} | ||
42 | #set ($horizontalBarCode = '{{chartjs type="horizontalBar" id="ckeditor-diagram-issues" title="CKEditor and Diagram Issues" | ||
43 | options=''{"tooltips": {"position": {"left": 0.3}}, "width": "600px", "height": "400px", "maintainAspectRatio": false}''}} | ||
44 | { | ||
45 | "labels": [ | ||
46 | "Bug", | ||
47 | "Improvement", | ||
48 | "New Feature" | ||
49 | ], | ||
50 | "datasets": [{ | ||
51 | "label": "CKEditor", | ||
52 | "data": [23, 17, 5], | ||
53 | "backgroundColor": "#ff16e8" | ||
54 | }, { | ||
55 | "label": "Diagram", | ||
56 | "data": [34, 11, 6], | ||
57 | "backgroundColor": "#0018f4" | ||
58 | }] | ||
59 | } | ||
60 | {{/chartjs}}') | ||
61 | |||
62 | #set ($pieSingleDataSetCode = '{{chartjs type="pie" id="pie-1" title="Issues" | ||
63 | options=''{ | ||
64 | "backgroundColors": ["#ff16e8", "#0018f4","#065d00"], | ||
65 | "legend": {"display": false}, | ||
66 | "layout": { | ||
67 | "padding": { | ||
68 | "left": 50, | ||
69 | "right": 50, | ||
70 | "top": 50, | ||
71 | "bottom": 50 | ||
72 | } | ||
73 | }, | ||
74 | "plugins": { | ||
75 | "datalabels": { | ||
76 | "anchor":"end", | ||
77 | "align": "end", | ||
78 | "includeLegend":true | ||
79 | } | ||
80 | }}''}} | ||
81 | { | ||
82 | "labels": [ | ||
83 | "Bug", | ||
84 | "Improvement", | ||
85 | "New Feature" | ||
86 | ], | ||
87 | "datasets": [{ | ||
88 | "label": "CKEditor", | ||
89 | "data": [23, 17, 5] | ||
90 | }] | ||
91 | } | ||
92 | {{/chartjs}}') | ||
93 | |||
94 | #set ($pieMultipleDataSetsCode = '{{chartjs type="pie" options="{~"backgroundColors~": [~"#ff16e8~", ~"#0018f4~", ~"#065d00~"]}"}} | ||
95 | { | ||
96 | "labels": [ | ||
97 | "Bug", | ||
98 | "Improvement", | ||
99 | "New Feature" | ||
100 | ], | ||
101 | "datasets": [{ | ||
102 | "label": "CKEditor", | ||
103 | "data": [23, 17, 5] | ||
104 | }, { | ||
105 | "label": "Diagram", | ||
106 | "data": [34, 11, 6] | ||
107 | }] | ||
108 | } | ||
109 | {{/chartjs}}') | ||
110 | |||
111 | #set ($mirroredHistogramWithLongLabelsCode ='{{chartjs type="horizontalBar" options=''{ | ||
112 | "backgroundColors": ["#ff16e8", "#0018f4","#065d00"], | ||
113 | "legend": {"display": false}, | ||
114 | "afterValue": "%", | ||
115 | "scales": { | ||
116 | "yAxes": [{ | ||
117 | "barThickness": 20, | ||
118 | "maxBarThickness": 20, | ||
119 | "ticks": { "mirror": true, "padding": -5, "labelOffset": -20, "fontColor": "#000", "fontSize": 14} | ||
120 | }], | ||
121 | "xAxes": [{"ticks": {"beginAtZero": true, "stepValue": 10, "max": 100, "afterValue": "%"}}] | ||
122 | }, | ||
123 | "tooltips": {"maxCharactersPerLine": 50} | ||
124 | } | ||
125 | ''}} | ||
126 | { | ||
127 | "labels": [ | ||
128 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | ||
129 | "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
130 | "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." | ||
131 | ], | ||
132 | "datasets": [{ | ||
133 | "label": "Lorem ipsum", | ||
134 | "data": [23, 47, 30] | ||
135 | }] | ||
136 | } | ||
137 | {{/chartjs}}') | ||
138 | |||
139 | {{/velocity}} | ||
140 | |||
141 | {{velocity}} | ||
142 | (% class="row" %)((( | ||
143 | (% class="col-xs-12 col-sm-6 col-md-7" %)((( | ||
144 | {{code language="none"}} | ||
145 | $horizontalBarCode | ||
146 | {{/code}} | ||
147 | ))) | ||
148 | (% class="col-xs-12 col-sm-6 col-md-5" %)((( | ||
149 | $horizontalBarCode | ||
150 | ))) | ||
151 | ))) | ||
152 | (% class="row" %)((( | ||
153 | (% class="col-xs-12 col-sm-6 col-md-7" %)((( | ||
154 | {{code language="none"}} | ||
155 | $pieSingleDataSetCode | ||
156 | {{/code}} | ||
157 | ))) | ||
158 | (% class="col-xs-12 col-sm-6 col-md-5" %)((( | ||
159 | $pieSingleDataSetCode | ||
160 | ))) | ||
161 | ))) | ||
162 | (% class="row" %)((( | ||
163 | (% class="col-xs-12 col-sm-6 col-md-7" %)((( | ||
164 | {{code language="none"}} | ||
165 | $pieMultipleDataSetsCode | ||
166 | {{/code}} | ||
167 | ))) | ||
168 | (% class="col-xs-12 col-sm-6 col-md-5" %)((( | ||
169 | $pieMultipleDataSetsCode | ||
170 | ))) | ||
171 | ))) | ||
172 | (% class="row" %)((( | ||
173 | (% class="col-xs-12 col-sm-6 col-md-7" %)((( | ||
174 | {{code language="none"}} | ||
175 | $mirroredHistogramWithLongLabelsCode | ||
176 | {{/code}} | ||
177 | ))) | ||
178 | (% class="col-xs-12 col-sm-6 col-md-5" %)((( | ||
179 | $mirroredHistogramWithLongLabelsCode | ||
180 | ))) | ||
181 | ))) | ||
182 | {{/velocity}} |