dimple/examples/advanced_grouped_mekko.html

48 lines
1.8 KiB
HTML
Raw Normal View History

2013-06-15 03:38:03 +04:00
<div id="chartContainer">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="/dist/dimple.v1.js"></script>
<script type="text/javascript">
var svg = dimple.newSvg("#chartContainer", 590, 400);
d3.tsv("/data/example_data.tsv", function (data) {
2013-06-18 13:29:12 +04:00
// Create and position the chart
2013-06-15 03:38:03 +04:00
var myChart = new dimple.chart(svg, data);
myChart.setBounds(60, 50, 510, 310)
2013-06-18 13:29:12 +04:00
// Add a Grouped Mekko Axis. This will show Brands grouped by owners
// sized by unit sales.
2013-06-15 03:38:03 +04:00
var x = myChart.addAxis("x", ["Owner", "Brand"], "Unit Sales");
x.showPercent = true;
2013-06-18 13:29:12 +04:00
// Add the vertical measure to also show unit sales, which is standard
// for a mekko, but not a requirement in dimple.
2013-06-15 03:38:03 +04:00
myChart.addPctAxis("y", "Unit Sales");
2013-06-18 13:29:12 +04:00
// Color by Unit Sales. By defining this without specifying the color
// range in the second parameter, dimple will assign colors as usual
// and adjust saturation based on the Unit Sales value.
2013-06-15 03:38:03 +04:00
var c = myChart.addColorAxis("Unit Sales");
2013-06-18 13:29:12 +04:00
// Override the minimum axis value to a lower number. By default the
// range of values is used with the minimum being 0 saturation and the
// maximum being 100% this causes the bars to be too washed out in this
// particular case.
2013-06-15 03:38:03 +04:00
c.overrideMin = -10000;
2013-06-18 13:29:12 +04:00
// Draw SKU's for the series, by specifying owner second here, it
// ensures dimple will color by owner rather than SKU. This suits the
// grouping to give blocks of color for each owner faded by the SKU
// unit sales value.
2013-06-15 03:38:03 +04:00
myChart.addSeries(["SKU", "Owner"], dimple.plot.bar);
2013-06-18 13:29:12 +04:00
// Add a legend
2013-06-15 03:38:03 +04:00
myChart.addLegend(240, 10, 330, 20, "right");
2013-06-18 13:29:12 +04:00
// Animate the chart by date values
2013-06-15 03:38:03 +04:00
myChart.setStoryboard("Date");
2013-06-18 13:29:12 +04:00
// Draw the chart
2013-06-15 03:38:03 +04:00
myChart.draw();
});
</script>
</div>