You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 satır
2.4KB

  1. import Chart from 'chart';
  2. export class CaracStatistics {
  3. static initBtnShowTotalOrderProduct(){
  4. $('.lc-show-products-sales-statistic').unbind('click').on('click', function (){
  5. var $btn = $(this);
  6. var url = $(this).data('url');
  7. $('#modal-products-sales-statistic').remove();
  8. $.ajax({
  9. url: url,
  10. method: "POST",
  11. dataType: "json",
  12. success: function (response) {
  13. $('body').append(response.data);
  14. $('#modal-products-sales-statistic').modal('show');
  15. CaracStatistics.initModalProductsSalesStatistic(response.statistics);
  16. }
  17. });
  18. });
  19. }
  20. static initModalProductsSalesStatistic(statistics) {
  21. var chart = null;
  22. $('.btn-products-sales-statistic').off('click');
  23. $('.btn-products-sales-statistic').on('click', function () {
  24. $('.table-products-sales-statistic').hide();
  25. $('.btn-products-sales-statistic').addClass('btn-secondary').removeClass('btn-primary');
  26. $(this).removeClass('btn-secondary').addClass('btn-primary');
  27. $('#table-products-sales-statistic-'+$(this).data('property-name')).show()
  28. if (chart) chart.destroy();
  29. $(this).removeClass('btn-secondary');
  30. chart = CaracStatistics.drawProductsSalesStatistic(statistics,$(this).data('property-name'))
  31. });
  32. $('.btn-products-sales-statistic').first().click();
  33. }
  34. static drawProductsSalesStatistic(statictics, propertyName) {
  35. var options = {
  36. bezierCurve : false,
  37. tooltips: {
  38. callbacks: {
  39. label: (item) => item.yLabel ,
  40. },
  41. },
  42. };
  43. chart = new Chart(document.getElementById("chart"), {
  44. "type": "line",
  45. "data": {
  46. "labels": Object.values(statictics.label),
  47. "datasets": [{
  48. "label": "Vente de produits / semaine",
  49. "data": Object.values(statictics.data[propertyName].data),
  50. "fill": false,
  51. "borderColor": "rgb(75, 192, 192)",
  52. "lineTension": 0.1
  53. }]
  54. },
  55. "options": options
  56. });
  57. return chart;
  58. }
  59. }