.xaxis text, .yaxis text{
fill : blue
}
.xaxis path, .xaxis line{
stroke-width : 1px;
fill : none;
stroke : red
}
.yaxis path, .yaxis line{
fill : none;
stroke-width:1px;
stroke : red
}
JavaScript
var width = 700,
height = 500,
padding = 50;
// create an svg container
var vis = d3.select("body").
append("svg")
.attr("width", width)
.attr("height", height);
// define the y scale (vertical)
var yScale = d3.scaleLinear()
.domain([0, 100]) // values between 0 and 100
.range([height - padding, padding]); // map these to the chart height, less padding.
//REMEMBER: y axis range has the bigger number first because the y value of zero is at the top of chart and increases as you go down.
// define the x scale (horizontal)
var mindate = new Date(2018,0,1),
maxdate = new Date(2018,0,31);
var xScale = d3.scaleTime()
.domain([mindate, maxdate]) // values between for month of january
.range([padding, width - padding * 1]); // map these the the chart width = total width minus padding at both sides
// define the y axis
var yAxis = d3.axisLeft()
.scale(yScale);
// define the y axis
var xAxis = d3.axisBottom()
.scale(xScale);
// draw y axis with labels and move in from the size by the amount of padding
vis.append("g")
.attr("class", "yaxis")
.attr("transform", "translate("+padding+",0)")
.call(yAxis);
// draw x axis with labels and move to the bottom of the chart area
vis.append("g")
.attr("class", "xaxis") // give it a class so it can be used to select only xaxis labels below
.attr("transform", "translate(0," + (height - padding) + ")")
.call(xAxis);
// now rotate text on x axis
// solution based on idea here: https://groups.google.com/forum/?fromgroups#!topic/d3-js/heOBPQF3sAY
// first move the text left so no longer centered...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.