在highcharts中,第三个系列未在导出的jpeg中打印

时间:2018-07-10 17:11:54

标签: angular highcharts

我正在使用我的angular 4应用程序中的高图表创建箱线图。我已经实现了导出到jpeg的功能。 高图已导出到jpeg,但是不幸的是第三个系列不可见。我不确定是什么问题。我在下面共享了实际高图和导出图像的屏幕截图。您还可以在代码中看到导出功能

Highchart

enter image description here

导出的图片

enter image description here

代码

import { Component, Input, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ShortNumberFormatPipe } from '@wtw/toolkit';

@Component({
    selector: 'app-box-plot-chart',
    template: '<chart [options]="options" (load)="getInstance($event.context)"></chart>',
    styles: [`
        chart{
              display: block;
              width: 100% !important;
              padding:0;
        }
    `]
})

//, width: number
export class BoxPlotChartComponent implements OnInit {
    static chart(shortNumberFormatPipe: ShortNumberFormatPipe, translate: TranslateService, moduleName: string, height: number, graphLegendTitle: string) {
        return {
            chart: {
                type: 'boxplot',
                reflow: true,
                height: height
            },
            title: {
                text: ''
            },
            legend: {
                enabled: false
            },
            exporting: {
                chartOptions: {
                    legend: {
                        allowHTML: true,
                        enabled: true,
                        margin: 25,
                        itemMarginTop: 0,
                        symbolRadius: 0,
                        symbolHeight: 20,
                        symbolWidth: 20,
                        useHTML: true,
                        align: 'right',
                        verticalAlign: 'bottom',
                           title: {
                            text: '',
                         }
                    }
                },
                 chart: {
                        sourcewidth: 600,
                        sourceheight: 800,
                        events: null }
            },

            credits: {
                enabled: false
            },
            xAxis: {

                lineWidth: 0,
                minorGridLineWidth: 0,
                lineColor: 'transparent',
                labels: {
                    enabled: false
                },
                minorTickLength: 0,
                tickLength: 0
            },
            tooltip: {
                shared: false,
                useHTML: true,

                formatter: function() {
                    let isMillionNumber: boolean = false;
                    const row = function(label, value) {
                        const key = 'CAPTIVES.RESULTS.COMMON.';

                        return '<tr><td style="font-size:10px;">' + translate.instant(key + label) + ': </td>'
                            + '<td style="font-size:10px;"><b>' + value + '</b></td></tr>';
                    };

                    const transformNumber = function(value) {
                        isMillionNumber = validateMillionNumber(value);
                        if (isMillionNumber || moduleName === 'eva')
                            return shortNumberFormatPipe.transform(value, 2);
                        else
                            return shortNumberFormatPipe.transform(value, 0);
                    };

                    const table = function(format, point) {
                        let txt = '<strong style="font-size:12px;color:' + point.color + '">' + point.series.name + '</strong><br><br>';
                        txt += '<table>';
                        if (moduleName === 'npv') {
                            txt += row('HIGH', format(point.high));
                            txt += row('Q3', format(point.q3));
                            txt += row('MEDIAN', format(point.median));
                            txt += row('Q1', format(point.q1));
                            txt += row('LOW', format(point.low));
                        } else if (moduleName === 'eva') {
                            txt += row('HIGH', format(point.high) + '%');
                            txt += row('Q3', format(point.q3) + '%');
                            txt += row('MEDIAN', format(point.median) + '%');
                            txt += row('Q1', format(point.q1) + '%');
                            txt += row('LOW', format(point.low) + '%');
                        }
                        txt += '</table>';
                        return txt;
                    };

                    let point = this.point;

                    return table(transformNumber, point);

                    function validateMillionNumber(millionNumber: number) {
                        return millionNumber >= 1000000;
                    }
               },
            },
            series: []
        };
    }

    public options: any;
    chart: any;
    @Input() public series: any;
    @Input() public moduleName: string = '';
    @Input() public height: number = 400;

    private shortNumberFormatPipe = new ShortNumberFormatPipe();

    constructor(private _translate: TranslateService) {
    }

    ngOnInit() {
        let graphLegendTitle: string = this._translate.instant('CAPTIVES.RESULTS.COMMON.GRAPH_LEGEND_TITLE');
        this.options = BoxPlotChartComponent.chart(this.shortNumberFormatPipe, this._translate, this.moduleName, this.height, graphLegendTitle);
    }

    getInstance(chartInstance): void {
        this.chart = chartInstance;
        this.redraw();
    }


    ngOnChanges(data: any) {
        if (!data.series.currentValue || !this.chart) return;
        data.series.currentValue.map(s => {
            this.chart.addSeries(s);
        });
        this.chart.reflow();
    }

    redraw() {
        if (!this.chart) return;
        this._redrawLogic(this.series);
        this.chart.redraw();
    }

    private _redrawLogic(series: any) {
        let seriesLength = this.chart.series.length;
        for (let i = seriesLength - 1; i > -1; i--) {
            this.chart.series[i].remove();
        }

        series.map(s => {
            if (s !== null) {
                this.chart.addSeries(s);
            }
        });

        const elements = document.querySelectorAll('.highcharts-legend-item path');
        for (let i = 0; i < elements.length; i++) {
            elements[i].setAttribute('stroke-width', '20');
            elements[i].setAttribute('stroke-height', '20');
        }
    }
}

0 个答案:

没有答案