Sunday, March 26, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home JavaScript

Vertical line and tooltip wherever the line hits a data point – JavaScript – SitePoint Forums

learningcode_x1mckf by learningcode_x1mckf
November 1, 2022
in JavaScript
0
Time limit for notify – JavaScript – SitePoint Forums
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


You might also like

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites – GBHackers

4 Ways to Remove a Specific Item From a JavaScript Array – MUO – MakeUseOf

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack


Dvdscot



October 31, 2022, 10:18am
#1

Hey, I’m again after an extended illness.

My subsequent process is to attract a vertical line wherever the mouse is, when this line hits a knowledge level of a graph it reveals the tooltip. I already found that it’s important to use bisector for that, so will attempt one thing and get again to this subject if I’m caught.


Dvdscot



October 31, 2022, 2:33pm
#2

So I’m making an attempt so as to add a line that strikes with the mouse and improve the tooltip.

Utilizing code from right here:

bl.ocks.org

Adding a Mouse Marker to a Line Graph in D3.js

Peter Barker’s Block 7684278

d3-graph-gallery.com

Line chart with cursor for exact values

Utilizing d3.js to create a line chart with a a cursor that show the precise worth of the closest X axis worth.

https://vizartpandey.com/line-chart-how-to-show-data-on-mouseover-using-d3-js/

Have to make use of invert and bisect in some way, my case is extra difficult than these examples given.
I assumed I’ve outlined circle but it surely says circle not outlined.

A bit like right here:
https://stackoverflow.com/questions/53595181/how-do-i-have-a-line-follow-the-mouse-on-hover-but-also-have-zoom-in-chart
https://jsfiddle.net/zkdxrtuc/8/


Dvdscot



November 1, 2022, 9:03am
#3

I copied this code 1:1 into my editor (upgraded to d3.v5) and each packages give me error messages.

bl.ocks.org

Adding a Mouse Marker to a Line Graph in D3.js

Peter Barker’s Block 7684278

Uncaught TypeError: Can’t learn properties of undefined (studying ‘scale’) at Bisect.html:45:22

d3-graph-gallery.com

Line chart with cursor for exact values

Utilizing d3.js to create a line chart with a a cursor that show the precise worth of the closest X axis worth.

Bisect2.html:100 Uncaught TypeError: Can’t learn properties of undefined (studying ‘x’)
at SVGRectElement.mousemove (Bisect2.html:100:38)
at SVGRectElement. (d3.v5.js:1526:16)

My intention was to edit these first to incorporate a line as a substitute of a circle after which put it into my program proven in Codepen.

So proper now, your mousemove code is searching for one thing known as circle, however that’s not outlined. (It was solely outlined by way of the movetooltip perform, as a result of that perform wanted to know what “circle” was being hovered over.

Even when it did resolve the reference to circle, it will then complain that it cant resolve a perform known as x, as a result of that must be your scale. It might additionally complain that your information doesn’t include an x property (as a result of your information isnt an object, its a 2 dimensional array).

I’m… considerably unclear what you’re particularly making an attempt to do at this actual second, however lets do this;

As a substitute of transferring the circle, inform your VertLine to maneuver itself on the x axis.

Issues I needed to do to get your code to work accurately: (No, i’m not supplying you with the code but, however pointers :P)

  • The mousemove occasion ought to as a substitute by a pointermove occasion sure to the SVG itself.
  • You’ll need a bisector with an accessor perform pointing on the x worth of the 2 dimensional information array.
  • The mouse, now sure to the SVG, just isn’t translated; so that you’ll want to regulate the x-coordinate obtained from the mouse to compensate.
  • As a result of the SVG is wider than your dataset, you will have to deal with the sting case that the bisector returns a worth that may be on the finish of the brand new array.

Bonus, which can be useful later:

  • I used a line as a substitute of a rect. As a result of it’s a line.


Dvdscot



November 1, 2022, 11:25am
#6

My authentic code in Codepen or the copied code from these two examples? My one is extra essential.

The code that you just Codepenned in put up 2.


Dvdscot



November 1, 2022, 11:40am
#8

Most code I’ve seen place an invisible rect over the graph for all the flowery graphic actions.

Very first thing I wanna do is show a vertical line wherever the mouse is. Like right here:

jsfiddle.net

Dual-Y Example – JSFiddle – Code Playground

Check your JavaScript, CSS, HTML or CoffeeScript on-line with JSFiddle code editor.

You’ll be able to see in my end result that I added a static line.

No tooltip but.

Copied that a part of the code right here:

var mouseG = svg.append("g")
      .attr("class", "mouse-over-effects");

mouseG.append("path") // that is the black vertical line to comply with mouse
      .attr("class", "mouse-line")
      .fashion("stroke", "black")
      .fashion("stroke-width", "1px")
      .fashion("opacity", "0");

var traces = focus.selectAll('path');

var mousePerLine = mouseG.selectAll('.mouse-per-line')
      .information(d3.vary(traces.size))
      .enter()
      .append("g")
      .attr("class", "mouse-per-line")
      .attr('pointer-events', 'none');

// the circle
mousePerLine.append("circle")
  .attr("r", 7)
  
  .fashion("stroke", perform(d) 
    return 'pink';
  )
  .fashion("fill", "none")
  .fashion("stroke-width", "1px")
  .fashion("opacity", "0");

perform showLine()
   d3.choose(".mouse-line")
      .fashion("opacity", "0");
 
 perform hideLine()
    d3.choose(".mouse-line")
      .fashion("opacity", "1");
 
  
svg.choose(".zoom")
  .on('mouseenter', showLine)
  .on('mouseleave', hideLine)
  .on('mousemove', perform() { // mouse transferring over canvas
    var mouse = d3.mouse(this);
    //showLine();
    // transfer the vertical line
    d3.choose(".mouse-line")
      .attr("d", perform() 
        var d = "M" + (mouse[0] + margin.left) + "," + (top + margin.prime);
        d += " " + (mouse[0] + margin.left) + "," + margin.prime;
        return d;
      );

You are able to do it that means too, it was simply simpler out of your present graph building for me to bind it to the SVG as a complete. shrug both means works.


Dvdscot



November 1, 2022, 12:16pm
#10

That JSFiddle instance code doesn’t work for me, there’s an error message within the D3.

I wanna add this line performance to the prevailing one, i.e. preserve the present tooltip code for now and solely take away it when the road model lastly works. Tried this now, no error messages however not working both:

        let VertLine = svg.append('line')
            .attr("remodel","translate(150,100)")
            .fashion("stroke", "black")
            .fashion("stroke-width", 2)
            .attr("x1", 0)
            .attr("y1", 0)
            .attr("x2", 0)
            .attr("y2", top);

        perform mousemove()
            var x0 = xScale.invert(d3.mouse(this)[0]);
            var i1 = bisect(dataset1, x0, 1);
            var i2 = bisect(dataset2, x0, 1);
            var i3 = bisect(dataset3, x0, 1);
            selectedData1 = dataset1[i1]
            selectedData2 = dataset1[i2]
            selectedData3 = dataset1[i3]
            VertLine
              .attr("cx", xScale(selectedData1.xScale))
              .attr("cy", yScale(selectedData1.yScale))
        

Properly for starters, a line doesnt have a cx or cy…

Secondly, that code must be throwing an error, as a result of your datapoint doesnt have a “xScale” attribute.


Dvdscot



November 1, 2022, 12:20pm
#12

x1 and y1, that code nonetheless references to a rectangle. The code the place I took it from makes use of x as a variable, I used xScale as a substitute.

 var x = d3.scaleLinear()
    .area([1,100])
    .vary([ 0, width ]);
  svg.append("g")
    .attr("remodel", "translate(0," + top + ")")
    .name(d3.axisBottom(x));

So… let’s deal with the factors that I laid out earlier than, one after the other.

m_hutley:

The mousemove occasion ought to as a substitute by a pointermove occasion sure to the SVG itself.

Proper now, your code binds a perform on mousemove, and tries to bind it to:
a nonexistant component class .zoom,
every dot of the pink line,
every dot of the blue line,
and every dot of the inexperienced line.

As a substitute, you will have to bind a pointermove occasion to an current component.



Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites – GBHackers

by learningcode_x1mckf
March 25, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Hackers Inject Weaponized JavaScript (JS) on 51,000 Websites  GBHackers Source link

Read more

4 Ways to Remove a Specific Item From a JavaScript Array – MUO – MakeUseOf

by learningcode_x1mckf
March 24, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

4 Ways to Remove a Specific Item From a JavaScript Array  MUO - MakeUseOf Source link

Read more

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Toolkit Allows JavaScript Devs to Program Embedded Devices  The New Stack Source link

Read more

Select data value from grandparent div? – JavaScript – SitePoint

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Select data value from grandparent div? - JavaScript  SitePoint Source link

Read more

How to Handle Errors in JavaScript – Programming – MUO – MakeUseOf

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Handle Errors in JavaScript - Programming  MUO - MakeUseOf Source link

Read more
Next Post
Java Web Frameworks Software Market Most Dominant Streaming Segment Analysis and Forecast 2030 – Technology Today

Java Web Frameworks Software Market Most Dominant Streaming Segment Analysis and Forecast 2030 - Technology Today

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Utilizing Makefiles for Swift projects

Utilizing Makefiles for Swift projects

January 10, 2023
New JavaScript runtime Bun challenges Deno, Node.js

New JavaScript runtime Bun challenges Deno, Node.js

October 27, 2022
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

JavaScript Typeof for Data Types: Array, Boolean and More – Built In

February 11, 2023

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • 2023 Java roadmap for developers – TheServerSide.com
  • YS Jagan launches Ragi Java in Jagananna Gorumudda, says focused on intellectual development of students – The Hans India
  • Disadvantages of Java – TheServerSide.com

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?