D3JS Simple JSON SVG barchart vertical with Axis
How do I make an d3js simple json svg barchart vertical with axis?
From tutorial http://bost.ocks.org/mike/bar/2/. What is a d3js simple json svg barchart vertical with axis? How do you make a d3js simple json svg barchart vertical with axis? This script and codes were developed by Dzulfikar Adi Putra on 06 September 2022, Tuesday.
D3JS Simple JSON SVG barchart vertical with Axis - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>D3JS Simple JSON SVG barchart vertical with Axis</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h2>D3JS Simple JSON SVG barchart Horizontal with Axis</h2>
<i>using simple JSON data</i><br/>
taken from <a href="https://bost.ocks.org/mike/bar/3/">https://bost.ocks.org/mike/bar/3/</a> <br/><br/>
<div id="chart"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://d3js.org/d3.v3.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
D3JS Simple JSON SVG barchart vertical with Axis - Script Codes CSS Codes
#chart rect{ fill: #4aaeea;
}
#chart text{ fill: white; font: 10px sans-serif; text-anchor: end;
}
.axis text{ font: 10px sans-serif;
}
.axis path, .axis line{ fill: none; stroke : #fff; shape-rendering: crispEdges;
}
body{ background: #1a1a1a; color : #eaeaea; padding : 10px;
}
D3JS Simple JSON SVG barchart vertical with Axis - Script Codes JS Codes
var margin ={top:20, right:30, bottom:30, left:40}, width=960-margin.left - margin.right, height=500-margin.top-margin.bottom;
// scale to ordinal because x axis is not numerical
var x = d3.scale.ordinal().rangeRoundBands([0, width], .1);
//scale to numerical value by height
var y = d3.scale.linear().range([height, 0]);
var chart = d3.select("#chart") .append("svg") //append svg element inside #chart .attr("width", width+(2*margin.left)+margin.right) //set width .attr("height", height+margin.top+margin.bottom); //set height
var xAxis = d3.svg.axis() .scale(x) .orient("bottom"); //orient bottom because x-axis will appear below the bars
var yAxis = d3.svg.axis() .scale(y) .orient("left");
d3.json("https://codepen.io/superpikar/pen/kcJDf.js", function(error, data){ x.domain(data.map(function(d){ return d.letter})); y.domain([0, d3.max(data, function(d){return d.frequency})]); var bar = chart.selectAll("g") .data(data) .enter() .append("g") .attr("transform", function(d, i){ return "translate("+x(d.letter)+", 0)"; }); bar.append("rect") .attr("y", function(d) { return y(d.frequency); }) .attr("x", function(d,i){ return x.rangeBand()+(margin.left/4); }) .attr("height", function(d) { return height - y(d.frequency); }) .attr("width", x.rangeBand()); //set width base on range on ordinal data bar.append("text") .attr("x", x.rangeBand()+margin.left ) .attr("y", function(d) { return y(d.frequency) -10; }) .attr("dy", ".75em") .text(function(d) { return d.frequency; }); chart.append("g") .attr("class", "x axis") .attr("transform", "translate("+margin.left+","+ height+")") .call(xAxis); chart.append("g") .attr("class", "y axis") .attr("transform", "translate("+margin.left+",0)") .call(yAxis) .append("text") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("Frequency");
});
function type(d) { d.letter = +d.letter; // coerce to number return d; }
Developer | Dzulfikar Adi Putra |
Username | superpikar |
Uploaded | September 06, 2022 |
Rating | 3 |
Size | 2,699 Kb |
Views | 36,432 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Force Layout Directed Graph using dot engine dagre-d3js library, data from JSON | 6,536 Kb |
Play and Pause Bootstrap 3 Button | 2,255 Kb |
Ionic Alphabetical List | 3,136 Kb |
D3JS Simple JSON SVG barchart vertical | 2,234 Kb |
Bulma breadcrumbs | 1,895 Kb |
SVG Animation Follow Path - d3js | 3,068 Kb |
D3js animation along path | 3,128 Kb |
JS Tree Example JSON Data | 2,435 Kb |
Multiple Expand Collapse | 2,733 Kb |
Centering Image and Icon in Semantic-UI card | 2,546 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Zip Button test | Lje7462 | 1,932 Kb |
Halo 5 REQ Guide Bookmarklet | Cwacht | 3,993 Kb |
Two column of responsive height | Fixie | 2,908 Kb |
Haml Calendar | Katydecorah | 5,643 Kb |
Countdown with Rings | Ewganoel | 2,490 Kb |
Wikipedia API | Coderpilot | 2,802 Kb |
Sticky notes with CSS3 | HaiNguyen007 | 2,146 Kb |
Lazy Load for Background Images | The_ruther4d | 2,977 Kb |
Animated Logo | Shakdaniel | 2,672 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!