如何在向下钻取(高图)中显示多个图形?

时间:2019-07-19 07:50:26

标签: javascript c# asp.net-mvc highcharts

NET MVC项目,我在其中使用Highcharts。在我的图表中,我有列和样条线。

我已经为图表实现了向下钻取,它可以完美地工作,但仅适用于列。在第一层上显示了列和样条线,但是当我触发向下钻取时,仅显示了列。 data2应该是样条线。

var mychart = Highcharts.chart('container', {
                    chart: {
                        zoomType: 'xy',
                        spacingBottom: 40,
                        spacingTop: 40,
                        events: {
                            // DRILLDOWN
                            drilldown: function (e) {

    //Some variables id, func                            

$.getJSON(`/Home/GetDataForMinuteDrilldown?id=${id}&function=${func}`, function (data) {
                                        console.log(data);

                                        var durationArrMinutes = data.map(function (item) {
                                            return item['minuteavg'];
                                        });

                                        var errorArrayMinutes = data.map(function (item) {
                                            return item['errorsperminute']
                                        });



                                        var minuteArray = data.map(function (item) {

                                            return {
                                                name: drill + ":" + item['minute'],
                                                y: item['minuteavg'],
                                                drilldown: item['minute']
                                            };

                                        });

                                        data2 = {
                                            name: 'Errors per Minute',
                                            type: 'spline',
                                            data: errorArrayMinutes,
                                            tooltip: {
                                                valueSuffix: ' '
                                            }
                                        }

                                        data = {
                                            name: 'Average Duration per Minute',
                                            type: 'column',
                                            yAxis: 1,
                                            data: minuteArray,
                                            tooltip: {
                                                valueSuffix: ' ms'
                                            },
                                            data2 //I think this is the error, but I i know no solution
                                        }

                                        console.log('Data:')
                                        console.log(data);

                                        mychart.hideLoading();
                                        mychart.addSeriesAsDrilldown(e.point, data);
                                    }); 
                            }
                        }
                    },
                    title: {
                        text: 'Performance and Error Analytics'
                    },
                    subtitle: {
                        text: 'Analytics of: ' + func
                    },
                    xAxis: [{
                        type: 'category',
                        crosshair: true
                    }],
                    yAxis: [{ // Primary yAxis
                        labels: {
                            format: '{value}',
                            style: {
                                color: Highcharts.getOptions().colors[1]
                            }
                        },
                        title: {
                            text: 'Errors',
                            style: {
                                color: Highcharts.getOptions().colors[2]
                            }
                        }
                    }, { // Secondary yAxis
                        title: {
                            text: 'Duration in ms',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        labels: {
                            format: '{value} ms',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        opposite: true
                    }],
                    tooltip: {
                        shared: true
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'center',
                        x: 0,
                        verticalAlign: 'bottom',
                        y: 50,
                        floating: true,
                        backgroundColor:
                            Highcharts.defaultOptions.legend.backgroundColor || // theme
                            'rgba(255,255,255,0.25)'
                    },
                    series: [{
                        name: 'Average Duration per Hour',
                        type: 'column',
                        yAxis: 1,
                        data: durationPerHourArray,
                        tooltip: {
                            valueSuffix: ' ms'
                        }
                    }, {
                        name: 'Errors',
                        type: 'spline',
                        data: errorArray,
                        tooltip: {
                            valueSuffix: ' '
                        }
                    }],
                    drilldown: {
                        activeAxisLabelStyle: {
                            textDecoration: 'none',
                            fontStyle: 'normal',
                            color: 'black'
                        },
                        series: []
                    }
                });

1 个答案:

答案 0 :(得分:0)

addSeriesAsDrilldown方法仅允许向向下钻取添加一个系列。从源代码:

Chart.prototype.addSeriesAsDrilldown = function (point, options) {
    this.addSingleSeriesAsDrilldown(point, options);
    this.applyDrilldown();
};

addSeriesAsDrilldown的状态下,您可以使用内部addSingleSeriesAsDrilldown方法添加系列并调用applyDrilldown

mychart.addSingleSeriesAsDrilldown(e.point, data);
mychart.addSingleSeriesAsDrilldown(e.point, data2);
mychart.applyDrilldown();

实时演示: http://jsfiddle.net/BlackLabel/obukspae/

源代码: https://code.highcharts.com/modules/drilldown.src.js