2013-09-12 13:56:11 +04:00
|
|
|
<!----------------------------------------------------------------->
|
|
|
|
<!-- AUTOMATICALLY GENERATED CODE - PLEASE EDIT TEMPLATE INSTEAD -->
|
|
|
|
<!----------------------------------------------------------------->
|
2015-07-10 19:41:31 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<html>
|
2013-06-21 14:27:29 +04:00
|
|
|
<div id="chartContainer">
|
2014-07-24 13:58:51 +04:00
|
|
|
<script src="/lib/d3.v3.4.8.js"></script>
|
2016-03-23 18:19:48 +03:00
|
|
|
<script src="/dist/dimple.v2.2.0.js"></script>
|
2013-06-21 14:27:29 +04:00
|
|
|
<script type="text/javascript">
|
|
|
|
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
|
|
|
d3.tsv("/data/example_data.tsv", function (data) {
|
|
|
|
|
|
|
|
// Get a unique list of dates
|
|
|
|
var months = dimple.getUniqueValues(data, "Date");
|
|
|
|
|
|
|
|
// Set the bounds for the charts
|
2013-06-24 13:01:52 +04:00
|
|
|
var row = 0,
|
|
|
|
col = 0,
|
2013-06-21 15:41:31 +04:00
|
|
|
top = 25,
|
2013-06-21 14:34:13 +04:00
|
|
|
left = 60,
|
2013-06-21 14:27:29 +04:00
|
|
|
inMarg = 15,
|
|
|
|
width = 115,
|
2013-06-24 13:04:55 +04:00
|
|
|
height = 90,
|
|
|
|
totalWidth = parseFloat(svg.attr("width"));
|
2013-06-21 14:27:29 +04:00
|
|
|
|
|
|
|
// Pick the latest 12 dates
|
2013-06-24 13:01:52 +04:00
|
|
|
months = months.slice(months.length - 12);
|
2013-06-21 14:27:29 +04:00
|
|
|
|
|
|
|
// Draw a chart for each of the 12 dates
|
|
|
|
months.forEach(function (month) {
|
|
|
|
|
|
|
|
// Wrap to the row above
|
2013-06-24 13:04:55 +04:00
|
|
|
if (left + ((col + 1) * (width + inMarg)) > totalWidth) {
|
2013-06-24 13:01:52 +04:00
|
|
|
row += 1;
|
|
|
|
col = 0;
|
2013-06-21 14:27:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter for the month in the iteration
|
|
|
|
var chartData = dimple.filterData(data, "Date", month);
|
|
|
|
|
|
|
|
// Use d3 to draw a text label for the month
|
|
|
|
svg
|
|
|
|
.append("text")
|
|
|
|
.attr("x", left + (col * (width + inMarg)) + (width / 2))
|
|
|
|
.attr("y", top + (row * (height + inMarg)) + (height / 2) + 12)
|
|
|
|
.style("font-family", "sans-serif")
|
|
|
|
.style("text-anchor", "middle")
|
|
|
|
.style("font-size", "28px")
|
|
|
|
.style("opacity", 0.2)
|
|
|
|
.text(chartData[0].Month.substring(0, 3));
|
|
|
|
|
|
|
|
// Create a chart at the correct point in the trellis
|
|
|
|
var myChart = new dimple.chart(svg, chartData);
|
|
|
|
myChart.setBounds(
|
|
|
|
left + (col * (width + inMarg)),
|
|
|
|
top + (row * (height + inMarg)),
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
|
|
|
|
// Add x and fix ordering so that all charts are the same
|
|
|
|
var x = myChart.addCategoryAxis("x", "Owner");
|
2013-06-21 14:34:13 +04:00
|
|
|
x.addOrderRule(["Black Mesa", "Aperture", "Tyrell Corp",
|
|
|
|
"Rekall", "MomCorp", "LexCorp", "Stark Ind", "Wayne Ent"]);
|
2013-06-21 14:27:29 +04:00
|
|
|
|
|
|
|
// Add y and fix scale so that all charts are the same
|
|
|
|
var y = myChart.addMeasureAxis("y", "Sales Value");
|
|
|
|
y.overrideMax = 16000000;
|
|
|
|
|
|
|
|
// Draw the bars. Passing null here would draw all bars with
|
|
|
|
// the same color. Passing owner second colors by owner, which
|
|
|
|
// is normally bad practice in a bar chart but works in a trellis.
|
|
|
|
// Month is only passed here so that it shows in the tooltip.
|
|
|
|
myChart.addSeries(["Month", "Owner"], dimple.plot.bar);
|
|
|
|
|
|
|
|
// Draw the chart
|
|
|
|
myChart.draw();
|
|
|
|
|
|
|
|
// Once drawn we can access the shapes
|
|
|
|
// If this is not in the first column remove the y text
|
|
|
|
if (col > 0) {
|
|
|
|
y.shapes.selectAll("text").remove();
|
|
|
|
}
|
|
|
|
// If this is not in the last row remove the x text
|
|
|
|
if (row < 2) {
|
|
|
|
x.shapes.selectAll("text").remove();
|
|
|
|
}
|
|
|
|
// Remove the axis labels
|
|
|
|
y.titleShape.remove();
|
|
|
|
x.titleShape.remove();
|
|
|
|
|
|
|
|
// Move to the next column
|
2013-06-24 13:01:52 +04:00
|
|
|
col += 1;
|
2013-06-21 14:27:29 +04:00
|
|
|
|
|
|
|
}, this);
|
|
|
|
});
|
|
|
|
</script>
|
2015-07-10 19:41:31 +03:00
|
|
|
</div>
|
|
|
|
</html>
|