0

I am using angular-highcharts to create multiple pie graphs, in that I want apply some properties to both the graphs different-different, like center, showInLegend and startAngle. but its giving an error for all the 3 properties, as it is not defined in series options, whether I am also using title property, that is also not defined, but for that I found a wrapper for that, but coudn't make it for those 3 properties, I am providing my graph code and wrapper as well, if anyone can help, that will be appreciable, thanks in advance.

const pChart = new Chart({
        chart: {
            type: 'pie'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        title: {
            text: ''
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    formatter: function () {
                        return Math.round(this.percentage * 100) / 100 + ' %';
                    },
                    distance: -30,
                    color: '#000'
                },
                colors: ['#e48701', '#a5bc4e'],
                size: 200,
                borderColor: 'none',
                shadow: true
            },
            series: {
                point: {
                    events: {
                        legendItemClick: function () {
                            return false; // <== returning false will cancel the default action
                        }
                    }
                },
                cursor: 'pointer',
                animation: this.isAnimation,
                events: {
                    click: (event) => {
                        this.isAnimation = false;
                        for (let j = 0; j < this.qecData.length; j++) {
                            this.select[j] = this.qecData[j].reasonForDebit === event.point.name;
                            if (this.select[j]) {
                                this.data = this.qecData[j].details;
                                freqData[j].sliced = amtData[j].sliced = freqData[j].selected = amtData[j].selected = true;
                                this.generateGraph(freqData, amtData);
                            } else {
                                freqData[j].sliced = amtData[j].sliced = freqData[j].selected = amtData[j].selected = false;
                            }
                        }
                    }
                }
            }
        },
        series: [
            {
                name: 'Frequency',
                data: freqData,
                center: ['20%', '55%'],
                showInLegend: true,
                startAngle: 270,
                title: {
                    align: 'center',
                    text: 'Frequency Graph',
                    verticalAlign: 'top',
                    y: -30,
                    style: {
                        color: '#869ca7'
                    }
                }
            },
            {
                name: 'Amount',
                data: amtData,
                center: ['80%', '55%'],
                showInLegend: false,
                startAngle: 180,
                title: {
                    align: 'center',
                    text: 'Amount Graph',
                    verticalAlign: 'top',
                    y: -30,
                    style: {
                        color: '#869ca7'
                    }
                }
            }
        ]
    });

And wrapper is:

Highcharts.wrap(Highcharts.seriesTypes.pie.prototype, 'render', function (proceed) {
        const chart = this.chart,
            center = this.center || (this.yAxis && this.yAxis.center),
            titleOption = this.options.title;
        let box;

        proceed.call(this);
        if (center && titleOption) {
            box = {
                x: chart.plotLeft + center[0] - 0.5 * center[2],
                y: chart.plotTop + center[1] - 0.5 * center[2],
                width: center[2],
                height: center[2]
            };
            if (!this.title) {
                this.title = this.chart.renderer.label(titleOption.text)
                    .css(titleOption.style)
                    .add();
            }
            const labelBBox = this.title.getBBox();
            if (titleOption.align === 'center') {
                box.x -= labelBBox.width / 2;
            } else if (titleOption.align === 'right') {
                box.x -= labelBBox.width;
            }
            this.title.align(titleOption, null, box);
        }
    });
  • Hi Nitisha Tambi, Everyting seems to work in this example: http://jsfiddle.net/BlackLabel/y3f9sngt/ Could you describe more precisely what you would like to achieve? – ppotaczek Jan 09 '19 at 10:46
  • @ppotaczek Yes, its working fine in browser, but first thing, when I compile it first time with command "ng serve", it gives compilation failed error due to the same above reason, don't try it on fiddle, just try it on your local, then will get the issue. – Nitisha Tambi Jan 10 '19 at 08:44
  • @Nitisha Tambi I managed to reproduce your chart and it works perfectly fine. However, I used `highcharts-angular` official wrapper which I recommend you (can be downloaded here: https://github.com/highcharts/highcharts-angular). Could you try to use it and check if it is working in your environmental? Demo: https://codesandbox.io/s/k5k3q3rwl7. – Wojciech Chmiel Jan 10 '19 at 14:35
  • Not possible in single graph, we have to create two separate graphs for that – Nitisha Tambi Feb 13 '19 at 06:37

0 Answers0