Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

statistic.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }