用不同的图表类型替换NVD3图表
Replace NVD3 chart with different chart type
我正在尝试用pieChart(NVD3型号)替换离散BarChart。是否有方法清理/更新图表或元素内容?
Html代码:
<div id="chart">
<svg></svg>
图表初始化:
nv.addGraph(function() {
var xKey = 'label';
var yKey = 'value';
var chart = nv.models.discreteBarChart().x(function(d) {
return d[xKey]
}).y(function(d) {
return d[yKey]
}).staggerLabels(true)
.tooltips(false).showValues(true).transitionDuration(250);
d3.select('#chart svg').datum(defaultData()).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
以及我对替换现有图表的陈述:
function updateToPie(key1, key2) {
var width = 500,
height = 500;
chart = nv.models.pieChart().x(function(d) {
return d[key1]
}).y(function(d) {
return d[key2]
}).color(d3.scale.category10().range()).width(width).height(height);
d3.select("#chart svg").datum(chartData[0].values).transition()
.duration(1200).attr('width', width).attr('height', height)
.call(chart);
chart.dispatch.on('stateChange', function(e) {
nv.log('New State:', JSON.stringify(e));
});
return chart;
}
然而,这只是将piechart与现有的barchart重叠。任何帮助都是值得的。感谢
您可以通过运行来删除所有存在的内容
d3.selectAll("#chart svg > *").remove();
在添加新图表之前。
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 我如何找到一个句子中的所有空格并替换忽略它们
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 如何将删除标记替换为输入类型文本
- 用不同的图表类型替换NVD3图表
- 另一个未捕获的类型错误::无法读取属性'替换'的未定义
- 未捕获的类型错误: 无法调用 null 的方法“替换”
- 未捕获的类型错误:无法调用未定义的下划线.js的方法“替换”
- 将字符串中的 url 替换为 href 链接 - 适用于多种地址类型
- 未捕获的类型错误:无法读取属性'替换'的未定义-下划线
- Emscripten:将提示替换为控制台(某种类型)
- 如何使用jquery/javascript替换dom标记类型
- 如何将小数逗号替换为<输入类型=“;数字“>
- 未捕获的类型错误:无法调用未定义的方法“替换”
- 未捕获的类型错误:无法调用未定义的方法“替换”
- 替换& lt; a>带有
- 替换Flow类型中对象属性的类型
- 使用regex解释不同类型的变量,并使用jquery进行查找和替换
- Regex从数字类型输入中替换
- IIS6无法获取类型属性;JS替换危险字符