首页 > 解决方案 > 默认情况下取消选择nvd3图表上的线条时如何删除复选标记

问题描述

我想将 nvd3 图表上的所有行设置为默认取消选择。我从 nvd3 网站修改了实时图表上的代码。这里(对不起,我不知道如何保存代码)。

legend: { vers: 'furious' }在图表块中添加,并添加disabled: true到系列对象中。代码片段:

chart: {
    type: 'lineChart',
    height: 450,
    margin : {
        top: 20,
        right: 20,
        bottom: 40,
        left: 55
    },
    legend: {
        vers: 'furious'
    },
    x: function(d){ return d.x; },
    y: function(d){ return d.y; },
    useInteractiveGuideline: true,
    dispatch: {
        stateChange: function(e){ console.log("stateChange"); },
        changeState: function(e){ console.log("changeState"); },
        tooltipShow: function(e){ console.log("tooltipShow"); },
        tooltipHide: function(e){ console.log("tooltipHide"); }
    },
    xAxis: {
        axisLabel: 'Time (ms)'
    },
    yAxis: {
        axisLabel: 'Voltage (v)',
        tickFormat: function(d){
            return d3.format('.02f')(d);
        },
        axisLabelDistance: -10
    },
    callback: function(chart){
        console.log("!!! lineChart callback !!!");
    }
}

function sinAndCos() {
    var sin = [],sin2 = [],
        cos = [];

    //Data is represented as an array of {x,y} pairs.
    for (var i = 0; i < 100; i++) {
        sin.push({x: i, y: Math.sin(i/10)});
        sin2.push({x: i, y: i % 10 == 5 ? null : Math.sin(i/10) *0.25 + 0.5});                 cos.push({x: i, y: .5 * Math.cos(i/10+ 2) + Math.random() / 10});
    }

    //Line chart data should be sent as an array of series objects.
    return [
        {
            values: sin,      //values - represents the array of {x,y} data points
            key: 'Sine Wave', //key  - the name of the series.
            color: '#ff7f0e',  //color - optional: choose your own line color.
            strokeWidth: 2,
            classed: 'dashed',
            disabled: true
        },
        {
            values: cos,
            key: 'Cosine Wave',
            color: '#2ca02c',
            disabled: true
        },
        {
            values: sin2,
            key: 'Another sine wave',
            color: '#7777ff',
            area: true      //area - set to true if you want this line to turn into a filled area chart.
        }
    ];
};

一切正常,但检查了复选标记。结果显示在这里:结果图像 我的问题是如何默认删除复选标记?非常感谢。

============================= 解决方法===================== =======

我找到了解决方案,只需添加以下语句。

userDisabled: true

标签: nvd3.js

解决方案


推荐阅读