price-chart.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. borderWidth: 2,
  16. pointRadius: 2,
  17. tension: 0.2,
  18. spanGaps: true
  19. }))
  20. },
  21. options: {
  22. responsive: true,
  23. maintainAspectRatio: false,
  24. plugins: {
  25. legend: { display: data.series.length > 1 }
  26. },
  27. scales: {
  28. y: { beginAtZero: false }
  29. }
  30. }
  31. });
  32. }
  33. }
  34. const priceChart = new PriceChart();