Skip to content

Commit c1918e5

Browse files
authoredApr 16, 2020
Support custom legends (#109)
This allows passing `customLegendElement`, which is an HTMLElement reference, to put the custom legend generated by `legendCallback` in.
1 parent 4ebb690 commit c1918e5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ $ ember install ember-cli-chart
1616
In your handlebars template just do:
1717

1818
```hbs
19-
{{ember-chart type=CHARTTYPE data=CHARTDATA options=CHARTOPTIONS width=CHARTWIDTH height=CHARTHEIGHT plugins=CHARTPLUGINS}}
19+
{{ember-chart
20+
type=CHARTTYPE
21+
data=CHARTDATA
22+
options=CHARTOPTIONS
23+
width=CHARTWIDTH
24+
height=CHARTHEIGHT
25+
plugins=CHARTPLUGINS
26+
customLegendElement=CUSTOMLEGENDELEMENT
27+
}}
2028
```
2129

2230
* CHARTTYPE: String; one of the following -- `line`, `bar`, `radar`, `polarArea`, `pie` or `doughnut`.
@@ -25,6 +33,7 @@ In your handlebars template just do:
2533
* CHARTWIDTH: Number; pixel width of the canvas element. Only applies if the chart is NOT responsive.
2634
* CHARTHEIGHT: Number; pixel height of the canvas element. Only applies if the chart is NOT responsive.
2735
* CHARTPLUGINS: Array; refer to ChartJS documentaion. This is optional.
36+
* CUSTOMLEGENDELEMENT: HTMLElement; A custom element to put a custom legend in, when using `legendCallback`. This is optional.
2837

2938
#### Example
3039

‎addon/components/ember-chart.js

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default Component.extend({
1313

1414
didInsertElement() {
1515
this._super(...arguments);
16+
1617
let context = this.get('element');
1718
let data = this.get('data');
1819
let type = this.get('type');
@@ -25,6 +26,7 @@ export default Component.extend({
2526
options: options,
2627
plugins: plugins
2728
});
29+
2830
this.set('chart', chart);
2931
},
3032

@@ -52,6 +54,10 @@ export default Component.extend({
5254
} else {
5355
chart.update(0);
5456
}
57+
58+
if (options.legendCallback && this.get('customLegendElement')) {
59+
this.get('customLegendElement').innerHTML = chart.generateLegend();
60+
}
5561
}
5662
}
5763
});

0 commit comments

Comments
 (0)