D3.js Plotting Multiple Data Sets from Separate Files

后端 未结 1 957
太阳男子
太阳男子 2020-12-30 06:17

I\'m trying to make a scatter plot with two sets of data from two tsv files. However, each one shares the x-axis with single scale. There are two y-axis each with their own

相关标签:
1条回答
  • 2020-12-30 06:39

    The problem is that you're using the same selector, svg.selectAll(".dot"), for each dataset .data(tsv1) and .data(tsv2).

    D3 thinks that the 2nd set is supposed to replace the first. You can fix it by assigning a unique class to each type of dot.

        svg.selectAll(".blue.dot")// Select specifically blue dots
            .data(tsv1)
            .enter().append("circle")
            .attr("class", "blue dot")// Assign two classes
            ...
    
        svg.selectAll(".orange.dot")
            .data(tsv2)
            .enter().append("circle")
            .attr("class", "orange dot")
            ...
    
    0 讨论(0)
提交回复
热议问题