D3 Dimple - How to show multiple dimple charts on same page?

怎甘沉沦 提交于 2019-12-02 05:48:39

Your problem is that you are using the same global name svg to hold references to two different charts. When your second piece of code runs, it overwrites the svg value that you had from the first piece of code, and when the .tsv() callback returns, it finds a reference to the second graph.

Simplest solution: use different names for svg variable in both pieces of code: svg1 and svg2 will be fine.

Most elegant solution: use some kind of namespace management, such as wrapping both pieces of code in immediately called functions:

function() {
// your first chunk of code here
}()

function() {
// your second chunk of code here
}()

This way you will have two svg variables local to their own scopes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!