Last active
December 7, 2015 02:38
D3 Formatting Example
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
<html> | |
<head> | |
<link href="https://rawgithub.com/palantir/plottable/develop/plottable.css" rel="stylesheet"/> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://rawgithub.com/palantir/plottable/develop/plottable.js"></script> | |
</head> | |
<body> | |
<div id="container"> | |
<svg id="chart" width="350" height="350"></svg> | |
</div> | |
</body> | |
<script> | |
var store = [{ Name:"Item 1", Total:18.73424242 }, | |
{ Name:"Item 2", Total:7.34311 }, | |
{ Name:"Item 3", Total:3.1235535}, | |
{ Name:"Item 4", Total:12.763574}]; | |
var colorScale = new Plottable.Scales.Color(); | |
var legend = new Plottable.Components.Legend(colorScale); | |
var pie = new Plottable.Plots.Pie() | |
.attr("fill", function(d){ return d.Name; }, colorScale) | |
.addDataset(new Plottable.Dataset(store)) | |
.sectorValue(function(d){ return +d.Total.toFixed(2); } ) | |
//.sectorValue(function(d){ return +d3.format('0.2f')(d.Total); } ) //this works too | |
.labelsEnabled(true); | |
new Plottable.Components.Table([[pie, legend]]).renderTo("#chart"); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gist created in response to http://stackoverflow.com/questions/34124949/how-to-format-number-precision-to-two-digit-decimals-in-plottable-js-piechart-la/34125335#34125335