y-takey / chartjs-plugin-stacked100

This plugin for Chart.js that makes your bar chart to 100% stacked bar chart.
MIT License
130 stars 29 forks source link

Doesn't seem to work with ng2-charts #20

Open jyotidhiman0610 opened 6 years ago

jyotidhiman0610 commented 6 years ago

I installed the plugin as specified in the docs, I am using ng2-charts with following options: public barChartOptions = { plugins: { stacked100: { enable: true }, }, legend: { display: true, position: 'bottom', }, scales: { xAxes: [{ display: true, stacked: true }], yAxes: [{ display: false, stacked: true }], }, };

No percentages are shown for me. The chart still displays value options.

ankitp047 commented 5 years ago

hi @jyotidhiman0610 did you find any solution i am also using ng2-charts but my charts didn't stacked at 100 %

srmccray commented 5 years ago

ng2-charts has some additional fiddling to make plugin registration work correctly, once it is hooked in correctly the stacked charts do work.

You'll want to take a look at this issue discussion: https://github.com/valor-software/ng2-charts/issues/752#issuecomment-439060266

gantispam commented 3 years ago

This is not a solution but you found a quick solution for use this lib with angular :

/**


* and on your chart component : 
```js
ngAfterViewInit() {
        const canvas: any = document.getElementById('canvas_' + this.guid);
        const ctx: HTMLCanvasElement = canvas.getContext('2d');

        // bug fix chartjs/angular. registerer stacked100 plugins
        chartJsRegistererStacked100();

        const options: any | Chart.ChartConfiguration = {
            type: this.chart.type,
            data: this.chart.data,
            options: {
                stacked100: {
                    enable: true,
                    replaceTooltipLabel: true,
                }
            },
        };

        const myBar = new Chart(ctx, options);
    }

/!\ chartjs-plugin-stacked100's options is not on "plugins" attribut but on "options" attribut !