Simple Line Chart Using D3 js with Animation, Value points and Tooltip

A Simple Line Chart Using D3 js with Animation, Value points and Tooltip

Inspired from great visualizations of data using d3js.org, a simple line chart using d3js with animation, value points and tooltip.



<!DOCTYPE html>
<html>
<head>
<style>
svg{
 background-color : none;
}
.axis{
 stroke : #0000001;
 fill : silver;
}
#tooltip{
 position : absolute;
 border : 1px solid #000;
 background-color : #ddd;
 padding : 5px;
 padding-left: 15px;
 padding-right : 15px;
 border-radius : 5px;
}


</style>
<script src="https://cdn.jsdelivr.net/d3js/3.4.12/d3.min.js" type="text/javascript"></script>
</head>
<body>
<svg id="my-line-chart" width="600" height="600"></svg>
<div id="tooltip"></div>
<script>
 drawLineChart();
 function drawLineChart(){

  var chartArea=d3.select('#my-line-chart');
  var lineData=[ { x: 0, y: 5},{ x: 20, y: 50 },{ x: 30, y: 45 },{ x: 40, y: 100 },{ x: 50, y: 65 },
    { x: 60, y: 75 },{ x: 70, y: 15 },{ x: 80, y: 85 },{ x: 90, y: 30 },{ x: 100, y: 0 }];

  //setting scale functions
  var xScale=d3.scale.linear().range([0,500]).domain(d3.extent(lineData, function(d){ return d.x;}));
  var yScale=d3.scale.linear().range([500,0]).domain(d3.extent(lineData, function(d){ return d.y;}));
  
  //setting axis functions
  xAxis = d3.svg.axis().scale(xScale).tickSize(2);
  yAxis = d3.svg.axis().scale(yScale).tickSize(2).ticks(20).orient("left");
  
  //drawing axes
  chartArea.append('g').attr('class','x axis').call(xAxis).attr('transform', 'translate(30,510)');
  chartArea.append('g').attr('class','y axis').call(yAxis).attr('transform', 'translate(30,10)');
  
  //line path generator function
  var linePathGenerator = d3.svg.line().x( function(d){
   return xScale(d.x);
  }).y(function(d){
   return yScale(d.y);
  });
  
  //drawing line 
  var linePath=chartArea.append('path').datum(lineData)
  .attr({
   'd' : linePathGenerator,
   'fill': 'none',
   'transform': 'translate(30,10)',
   'stroke': 'rgb(9, 112, 184)',
   'stroke-width' : 3
  });
  
  // animation 
  var pathLength = linePath.node().getTotalLength();
  linePath.attr({
   "stroke-dasharray" : pathLength  + " " + pathLength,
   "stroke-dashoffset" : pathLength
  }).transition().duration(3000).ease("linear")
  .attr("stroke-dashoffset", 0);
   
   //points
  var circlePoints=chartArea.selectAll('circle')
  .data(lineData)
  .enter()
  .append('circle')
  .attr({cx :  function(d){
   return xScale(d.x)+30;
  }, cy : function (d){
   return yScale(d.y)+10;
  }, r :8,
  fill : 'silver' 
  });
  
  // tooltip
  var div= d3.select('#tooltip');
  circlePoints.on("mouseover", function(d) {      
   div.transition()        
    .duration(200)      
                .style("opacity", .9);      
            div.html(d.y)  
               .style("left", (d3.event.pageX) + "px")     
               .style("top", (d3.event.pageY - 28) + "px");    
        }).on("mouseout", function(d) {       
            div.transition()        
                .duration(500)      
                .style("opacity", 0);   
        });
}
</script>
</body>
</html>

129 comments:

  1. Nice post you have done here. please check out this site Hotmail contact telephone number UK

    ReplyDelete
  2. I would like to thank you for the efforts you have made in writing this article.
    baixar facebook
    baixar whatsapp
    unblocked games

    ReplyDelete
  3. Thank you for that information you article
    i like play games games for kids friv online and play game friv games and games 2 girls ! have fun!

    ReplyDelete
  4. This article is really fantastic and thanks for sharing the valuable post.
    Signature:
    download free descargar whatsapp and descargar whatsapp gratis , baixar whatsapp gratis

    ReplyDelete
  5. Total Video Converter for Mac Total Video Converter for Mac is your best video converter for Mac to convert all videos to iPad, iPhone... Best all-in-one Video Converter for Mac.

    ReplyDelete
  6. I was working and suddenly I visits your site frequently and recommended it to me to read also. The writing style is superior and the content is relevant. Thanks for the insight you provide the readers!
    Signature:
    facebook entrar iniciar sesion gratis - Sitio Oficial iniciado sesiĆ³n en Facebook lengua espaƱola. facebook entrar rĆ”pido, facebook iniciar sesion en tu cuenta de entrar facebook

    ReplyDelete
  7. The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful
    kids games online , friv 2 , jogos do friv , juegosjuegos.com , juegos de matar zombbies
    , juegos de un show mas

    ReplyDelete
  8. I found a lot of information here to create this actually best for all newbie here. Thank you for this information.
    Signature:
    i like play games happy wheels online and play happy wheels 2 games and Download retrica online includes more than eighty different filters with many different styles and include retrica indir , and zombie tsunami is the ideal game for anyone who loves the running game genre

    ReplyDelete
  9. How often do you play games on free time or after hours of work stress? I usually come to the game as a way to
    manabadi ts ssc supplementary results 2017
    balance life is full of pressure. And I would recommend to everyone that I loved the game
    strike force heroes 2, strike force heroes 2 game, strike force heroes 3 , strike force heroes 2 game

    ReplyDelete
  10. Thanks for sharing this information with us, i always like to read these articles, cool..!
    24JobsExam Free Job Alert Bankers Adda
    Check 24JobsExam govt job Portal Placement Store

    ReplyDelete
  11. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
  12. Thanks!
    Amazing sharing content publicly and more informative.
    Nursery admission in private schools of Ghaziabad for academic session 2019-20
    The most popular place and education environment
    Indirapuram Public Schools Nursery Admission
    - DPS Indirapuram.

    ReplyDelete
  13. There are a lot of occasions to be in contact with the job world (workshops, presentations in front of the company, guest speakers, seminars).Along that blogs is helping through learn on different path to move on different career.
    Mobile phone service center in chennai | Laptop data recovery service in chennai | Mobile phone display replacement | Laptop battery replacement service in chennai | Laptop display replacement service in chennai | Mobile phone Water damage service | Dell laptop service center in chennai

    ReplyDelete
  14. Thanks for sharing such a good article and for informative things

    ReplyDelete
  15. I got what i am seraching from last few days in your Blog. I hope you will share more info about it. Please keep sharing.
    Laptop Service center in Ameerpet
    Dell Service center in Ameerpet
    HP Service center in Ameerpet
    Lenovo Service center in Ameerpet

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. Really your content is a very impressive!

    A list of international school in India. To check almost all CBSE, ICSE Schools in India. Click on the best school in Noida Extension 2019.

    ReplyDelete
  19. Hi!
    The most impressive posting a blog.
    Ranking of the Top 10 CBSE affiliated schools in Ghaziabad.

    ReplyDelete
  20. This is an amazing blog, thank you so much for sharing such valuable information with us.
    Visit for best logo and brochure designing services at- brochure designer in gurgaon.
    Thank you for sharing your wonderful information. for professional graphics,
    work contacts me. I am a freelance designer in gurgaon.
    Freelance Graphic Designing
    Freelance Catalogue Designing in delhi
    Freelance Catalogue Designing in gurgaon
    Freelance Brochure Designing
    Freelance Label Designing
    Freelance Banner Designer
    Freelance Poster Designer
    graphic design services in delhi
    graphic design services in gurgaon
    Freelance Catalogue Designing in delhi
    Freelance Catalogue Designing in gurgaon
    Freelance Brochure Designing
    Freelance Label Designing
    Freelance Banner Designer
    Freelance Poster Designer
    graphic design services in delhi
    graphic design services in gurgaon
    Freelance Catalogue Designing in delhi
    Freelance Catalogue Designing in gurgaon
    Freelance Brochure Designing
    Freelance Label Designing
    Freelance Banner Designer
    Freelance Poster Designer
    graphic design services in delhi
    graphic design services in gurgaon
    Freelance Catalogue Designing in delhi
    Freelance Catalogue Designing in gurgaon
    Freelance Brochure Designing
    Freelance Label Designing
    Freelance Banner Designer
    Freelance Poster Designer
    graphic design services in delhi
    graphic design services in gurgaon
    graphic designer in gurgaon
    freelance graphic designer in gurgaon
    freelance graphic designer in gurgaon
    freelance graphic designer in gurgaon
    freelance logo designer in gurgaon
    freelance logo designer in gurgaon
    freelance web designer in gurgaon

    ReplyDelete
  21. Google brain is working in the Hadoop consulting services to make it a huge success for the world. We hope that society will soon use AI devices at a reasonable cost.

    ReplyDelete
  22. This website is very helpful for those who are currently doing their computer engineering and those who are facing problems in coding like me. thank you
    -MyCodeCamp

    ReplyDelete
  23. You’d outstanding guidelines there. I did a search about the field and identified that very likely the majority will agree with your web page.

    JNU University BCOM 3rd Year Result 2020
    Berhampur University Odisha BCOM 3rd Year Result 2020
    Lucknow University BCOM 3rd Year Result 2020

    ReplyDelete
  24. Hello, Such A Nice Article. Great Share. Also, if You Are Looking for sofas reviews and Guides. then you can checkout here.
    https://sofareviewsguide.puzl.com/
    https://bestkidscouchreviews.blogspot.com/

    ReplyDelete
  25. Find here Electric Screwdriver,Kilews torque driver, Electrical Screwdriver manufacturers, suppliers & exporters in India. Kilews Electric Screwdrivers indiais regarded as the best quality electric screwdriver in India and has a very high reputation in the market.

    ReplyDelete
  26. Here is the site(bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
    MLSU BCOM 3rd Year Result 2020
    BA 3rd year Result 2019-20

    ReplyDelete
  27. Thanks admin for the nice post, Its really helpful to get lots of new information.

    learn .net Core

    ReplyDelete
  28. Seriously spectacular Post that You have shared here, This is an amazing superb article Keep Sharing this...
    Thanks, thanks to a lotttttttt!!!!

    Germany VPS Hosting

    ReplyDelete
  29. Bollywood News in Hindi - Check out the latest Bollywood news, new Hindi movie reviews, box office collection updates and latest Hindi movie videos. Download free HD wallpapers of Bollywood celebrities and recent movies and much more on Bollywood Hungama.

    the kings man full movie
    free guy full movie

    ReplyDelete
  30. There are you could get amazing information and easily control your all business startup.
    Domain Name Registration Sites

    ReplyDelete
  31. Hi,
    Nice explanation, thank you for sharing information about Chart Using D3 js. If you want get complete USA VPS Hosting Server Hosting solution, then click the link.

    ReplyDelete
  32. This comment has been removed by the author.

    ReplyDelete
  33. That is a mind-blowing blog post. Such loving information if think everyone wanna read this blog post and grasp lot of ideas, So I here am also one place where you could Cheak Domain Name Onlineand share your ideas and interesting thoughts with is loved new generation people.

    ReplyDelete
  34. Waw, that post is amazing every business need branding, so for a brand, social media platform is most helpful in your business branding. and in this blog, we got a lot of guidance on social media managing.
    Book Domain Name Registration Online

    ReplyDelete
  35. Have you encountered Quickbooks Error C=343? QuickBooks Error Code C=343 occurs when you are unable to access the company file and this generally happens when Quickbooks is not updated. if you are still facing any issue to fix Quickbooks Error C=343, you can reach out to Quickbooks enterprise support number at 1-888-485-0289.

    ReplyDelete
  36. Are you struggling to fix Quickbooks error C=51. QuickBooks Error Code C=51 is a database error which arrives when Quickbooks fails to find the TxList. QuickBooks Error Code C=51. For any issues, you can reach out to Quickbooks enterprise support at 1-888-485-0289.

    ReplyDelete
  37. this post is amazing
    Best Indian Astrologer in Sydney Famous Astrologer in Sydney Australia
    astrologer in Sydney

    ReplyDelete
  38. Thanks for providing such excellent information about Time Tracking Software, I have learned so much. I hope you will continue to share interesting content about this topic.

    Visit: Time Tracking Software

    ReplyDelete
  39. All type services start in Bihar Govt go to see this services and help for filling form RTPS Bihar

    ReplyDelete
  40. great post. very informative. you may also like to read the blog on gaskets - Gasco INC. one of the leadingGasket Manufacturer in India 

    ReplyDelete
  41. great post. very informative. you may also like to read the blog on Inox India Steel - one of the biggest leading aluminium plate manufacturer in india and has substantial expertise in the manufacturing and supplying of all sorts of Aluminium Plate worldwide. 

    ReplyDelete
  42. Great...Thank you for sharing this. Contact Astrologer Sharma Ji, who offers effective Astrology solutions to many Canadians. Famous Astrologer in Scarborough | Good Astrologer in Scarborough | Psychic Reader in Scarborough | Palm Reader in Scarborough | Fortune Teller in Scarborough

    ReplyDelete
  43. Welcome to CapturedCurrentNews – Latest & Breaking India News 2021
    Hello Friends My Name Anthony Morris.latest and breaking news linkfeeder

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. Nice!! intresting post, you will be also intrested in knowing about API 5L X65 PSL1 / PSL2 Pipe Manufacturer in India. It is one of the best manufacterer, supplier, Expoter and stockist company.

    ReplyDelete
  46. This comment has been removed by the author.

    ReplyDelete
  47. Thank you for sharing this vital information with us and assisting us in achieving our goal. You may go here. ERW Pipes Manufacturer in India, ERW Pipe Suppliers in Dubai, ERW Pipe Suppliers in UAE, Shashwat Stainless Inc.

    ReplyDelete
  48. Thank You for sharing this informative blog
    Visit our blog: Stainless Steel Flanges
    You may also like: Slip on Flanges
    Website: https://vihaforge.com

    ReplyDelete
  49. This comment has been removed by the author.

    ReplyDelete
  50. This comment has been removed by the author.

    ReplyDelete
  51. Nice info also check Stainless Steel 316 Wire and visit our website at Timex Metals.We also deal with Round Bars, SS Wire Rods, and many more.

    ReplyDelete
  52. Thank you for sharing this vital information with us.
    Website: Caliber Enterprises
    For more info visit us: Fasteners manufacturers in India
    Also visit: Fasteners Manufacturers in Mumbai

    ReplyDelete
  53. Thank You for sharing this excellent blog. It was very helpful. Also read Blogs on High Tensile Nut Bolt Manufacturer in India, High Tensile Nut Bolt Manufacturer, and related blogs High Tensile Fasteners, High Tensile Screws, Also visit our website Ananka Fasteners.

    ReplyDelete
  54. Good Blog, I got a lot of new information. Also check out our blog what is white hat and black hat seo, Google Services, and do you know What Is WordPress? If not check out our blog.If you like these blogs visit F60 Host For more such blogs.

    ReplyDelete
  55. Nice Post. Thank You for sharing.
    Do visit our blog: Pure Copper Earthing Electrode
    You may also like: Copper Bonded Electrode

    ReplyDelete
  56. Thank you for sharing this useful blog with us.
    Do visit our website: Aluminium Bronze Bar, Aluminium Bronze Bar Manufacturers, Aluminium Bronze Bar Suppliers



    ReplyDelete
  57. I’m amazed with your blog, got a lot of information.
    Also check out our blog Pipe Fittings Manufacturer
    You can also check Pipe Fittings supplier and Flanges Manufacturer in India.

    ReplyDelete
  58. Nice Info, also check wire mesh manufacturer in India and visit our website at Bhansali Steel.We Manufacture various types of steel products like Perforated Sheet and Welded Wire Mesh.

    ReplyDelete
  59. Thank You for sharing this informative blog, please also check out: Single Piece Design Ball Valves, Two way Ball Valves, Three Way Ball Valves and Four Way Ball Valves

    ReplyDelete
  60. Great article. Keep writing such kind of information on your blog.

    Biobanks | biorepositories
    human-samples | patient-samples

    ReplyDelete
  61. Thank you for this amazing blog, for posting this vital information with all of us.
    Website: veraizenearthing.com
    For more details visit: Pure Copper Earthing Electrode Suppliers
    You may also like: Copper Bonded Electrode

    ReplyDelete
  62. Hi,
    Thanks for sharing your blog. It was really good. If you're looking for self storage solutions then you must consider Spacebox Birmingham. They are committed to providing services to clients that work With 10+ years of experience and a diverse portfolio, Spacebox is able to cater and design services for most businesses.

    ReplyDelete
  63. Hii your content is so useful.
    thankyou author.
    if you want to learn about URL then click on my profile and visit my web page

    ReplyDelete

  64. very informative and impressive article. Thanks for sharing with us
    cyfuture cloud

    ReplyDelete
  65. Great post! Glad to read and see your post. We all love and appreciate this kind of post. However, if someone is not able to write an assignment, we at No1AssignmentHelp.Com are available 24x7 to help you in completing your assignment. We provide Assignment Help written by the professional writers hired by us for your assignment writing.

    ReplyDelete
    Replies
    1. Thank you for providing this kind of informatio, I Really liked reading it. I like your writing style, it’s quite unique. Thanks for sharing the information here. and please read The Most Important Features of Microsoft Azure in 2023

      Delete
  66. Great post! Glad to read and see your post. We all love and appreciate this kind of post. However, if someone is not able to write an assignment, we at No1AssignmentHelp.Com are available 24x7 to help you in completing your assignment. We provide Assignment Help written by the professional writers hired by us for your assignment writing.
    HASHCRON Technologies

    ReplyDelete
  67. Impressive posting, really liked reading it. I like your writing style, it’s quite unique. Thanks for sharing the information here. Become a Certified DevOps Expert with Comprehensive DevOps Training

    ReplyDelete
  68. Animation design is employed in film to entertain. In today's society, animation is used to promote businesses. It's my pastime to create animation designs, and I'm pleased with the results.
    Local SEO Citations

    ReplyDelete
  69. Immerse yourself in our Best Mern Stack Course In South Delhi , a program crafted to provide you with a comprehensive grasp of full-stack web development using the MERN technology.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...