0

我正在尝试为 cpu 参数、磁盘参数、内存参数绘制 highcharts。我可以点击下拉菜单来选择特定的参数。我的任务是在单击特定参数时绘制高图。我想保留之前绘制的图表。也就是说,我想在从下拉列表中选择任何参数时添加图表。我写了以下代码

function DrawTrendCpu(plot,TypeOfParameter,sub_type) {
    itemdata=[];

    $(function () {
        $('#container').highcharts({
            chart: {
                zoomType: 'xy'
            },
            title: {
                text: 'Server Monitroting Tool'
            },
            subtitle: {
                text:  TypeOfParameter+'   usage'
            },
            xAxis: {
                type: 'datetime',
                categories: ['TIME']
            },
            yAxis: [{ // Primary yAxis
                labels: {
                    formatter: function() {
                        return this.value +'%';
                    },
                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: "core " +sub_type,
                    style: {
                        color: '#89A54E'
                    }
                }
            }],
            legend: {
                layout: 'vertical',
                align: 'left',
                x: 120,
                verticalAlign: 'top',
                y: 80,
                floating: true,
                backgroundColor: '#FFFFFF'
            },
            series: []
        });
    });

    if (TypeOfParameter=='memory')
    {
        for (i = 0; i< plot.length; i++) {
            x = parseFloat(plot[i][3]);
            itemdata.push((x));
        }

        var chart = $('#container').highcharts();

        chart.addAxis({ // Secondary yAxis
            title: {
                text: 'Rainfall'
            },
            lineWidth: 2,
            lineColor: '#08F',
            opposite: true
        });
        chart.addSeries({
            name: 'memory',
            type: 'spline',
            color: '#08F',
            yAxis: "memory usage ",
            data: itemdata
        });
    }
    else if(TypeOfParameter=='cpu')
    {
        console.log("cpu")
        //console.log(plot["all"])

        console.log(plot[0].length,"hey")
        for (i = 0; i< plot[0].length; i++) {
            itemdata.push(parseFloat(plot[i][8]));
        }

        var chart = $('#container').highcharts();
        chart.addSeries({
            name: "core "+sub_type,
            data: itemdata
        }, false);
        chart.redraw();
    }
    else if (TypeOfParameter=='disk')
    {
        for (i = 0; i< plot.length; i++) {
            x = parseFloat(plot[i][3]);
            itemdata.push((x));
        }
        var chart = $('#container').highcharts();
        chart.addSeries({
            name: "disk "+sub_type,
            data: itemdata
        },false);
        chart.redraw();
    } 
}

我想要做的是动态添加额外的轴,但是给了我错误 18,请帮忙。我是新手。

4

1 回答 1

0
        chart.addAxis({ // Secondary yAxis

            title: {
                text: 'Rainfall'
            },
            lineWidth: 2,
            lineColor: '#08F',
            opposite: true
        });
        chart.addSeries({
            name: 'memory',
            type: 'spline',
            color: '#08F',
            **yAxis: "memory usage ",**
            data: itemdata
        });

看着这段代码。您正在添加一个 Axis,但您没有设置 id,然后您尝试在 addSeries 调用中通过 id 访问 yAxis。因此,要么通过数字访问 yAxis,要么在 Axis 定义中添加一个 id。

于 2013-07-24T16:36:03.330 回答