c3js synchronize tooltips of areachart and piechart showing the same data












0














I have a piechart and a arechart showing the same data. The piechart shows the summarized data of the areachart.
Now I want to show the tooltip /highlight the data of the other chart if the respective data is selected.



jsfiddle: http://jsfiddle.net/gothmogg/m59poqcd/18/



I found a hint that I should use



onmouseover: function (d) { 
chart2.tooltip.show({ x: d.x });
}


As a sample my code would look like (same as in jsfiddle)






var columns = ['data1', 'data2', 'data3', 'data4'];
var data = ;
data.push([20, 40, 30, 10, 50]);
data.push([50, 50, 50, 40, 60]);
data.push([10, 40, 60, 25, 30]);
data.push([80, 60, 30, 25, 35]);


var pieChart = c3.generate({
bindto: d3.select('#pie-chart'),
data: {
columns: [
[columns[0]].concat(data[0])
],
type: 'pie',
onmouseover: function(d, i) {
if (areaChart)
areaChart.tooltip.show({
x: d.x
});
},

}
});

var areaChart = c3.generate({
bindto: d3.select('#area-chart'),
data: {
columns: [
[columns[0]].concat(data[0])
],
type: 'area-spline',
onmouseover: function(d, i) {
if (pieChart)
pieChart.tooltip.show({
x: d.x
});
},

}
});

for (i = 1; i < columns.length; i++) {
setTimeout(function(column) {
pieChart.load({
columns: [
[columns[column]].concat(data[column]),
]
});
areaChart.load({
columns: [
[columns[column]].concat(data[column]),
]
});
}, (i * 5000 / columns.length), i);
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

<div id="area-chart"></div>
<div id="pie-chart"></div>





The highlighting/tooltip of course does not work that way...



Any ideas except of manually highlighting with d3?










share|improve this question



























    0














    I have a piechart and a arechart showing the same data. The piechart shows the summarized data of the areachart.
    Now I want to show the tooltip /highlight the data of the other chart if the respective data is selected.



    jsfiddle: http://jsfiddle.net/gothmogg/m59poqcd/18/



    I found a hint that I should use



    onmouseover: function (d) { 
    chart2.tooltip.show({ x: d.x });
    }


    As a sample my code would look like (same as in jsfiddle)






    var columns = ['data1', 'data2', 'data3', 'data4'];
    var data = ;
    data.push([20, 40, 30, 10, 50]);
    data.push([50, 50, 50, 40, 60]);
    data.push([10, 40, 60, 25, 30]);
    data.push([80, 60, 30, 25, 35]);


    var pieChart = c3.generate({
    bindto: d3.select('#pie-chart'),
    data: {
    columns: [
    [columns[0]].concat(data[0])
    ],
    type: 'pie',
    onmouseover: function(d, i) {
    if (areaChart)
    areaChart.tooltip.show({
    x: d.x
    });
    },

    }
    });

    var areaChart = c3.generate({
    bindto: d3.select('#area-chart'),
    data: {
    columns: [
    [columns[0]].concat(data[0])
    ],
    type: 'area-spline',
    onmouseover: function(d, i) {
    if (pieChart)
    pieChart.tooltip.show({
    x: d.x
    });
    },

    }
    });

    for (i = 1; i < columns.length; i++) {
    setTimeout(function(column) {
    pieChart.load({
    columns: [
    [columns[column]].concat(data[column]),
    ]
    });
    areaChart.load({
    columns: [
    [columns[column]].concat(data[column]),
    ]
    });
    }, (i * 5000 / columns.length), i);
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

    <div id="area-chart"></div>
    <div id="pie-chart"></div>





    The highlighting/tooltip of course does not work that way...



    Any ideas except of manually highlighting with d3?










    share|improve this question

























      0












      0








      0







      I have a piechart and a arechart showing the same data. The piechart shows the summarized data of the areachart.
      Now I want to show the tooltip /highlight the data of the other chart if the respective data is selected.



      jsfiddle: http://jsfiddle.net/gothmogg/m59poqcd/18/



      I found a hint that I should use



      onmouseover: function (d) { 
      chart2.tooltip.show({ x: d.x });
      }


      As a sample my code would look like (same as in jsfiddle)






      var columns = ['data1', 'data2', 'data3', 'data4'];
      var data = ;
      data.push([20, 40, 30, 10, 50]);
      data.push([50, 50, 50, 40, 60]);
      data.push([10, 40, 60, 25, 30]);
      data.push([80, 60, 30, 25, 35]);


      var pieChart = c3.generate({
      bindto: d3.select('#pie-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'pie',
      onmouseover: function(d, i) {
      if (areaChart)
      areaChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      var areaChart = c3.generate({
      bindto: d3.select('#area-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'area-spline',
      onmouseover: function(d, i) {
      if (pieChart)
      pieChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      for (i = 1; i < columns.length; i++) {
      setTimeout(function(column) {
      pieChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      areaChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      }, (i * 5000 / columns.length), i);
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

      <div id="area-chart"></div>
      <div id="pie-chart"></div>





      The highlighting/tooltip of course does not work that way...



      Any ideas except of manually highlighting with d3?










      share|improve this question













      I have a piechart and a arechart showing the same data. The piechart shows the summarized data of the areachart.
      Now I want to show the tooltip /highlight the data of the other chart if the respective data is selected.



      jsfiddle: http://jsfiddle.net/gothmogg/m59poqcd/18/



      I found a hint that I should use



      onmouseover: function (d) { 
      chart2.tooltip.show({ x: d.x });
      }


      As a sample my code would look like (same as in jsfiddle)






      var columns = ['data1', 'data2', 'data3', 'data4'];
      var data = ;
      data.push([20, 40, 30, 10, 50]);
      data.push([50, 50, 50, 40, 60]);
      data.push([10, 40, 60, 25, 30]);
      data.push([80, 60, 30, 25, 35]);


      var pieChart = c3.generate({
      bindto: d3.select('#pie-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'pie',
      onmouseover: function(d, i) {
      if (areaChart)
      areaChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      var areaChart = c3.generate({
      bindto: d3.select('#area-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'area-spline',
      onmouseover: function(d, i) {
      if (pieChart)
      pieChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      for (i = 1; i < columns.length; i++) {
      setTimeout(function(column) {
      pieChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      areaChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      }, (i * 5000 / columns.length), i);
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

      <div id="area-chart"></div>
      <div id="pie-chart"></div>





      The highlighting/tooltip of course does not work that way...



      Any ideas except of manually highlighting with d3?






      var columns = ['data1', 'data2', 'data3', 'data4'];
      var data = ;
      data.push([20, 40, 30, 10, 50]);
      data.push([50, 50, 50, 40, 60]);
      data.push([10, 40, 60, 25, 30]);
      data.push([80, 60, 30, 25, 35]);


      var pieChart = c3.generate({
      bindto: d3.select('#pie-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'pie',
      onmouseover: function(d, i) {
      if (areaChart)
      areaChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      var areaChart = c3.generate({
      bindto: d3.select('#area-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'area-spline',
      onmouseover: function(d, i) {
      if (pieChart)
      pieChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      for (i = 1; i < columns.length; i++) {
      setTimeout(function(column) {
      pieChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      areaChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      }, (i * 5000 / columns.length), i);
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

      <div id="area-chart"></div>
      <div id="pie-chart"></div>





      var columns = ['data1', 'data2', 'data3', 'data4'];
      var data = ;
      data.push([20, 40, 30, 10, 50]);
      data.push([50, 50, 50, 40, 60]);
      data.push([10, 40, 60, 25, 30]);
      data.push([80, 60, 30, 25, 35]);


      var pieChart = c3.generate({
      bindto: d3.select('#pie-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'pie',
      onmouseover: function(d, i) {
      if (areaChart)
      areaChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      var areaChart = c3.generate({
      bindto: d3.select('#area-chart'),
      data: {
      columns: [
      [columns[0]].concat(data[0])
      ],
      type: 'area-spline',
      onmouseover: function(d, i) {
      if (pieChart)
      pieChart.tooltip.show({
      x: d.x
      });
      },

      }
      });

      for (i = 1; i < columns.length; i++) {
      setTimeout(function(column) {
      pieChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      areaChart.load({
      columns: [
      [columns[column]].concat(data[column]),
      ]
      });
      }, (i * 5000 / columns.length), i);
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.9/c3.min.js"></script>

      <div id="area-chart"></div>
      <div id="pie-chart"></div>






      javascript tooltip pie-chart c3.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 9:57









      gothmogggothmogg

      34




      34
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The trouble, in a logical sense, is the pie chart is an aggregation of the area chart - you can't match up the tooltips for the data series in each chart one to one between them.



          If you highlighted a data series (a slice) in a pie chart, which of the 5 tooltips for that series would you expect to show up in the area chart? And if you tooltipped over one of the points in the area chart, would you expect the default tooltip for the pie chart to show up - which would show say 18.9% for the blue slice, when in reality you've only chosen/queried a small portion of it?



          You might be better to synchronise the highlighting rather than the tooltips, but there's a problem there when the points overlap in the area chart too



          http://jsfiddle.net/43ane5jk/1/



          var pieChart = c3.generate({
          bindto: d3.select('#pie-chart'),
          data: {
          columns: [
          [columns[0]].concat(data[0])
          ],
          type: 'pie',
          onmouseover: function(d, i) {
          if (areaChart)
          areaChart.focus(d.id);
          },
          onmouseout: function(d, i) {
          if (areaChart)
          areaChart.revert();
          },

          }
          });

          var areaChart = c3.generate({
          bindto: d3.select('#area-chart'),
          data: {
          columns: [
          [columns[0]].concat(data[0])
          ],
          type: 'area-spline',
          onmouseover: function(d, i) {
          if (pieChart)
          pieChart.focus(d.id);
          },
          onmouseout: function(d, i) {
          if (pieChart)
          pieChart.revert();
          },

          }
          });





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444374%2fc3js-synchronize-tooltips-of-areachart-and-piechart-showing-the-same-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The trouble, in a logical sense, is the pie chart is an aggregation of the area chart - you can't match up the tooltips for the data series in each chart one to one between them.



            If you highlighted a data series (a slice) in a pie chart, which of the 5 tooltips for that series would you expect to show up in the area chart? And if you tooltipped over one of the points in the area chart, would you expect the default tooltip for the pie chart to show up - which would show say 18.9% for the blue slice, when in reality you've only chosen/queried a small portion of it?



            You might be better to synchronise the highlighting rather than the tooltips, but there's a problem there when the points overlap in the area chart too



            http://jsfiddle.net/43ane5jk/1/



            var pieChart = c3.generate({
            bindto: d3.select('#pie-chart'),
            data: {
            columns: [
            [columns[0]].concat(data[0])
            ],
            type: 'pie',
            onmouseover: function(d, i) {
            if (areaChart)
            areaChart.focus(d.id);
            },
            onmouseout: function(d, i) {
            if (areaChart)
            areaChart.revert();
            },

            }
            });

            var areaChart = c3.generate({
            bindto: d3.select('#area-chart'),
            data: {
            columns: [
            [columns[0]].concat(data[0])
            ],
            type: 'area-spline',
            onmouseover: function(d, i) {
            if (pieChart)
            pieChart.focus(d.id);
            },
            onmouseout: function(d, i) {
            if (pieChart)
            pieChart.revert();
            },

            }
            });





            share|improve this answer


























              0














              The trouble, in a logical sense, is the pie chart is an aggregation of the area chart - you can't match up the tooltips for the data series in each chart one to one between them.



              If you highlighted a data series (a slice) in a pie chart, which of the 5 tooltips for that series would you expect to show up in the area chart? And if you tooltipped over one of the points in the area chart, would you expect the default tooltip for the pie chart to show up - which would show say 18.9% for the blue slice, when in reality you've only chosen/queried a small portion of it?



              You might be better to synchronise the highlighting rather than the tooltips, but there's a problem there when the points overlap in the area chart too



              http://jsfiddle.net/43ane5jk/1/



              var pieChart = c3.generate({
              bindto: d3.select('#pie-chart'),
              data: {
              columns: [
              [columns[0]].concat(data[0])
              ],
              type: 'pie',
              onmouseover: function(d, i) {
              if (areaChart)
              areaChart.focus(d.id);
              },
              onmouseout: function(d, i) {
              if (areaChart)
              areaChart.revert();
              },

              }
              });

              var areaChart = c3.generate({
              bindto: d3.select('#area-chart'),
              data: {
              columns: [
              [columns[0]].concat(data[0])
              ],
              type: 'area-spline',
              onmouseover: function(d, i) {
              if (pieChart)
              pieChart.focus(d.id);
              },
              onmouseout: function(d, i) {
              if (pieChart)
              pieChart.revert();
              },

              }
              });





              share|improve this answer
























                0












                0








                0






                The trouble, in a logical sense, is the pie chart is an aggregation of the area chart - you can't match up the tooltips for the data series in each chart one to one between them.



                If you highlighted a data series (a slice) in a pie chart, which of the 5 tooltips for that series would you expect to show up in the area chart? And if you tooltipped over one of the points in the area chart, would you expect the default tooltip for the pie chart to show up - which would show say 18.9% for the blue slice, when in reality you've only chosen/queried a small portion of it?



                You might be better to synchronise the highlighting rather than the tooltips, but there's a problem there when the points overlap in the area chart too



                http://jsfiddle.net/43ane5jk/1/



                var pieChart = c3.generate({
                bindto: d3.select('#pie-chart'),
                data: {
                columns: [
                [columns[0]].concat(data[0])
                ],
                type: 'pie',
                onmouseover: function(d, i) {
                if (areaChart)
                areaChart.focus(d.id);
                },
                onmouseout: function(d, i) {
                if (areaChart)
                areaChart.revert();
                },

                }
                });

                var areaChart = c3.generate({
                bindto: d3.select('#area-chart'),
                data: {
                columns: [
                [columns[0]].concat(data[0])
                ],
                type: 'area-spline',
                onmouseover: function(d, i) {
                if (pieChart)
                pieChart.focus(d.id);
                },
                onmouseout: function(d, i) {
                if (pieChart)
                pieChart.revert();
                },

                }
                });





                share|improve this answer












                The trouble, in a logical sense, is the pie chart is an aggregation of the area chart - you can't match up the tooltips for the data series in each chart one to one between them.



                If you highlighted a data series (a slice) in a pie chart, which of the 5 tooltips for that series would you expect to show up in the area chart? And if you tooltipped over one of the points in the area chart, would you expect the default tooltip for the pie chart to show up - which would show say 18.9% for the blue slice, when in reality you've only chosen/queried a small portion of it?



                You might be better to synchronise the highlighting rather than the tooltips, but there's a problem there when the points overlap in the area chart too



                http://jsfiddle.net/43ane5jk/1/



                var pieChart = c3.generate({
                bindto: d3.select('#pie-chart'),
                data: {
                columns: [
                [columns[0]].concat(data[0])
                ],
                type: 'pie',
                onmouseover: function(d, i) {
                if (areaChart)
                areaChart.focus(d.id);
                },
                onmouseout: function(d, i) {
                if (areaChart)
                areaChart.revert();
                },

                }
                });

                var areaChart = c3.generate({
                bindto: d3.select('#area-chart'),
                data: {
                columns: [
                [columns[0]].concat(data[0])
                ],
                type: 'area-spline',
                onmouseover: function(d, i) {
                if (pieChart)
                pieChart.focus(d.id);
                },
                onmouseout: function(d, i) {
                if (pieChart)
                pieChart.revert();
                },

                }
                });






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 28 '18 at 14:30









                mgrahammgraham

                4,60711217




                4,60711217






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444374%2fc3js-synchronize-tooltips-of-areachart-and-piechart-showing-the-same-data%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Berounka

                    Sphinx de Gizeh

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...