2026-07-12 13:00:02 +08:00
|
|
|
name: Chart
|
2026-07-12 02:03:28 +08:00
|
|
|
|
|
|
|
|
constructor:
|
2026-07-12 13:00:02 +08:00
|
|
|
signature: new Chart(canvas, options)
|
2026-07-12 02:03:28 +08:00
|
|
|
options:
|
|
|
|
|
type: line, bar, or pie. Default is line.
|
|
|
|
|
data: Chart.js data object or source object array.
|
|
|
|
|
options: Chart.js options object.
|
|
|
|
|
map: "{ labels, values, label } for source object arrays."
|
|
|
|
|
|
|
|
|
|
component:
|
|
|
|
|
attributes:
|
|
|
|
|
type: line, bar, or pie.
|
|
|
|
|
state:
|
|
|
|
|
data: Chart.js data object or source object array.
|
|
|
|
|
options: Chart.js options.
|
|
|
|
|
map: "{ labels, values, label }"
|
|
|
|
|
property:
|
2026-07-12 13:00:02 +08:00
|
|
|
chartInstance: Underlying Chart instance.
|
2026-07-12 02:03:28 +08:00
|
|
|
|
|
|
|
|
methods:
|
|
|
|
|
update: Update optional data and redraw.
|
|
|
|
|
destroy: Destroy the underlying Chart.js instance.
|
|
|
|
|
|
|
|
|
|
rules:
|
2026-07-12 13:00:02 +08:00
|
|
|
- Give the Chart container an explicit height.
|
2026-07-12 02:03:28 +08:00
|
|
|
- Use map only when data is an array of objects.
|
2026-07-12 13:00:02 +08:00
|
|
|
- Chart destroys its Chart.js instance when the component unloads.
|
2026-07-12 02:03:28 +08:00
|
|
|
|
|
|
|
|
example: |
|
2026-07-12 13:00:02 +08:00
|
|
|
<Chart id="sales" type="bar"></Chart>
|
2026-07-12 02:03:28 +08:00
|
|
|
<script>
|
|
|
|
|
const chart = document.querySelector('#sales')
|
|
|
|
|
chart.state.data = [
|
|
|
|
|
{ month: 'Jan', amount: 12 },
|
|
|
|
|
{ month: 'Feb', amount: 18 }
|
|
|
|
|
]
|
|
|
|
|
chart.state.map = { labels: 'month', values: 'amount' }
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
tests:
|
|
|
|
|
- apigo.cc/web/chart/test/all.spec.js
|