Created
November 7, 2015 17:03
-
-
Save anonymous/22e3556b6bf6caa3bc98 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ciluge
This file contains 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> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var h = 350; | |
var w = 400; | |
var lineFun = d3.svg.line() | |
.x(function(d) { return d.month*3; }) | |
.y(function(d) { return h-d.sales; }) | |
.interpolate("basis"); | |
var monthlySales = [ | |
{"month": 10, "sales": 100}, | |
{"month": 20, "sales": 130}, | |
{"month": 30, "sales": 250}, | |
{"month": 40, "sales": 300}, | |
{"month": 50, "sales": 265}, | |
{"month": 60, "sales": 225}, | |
{"month": 70, "sales": 180}, | |
{"month": 80, "sales": 120}, | |
{"month": 90, "sales": 145}, | |
{"month": 100, "sales": 130} | |
]; | |
function salesKPI(d) { | |
if(d>=250) { return "#33CC66"; } | |
else if(d<250) { return "#666666"; } | |
} | |
function showMinMax(ds, col, val, type) { | |
var max = d3.max(ds, function(d) { return d[col]; }); | |
var min = d3.min(ds, function(d) { return d[col]; }); | |
if(type =='minmax' && (val==max || val==min)) { | |
return val; | |
} else { | |
if (type == 'all') { | |
return val; | |
} | |
} | |
} | |
var svg = d3.select("body").append("svg").attr({width:w, height:h}); | |
var dots = svg.selectAll("circle").data(monthlySales).enter() | |
.append("circle") | |
.attr({ | |
cx: function(d) { return d.month * 3; }, | |
cy: function(d) { return h-d.sales; }, | |
r: 5, | |
"fill": function(d) { return salesKPI(d.sales); } | |
}); | |
var labels = svg.selectAll("text").data(monthlySales).enter() | |
.append("text") | |
.text(function(d) { return showMinMax(monthlySales, 'sales', d.sales, 'minmax'); }) | |
.attr({ | |
x: function(d) { return (d.month*3)-25; }, | |
y: function(d) { return h-d.sales; }, | |
"font-size": "12px", | |
"font-family": "sans-serif", | |
"fill": "#666666", | |
"text-anchor": "start" | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var h = 350; | |
var w = 400; | |
var lineFun = d3.svg.line() | |
.x(function(d) { return d.month*3; }) | |
.y(function(d) { return h-d.sales; }) | |
.interpolate("basis"); | |
var monthlySales = [ | |
{"month": 10, "sales": 100}, | |
{"month": 20, "sales": 130}, | |
{"month": 30, "sales": 250}, | |
{"month": 40, "sales": 300}, | |
{"month": 50, "sales": 265}, | |
{"month": 60, "sales": 225}, | |
{"month": 70, "sales": 180}, | |
{"month": 80, "sales": 120}, | |
{"month": 90, "sales": 145}, | |
{"month": 100, "sales": 130} | |
]; | |
function salesKPI(d) { | |
if(d>=250) { return "#33CC66"; } | |
else if(d<250) { return "#666666"; } | |
} | |
function showMinMax(ds, col, val, type) { | |
var max = d3.max(ds, function(d) { return d[col]; }); | |
var min = d3.min(ds, function(d) { return d[col]; }); | |
if(type =='minmax' && (val==max || val==min)) { | |
return val; | |
} else { | |
if (type == 'all') { | |
return val; | |
} | |
} | |
} | |
var svg = d3.select("body").append("svg").attr({width:w, height:h}); | |
var dots = svg.selectAll("circle").data(monthlySales).enter() | |
.append("circle") | |
.attr({ | |
cx: function(d) { return d.month * 3; }, | |
cy: function(d) { return h-d.sales; }, | |
r: 5, | |
"fill": function(d) { return salesKPI(d.sales); } | |
}); | |
var labels = svg.selectAll("text").data(monthlySales).enter() | |
.append("text") | |
.text(function(d) { return showMinMax(monthlySales, 'sales', d.sales, 'minmax'); }) | |
.attr({ | |
x: function(d) { return (d.month*3)-25; }, | |
y: function(d) { return h-d.sales; }, | |
"font-size": "12px", | |
"font-family": "sans-serif", | |
"fill": "#666666", | |
"text-anchor": "start" | |
});</script></body> | |
</html> |
This file contains 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
var h = 350; | |
var w = 400; | |
var lineFun = d3.svg.line() | |
.x(function(d) { return d.month*3; }) | |
.y(function(d) { return h-d.sales; }) | |
.interpolate("basis"); | |
var monthlySales = [ | |
{"month": 10, "sales": 100}, | |
{"month": 20, "sales": 130}, | |
{"month": 30, "sales": 250}, | |
{"month": 40, "sales": 300}, | |
{"month": 50, "sales": 265}, | |
{"month": 60, "sales": 225}, | |
{"month": 70, "sales": 180}, | |
{"month": 80, "sales": 120}, | |
{"month": 90, "sales": 145}, | |
{"month": 100, "sales": 130} | |
]; | |
function salesKPI(d) { | |
if(d>=250) { return "#33CC66"; } | |
else if(d<250) { return "#666666"; } | |
} | |
function showMinMax(ds, col, val, type) { | |
var max = d3.max(ds, function(d) { return d[col]; }); | |
var min = d3.min(ds, function(d) { return d[col]; }); | |
if(type =='minmax' && (val==max || val==min)) { | |
return val; | |
} else { | |
if (type == 'all') { | |
return val; | |
} | |
} | |
} | |
var svg = d3.select("body").append("svg").attr({width:w, height:h}); | |
var dots = svg.selectAll("circle").data(monthlySales).enter() | |
.append("circle") | |
.attr({ | |
cx: function(d) { return d.month * 3; }, | |
cy: function(d) { return h-d.sales; }, | |
r: 5, | |
"fill": function(d) { return salesKPI(d.sales); } | |
}); | |
var labels = svg.selectAll("text").data(monthlySales).enter() | |
.append("text") | |
.text(function(d) { return showMinMax(monthlySales, 'sales', d.sales, 'minmax'); }) | |
.attr({ | |
x: function(d) { return (d.month*3)-25; }, | |
y: function(d) { return h-d.sales; }, | |
"font-size": "12px", | |
"font-family": "sans-serif", | |
"fill": "#666666", | |
"text-anchor": "start" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment