javascript - Mouseover Line on multiple charts when hover on single chart using D3 -


please advice if there difficulty in understanding question. that, can edit question , provide required information.

i want show line , tooltip on multiple charts when hover on single chart.

in following chart, able line on single chart, want line should continue till x-axis , tooltip highlighted value on multiple charts.

following jsfiddle have worked till now.

                            $(window).load(function () {                                                     var textareas$ = $('#chartarea g');                                                          textareas$.hide();                                                    $('input[name="air"]').change(function () {                                                      var elem$ = $(this);                                                      var correspelem$ = textareas$.eq(elem$.val() - 1);                                                                                                                    if (elem$.val() == 1) {                                                                                  select('retail', "#retail");                                                                  } else if (elem$.val() == 2) {                                                                                  select("gas", "#gas");                                                                  } else if (elem$.val() == 3) {                                                                                  select("dining", "#dining");                                                                  } else {};                                                                  if (elem$.is(':checked')) correspelem$.show();                                                                  else correspelem$.hide();                                                                   var lastselectedchartindex;                  var chartaxis = document.queryselectorall('#chartarea  .axis.x');                                    var selectedcharts = document.queryselectorall('#options input').foreach((elem, index) => {                  if (elem.checked) {                  	lastselectedchartindex = index;                  }                  });                                    //console.log(lastselectedchartindex)                                    chartaxis                  	.foreach((elem, index) => (index !== chartaxis.length - 1) && !(index == lastselectedchartindex) ? elem.style.display = 'none' : elem.style.display = 'block')                                                            });                                                  });

snapshot

i updated jsfiddle have working. used vscode , reindented code, hope ok you. did is:

  • create event dispatcher in chart
  • creating callback on dispatcher event
  • select lines
  • set position

the callback looks this:

chart.onhover(function (x) {     console.log(x);     d3.selectall('.hover-line')         .select('line')         .attr('x1', x)         .attr('x2', x)         .style('opacity', 1) }) 

this works, don't fact gets reselected every time. should possible subscribe event directly when calling chart, can't wrap head around it.


Comments

Popular posts from this blog

javascript - generate date range base on integers -

PHP and MySQL WP -