改变凹坑js图表的宽度

时间:2014-11-14 10:58:06

标签: javascript d3.js dimple.js

我正在使用dimple js,我想更改图表的宽度并重新绘制它我该怎么做。我尝试了chart.width()甚至是chart.newSvg(),但这些都没有我的样本javascript线图,我把它放在jsfiddleJsfiddle
Javascript代码:

var svg = dimple.newSvg("#chartContainer", 600, 400),
            data = [
                { "Value" : 10, "Year" : 2009 },
                { "Value" : 5, "Year" : 2010 },
                { "Value" : 4, "Year" : 2011 },
                { "Value" : 7, "Year" : 2012 },
                { "Value" : 10, "Year" : 2010 },
                { "Value" : 50, "Year" : 2020 },
                { "Value" : 40, "Year" : 2015 },
                { "Value" : 100, "Year" : 2014 },
                { "Value" : 200, "Year" : 2014 }
            ];
    var chart = new dimple.chart(svg, data);
    var x = chart.addCategoryAxis("x", "Year");
    x.addOrderRule("Year");
    var y = chart.addMeasureAxis("y", "Value");
    chart.addColorAxis("Value", ["green", "yellow", "red"]);
    var lines = chart.addSeries(null, dimple.plot.line);
    lines.lineWeight = 4;
    lines.lineMarkers = true;
    chart.ease = "bounce";
    chart.staggerDraw = true;
    chart.draw(2000);

1 个答案:

答案 0 :(得分:0)

Fiddle

更改此

var svg = dimple.newSvg("#chartContainer", 600, 400),

到您所需的宽度

var svg = dimple.newSvg("#chartContainer", width, height),

在再次绘制图表之前使用此行

 document.getElementById('').innerHTML="";