price-chart.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. class PriceChart {
  2. constructor() {
  3. const el = document.getElementById("priceChartData");
  4. if (!el || typeof Chart === "undefined") {
  5. return;
  6. }
  7. const data = JSON.parse(el.textContent);
  8. new Chart(document.getElementById("priceChart"), {
  9. type: "line",
  10. data: {
  11. labels: data.labels,
  12. datasets: data.series.map((s) => ({
  13. label: s.name,
  14. data: s.values,
  15. fill: "origin",
  16. borderWidth: 2,
  17. pointRadius: 2,
  18. tension: 0.2,
  19. spanGaps: true
  20. }))
  21. },
  22. options: {
  23. responsive: true,
  24. maintainAspectRatio: false,
  25. plugins: {
  26. legend: { display: data.series.length > 1 }
  27. },
  28. scales: {
  29. y: { beginAtZero: false }
  30. }
  31. }
  32. });
  33. }
  34. }
  35. const priceChart = new PriceChart();