Built with blockbuilder.org
Last active
January 21, 2020 19:46
-
-
Save tomshanley/bf25690125b97b36db71cd5869c7d58f to your computer and use it in GitHub Desktop.
fresh block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <style> | |
| body { margin:50;top:50;right:50;bottom:50;left:50; } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| console.clear() | |
| let width = 500 | |
| let height = 500 | |
| let radius = 10 | |
| let data = [ | |
| {"date": "date1", "value": 41.5}, | |
| {"date": "date2", "value": 35.5}, | |
| {"date": "date3", "value": 36}, | |
| {"date": "date4", "value": 34}, | |
| {"date": "date5", "value": 34}, | |
| {"date": "date6", "value": 36}, | |
| {"date": "date7", "value": 37}, | |
| {"date": "date8", "value": 40}, | |
| {"date": "date9", "value": 39.5}, | |
| {"date": "date10", "value": 38.5}, | |
| ] | |
| let xScale = d3.scaleBand() | |
| .domain(data.map(d => d.date)) | |
| .range([0, width]) | |
| let yScale = d3.scaleLinear() | |
| .domain([0, 45]) | |
| .range([height, 0]) | |
| let path = d3.line() | |
| .x(d => xScale(d.date)) | |
| .y(d => yScale(d.value)) | |
| .curve(d3.curveCardinal) | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height) | |
| svg.append("path") | |
| .datum(data) | |
| .attr("d", path) | |
| .style("stroke", "black") | |
| .style("fill", "none") | |
| svg.selectAll("circle") | |
| .data(data) | |
| .enter() | |
| .append('circle') | |
| .attr("cx", d => xScale(d.date)) | |
| .attr("cy", d => yScale(d.value)) | |
| .attr("r", radius) | |
| .style("stroke", "black") | |
| .style("fill", "white") | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment