chart.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class Chart {
  2. constructor(customId) {
  3. this.customId = customId;
  4. //////////////////////////////
  5. // SVG AND GRAPH DIMENSIONS //
  6. //////////////////////////////
  7. this.svgWidth = 450;
  8. this.svgHeight = 425;
  9. this.margin = { top: 15, right: 0, bottom: 15, left: 60 };
  10. this.width = this.svgWidth - this.margin.left - this.margin.right;
  11. this.height = this.svgHeight - this.margin.top - this.margin.bottom;
  12. this.svg = d3.select('#chart-'+this.customId)
  13. .append("div")
  14. // Container class to make it responsive.
  15. .classed("svg-container", true)
  16. .append("svg")
  17. // Responsive SVG needs these 2 attributes and no width and height attr.
  18. // .attr("preserveAspectRatio", "xMidYMid none")
  19. .attr("viewBox", "0 0 " + this.svgWidth + " " + this.svgHeight)
  20. // Class to make it responsive.
  21. .classed("svg-content-responsive", true);
  22. // this.svg.append("text")
  23. // .style("text-anchor", "end")
  24. // .attr("x", this.width)
  25. // .attr("y", this.height - 8)
  26. // .text("X Axis");
  27. //
  28. // this.svg.append("text")
  29. // .attr("transform", "rotate(-90)")
  30. // .attr("y", 6)
  31. // .attr("dy", "1em")
  32. // .style("text-anchor", "end")
  33. // .text("Y Axis");
  34. }
  35. updateAndDraw(chartData) {
  36. console.log("updating data");
  37. this.draw();
  38. }
  39. draw() {
  40. console.log("drawing data");
  41. }
  42. }