Guest User

Untitled

a guest
Jun 28th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.28 KB | None | 0 0
  1. <html>
  2. <div id="chartContainer">
  3.   <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
  4.   <script src="http://dimplejs.org/dist/dimple.v2.2.0.min.js"></script>
  5.   <script type="text/javascript">
  6.     var svg = dimple.newSvg("#chartContainer", 1180, 800);
  7.     d3.csv("test_items.csv", function (data) {
  8.  
  9.       // Get a unique list of dates.
  10.       var scraper_names = dimple.getUniqueValues(data, "scraper_name");
  11.  
  12.       // Set the bounds for the charts.
  13.       var totalWidth = parseFloat(svg.attr("width")),
  14.           row = 0,
  15.           col = 0,
  16.           top = 30,
  17.           ouMarg = 30,
  18.           inMarg = 50,
  19.           width = (totalWidth - 2*ouMarg - 2*inMarg)/3,
  20.           height = 190;
  21.  
  22.       // Draw a chart for each of the scrapers.
  23.       scraper_names.forEach(function (scraper_name) {
  24.  
  25.           // Wrap to the row above
  26.           if (2*ouMarg + ((col) * (width + inMarg)) > totalWidth) {
  27.             row += 1;
  28.             col = 0;
  29.           }
  30.  
  31.           // Filter for the scraper_name in the iteration.
  32.           var chartData = dimple.filterData(data, "scraper_name", scraper_name);
  33.  
  34.           // Use d3 to draw a text label for the scraper_name.
  35.           svg
  36.             .append("text")
  37.                 .attr("x", ouMarg + (col * (width + inMarg)) + (width / 2))
  38.                 .attr("y", top + (row * (height + inMarg)) + (height / 2) + 12)
  39.                 .style("font-family", "sans-serif")
  40.                 .style("text-anchor", "middle")
  41.                 .style("font-size", "28px")
  42.                 .style("opacity", 0.3)
  43.                 .text(chartData[0].scraper_name);
  44.  
  45.           // Create a chart at the correct point in the trellis.
  46.           var myChart = new dimple.chart(svg, chartData);
  47.           myChart.setBounds(
  48.             ouMarg + (col * (width + inMarg)),
  49.             top + (row * (height + inMarg)),
  50.             width,
  51.             height);
  52.  
  53.           // Add x and fix ordering so that all charts are the same
  54.           var x = myChart.addTimeAxis("x", "date", "%Y-%m-%d", "%m/%d");
  55.           x.timePeriod = d3.time.days;
  56.           x.timeInterval = 2;
  57.           x.showGridlines = null;
  58.           //x.addOrderRule(["Black Mesa", "Aperture", "Tyrell Corp",
  59.           //  "Rekall", "MomCorp", "LexCorp", "Stark Ind", "Wayne Ent"]);
  60.  
  61.           // Add y and fix scale so that all charts are the same
  62.           var y = myChart.addMeasureAxis("y", "items");
  63.           y.showGridlines = null;
  64.           //y.overrideMax = 16000000;
  65.  
  66.           // Draw the bars.  Passing null here would draw all bars with
  67.           // the same color.  Passing date second colors by date, which
  68.           // is normally bad practice in a bar chart but works in a trellis.
  69.           // scraper_name is only passed here so that it shows in the tooltip.
  70.           myChart.addSeries("scraper_name", dimple.plot.bubble);
  71.  
  72.           // Add a line to connect the points.
  73.           var s = myChart.addSeries("scraper_name", dimple.plot.line);
  74.           //s.lineMarkers = true;
  75.  
  76.           // Draw the chart
  77.           myChart.draw();
  78.  
  79.           // Remove the axis labels
  80.           y.titleShape.remove();
  81.           x.titleShape.remove();
  82.  
  83.           // Move to the next column
  84.           col += 1;
  85.  
  86.       }, this);
  87.     });
  88.   </script>
  89. </div>
  90. </html>
Add Comment
Please, Sign In to add comment