let data = [{
date:null,
close:'40',
},{
date:'2-May-12',
close:23,
},{
date:'3-May-12',
close:43,
},{
date:'4-May-12',
close:12,
},{
date:'5-May-12',
close:37,
},{
date:'6-May-12',
close:41,
},{
date:'7-May-12',
close:29,
},{
date:'8-May-12',
close:123,
}];
let element = d3.select('#dashboardLineChart').node();
let divWidth = element.getBoundingClientRect().width;
let divHeight = element.getBoundingClientRect().height;
// set the dimensions and margins of the graph
let margin = {top: 20, right: 30, bottom: 30, left: 20};
let width = divWidth - margin.left - margin.right;
let height = divHeight - margin.top - margin.bottom;
// parse the date / time
const parseTime = d3.timeParse("%d-%b-%y");
let y = d3.scaleLinear().range([height, 0]);
const tooltipStack = d3.select('body').append('div')
.attr('id', 'tooltip');
// define the line
const valueline = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); })
.curve(d3.curveMonotoneX);
// gridlines in y axis function
function make_y_gridlines() {
return d3.axisLeft(y)
.ticks(5)
}
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
let svg = d3.select("#dashboardLineChart").append("svg")
/* .attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom) */
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 " + (divWidth) + " " + (divHeight))
let graphContainer = svg.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Get the data
/* d3.csv("data.csv", function(error, data) { */
/* if (error) throw error; */
// format the data
data.forEach(function(d) {
d.date = parseTime(d.date);
d.close = +d.close;
});
y.domain([0, d3.max(data, function(d) { return d.close; })]);
// Add the Y Axis
let yAxisContainer =...
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.