price-chart.js 940 B

12345678910111213141516171819202122232425262728293031323334
  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: "bar",
  10. data: {
  11. labels: data.labels,
  12. datasets: data.series.map((s) => ({
  13. label: s.name,
  14. data: s.values,
  15. borderWidth: 1
  16. }))
  17. },
  18. options: {
  19. responsive: true,
  20. maintainAspectRatio: false,
  21. plugins: {
  22. legend: { display: data.series.length > 1 }
  23. },
  24. scales: {
  25. y: { beginAtZero: false }
  26. }
  27. }
  28. });
  29. }
  30. }
  31. const priceChart = new PriceChart();