Update dimple.js chart when select a new option

后端 未结 1 891
生来不讨喜
生来不讨喜 2020-12-10 09:05
         


        
相关标签:
1条回答
  • 2020-12-10 09:31

    Here's an example to redraw the chart with random numbers whenever the button is clicked. Hopefully this will give you enough to work your example:

    var svg = dimple.newSvg("#chartContainer", 590, 400);
    var data = [
        { Animal: "Cats", Value: (Math.random() * 1000000) },
        { Animal: "Dogs", Value: (Math.random() * 1000000) },
        { Animal: "Mice", Value: (Math.random() * 1000000) }
    ];
    
    var myChart = new dimple.chart(svg, data);
    myChart.setBounds(60, 30, 510, 305)
    var x = myChart.addCategoryAxis("x", "Animal"); 
    x.addOrderRule(["Cats", "Dogs", "Mice"]);
    myChart.addMeasureAxis("y", "Value");
    myChart.addSeries(null, dimple.plot.bar);
    myChart.draw();
    
    d3.select("#btn").on("click", function() {
        myChart.data = [
            { Animal: "Cats", Value: (Math.random() * 1000000) },
            { Animal: "Dogs", Value: (Math.random() * 1000000) },
            { Animal: "Mice", Value: (Math.random() * 1000000) }
        ];
        myChart.draw(1000);
    });
    

    And a working example here:

    http://jsfiddle.net/nf57j/

    0 讨论(0)
提交回复
热议问题