javascript - 重绘Highchart系列方法。 Vue.js

标签 javascript vue.js highcharts

在 Vuejs 和 Hightcharts 上构建响应式(Reactive)图表。堆积如山,试图为 redraw() 创建方法。

我试过 this.chart.series[0].setData(this.values,true); 但它不起作用,因为我需要设置整个 series 而不是 series.data。我的系列数据格式:[{"data": 'value', "name": 'value'}],但我只知道如何重绘系列数据部分。任何提示将不胜感激!

// My data format:
    values: [ 
    { "data": [ 6000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, { "isSum": true } ], "name": "Shares A" }, 
    { "data": [ 9600000, 0, 0, 0, 0, 0, 0, 0, 0, 0, { "isSum": true } ], "name": "Shares B" }, 
    { "data": [ 0, 0, 4000000, 0, 0, 0, 0, 0, 0, 0, { "isSum": true } ], "name": "Share C" }, 
    { "data": [ 0, 5000000, 0, 0, 0, 0, 0, 0, 0, 0, { "isSum": true } ], "name": "Shares D" } 
    ]
    // Redraw method:
    methods:{
        redraw(){
            // this doesn't work, need help with this part 
            this.chart.series[0].setData(this.values,true);

            // I've also tried this way, but it redraws only 1st seria, not every of them
            this.chart.series[0].update({
                data: this.values[0].data,
                name: this.values[0].name
            }, true); 
        }
    },
    watch:{
        values(){this.redraw()},
    },
    series: this.values

最佳答案

我终于找到了解决方案:

methods:{
        redraw(){
            chart = this.chart

            if(chart.series.length > 1){
                var s = 0;
                for(var i in this.values){
                    chart.series[s].setData(this.values[i].data);
                    chart.series[s].name = this.values[i].name;
                    s++;
                }
            }else{
                this.chart.series[0].setData(this.values[0].data);
                this.chart.series[0].name = this.values[0].name;
            }
        }
    },

关于javascript - 重绘Highchart系列方法。 Vue.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56856266/

相关文章:

javascript - 两个对象之间的通用深度差异

javascript - 从日期数组javascript中查找缺失的一天

javascript - Crockford 的 hanoi 函数(来自 "The Good Parts")

javascript - 通过链接或按钮将传单 map 置于标记的中心

javascript - 从 Vue.JS 中的函数渲染 JSX

javascript - VueJS : global variables not reconized in components

javascript - 在带有 Angular 的 Highcharts 中使用经典模式而不是样式模式

javascript - Highcharts 在可拖动的折线图上重绘和排序数据

css - Vue.js 转换 - 第一个入口不工作

javascript - 将 JS 转换为 CoffeScript,缺少操作数?