chartjs.blade.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <div class="row">
  2. <div class="col-md-6" style="margin-top: 20px">
  3. <canvas id="line" style="width: 505px; display: block; height: 252px;" width="505" height="252"
  4. class="chartjs-render-monitor"></canvas>
  5. <script>
  6. $(function () {
  7. function randomScalingFactor() {
  8. return Math.floor(Math.random() * 100)
  9. }
  10. function getDataLabels(type = 1) {
  11. var labels = {}
  12. $.ajax({
  13. url: '/admin/getDataLabels',
  14. type: 'get',
  15. data: {type: type},
  16. dataType: 'json',
  17. async: false,
  18. success: function (res) {
  19. labels = res;
  20. }
  21. })
  22. return labels;
  23. }
  24. function getData(type) {
  25. var data = {}
  26. $.ajax({
  27. url: '/admin/data',
  28. type: 'get',
  29. data: {type: type},
  30. dataType: 'json',
  31. async: false,
  32. success: function (res) {
  33. data = res;
  34. }
  35. })
  36. return data;
  37. }
  38. window.chartColors = {
  39. red: 'rgb(255, 99, 132)',
  40. orange: 'rgb(255, 159, 64)',
  41. yellow: 'rgb(255, 205, 86)',
  42. green: 'rgb(75, 192, 192)',
  43. blue: 'rgb(54, 162, 235)',
  44. purple: 'rgb(153, 102, 255)',
  45. grey: 'rgb(201, 203, 207)'
  46. };
  47. var da = getData(1);
  48. var config = {
  49. type: 'line',
  50. data: {
  51. labels: da[1]['labels'],
  52. datasets: [{
  53. label: '店铺1',
  54. backgroundColor: window.chartColors.red,
  55. borderColor: window.chartColors.red,
  56. // data: getData(1, 1),
  57. data: da[1]['data'],
  58. fill: false,
  59. }, {
  60. label: '店铺2',
  61. fill: false,
  62. backgroundColor: window.chartColors.blue,
  63. borderColor: window.chartColors.blue,
  64. data: da[2]['data'],
  65. },{
  66. label: '店铺3',
  67. fill: false,
  68. backgroundColor: window.chartColors.orange,
  69. borderColor: window.chartColors.orange,
  70. data: da[3]['data'],
  71. }]
  72. },
  73. options: {
  74. responsive: true,
  75. title: {
  76. display: true,
  77. text: '最近七日店铺用户量'
  78. },
  79. tooltips: {
  80. mode: 'index',
  81. intersect: false,
  82. },
  83. hover: {
  84. mode: 'nearest',
  85. intersect: true
  86. },
  87. scales: {
  88. xAxes: [{
  89. display: true,
  90. scaleLabel: {
  91. display: true,
  92. labelString: '日期'
  93. }
  94. }],
  95. yAxes: [{
  96. display: true,
  97. scaleLabel: {
  98. display: true,
  99. labelString: '用户数量'
  100. }
  101. }]
  102. }
  103. }
  104. };
  105. var ctx = document.getElementById('line').getContext('2d');
  106. new Chart(ctx, config);
  107. });
  108. </script>
  109. </div>
  110. {{-- <div class="col-md-6" style="margin-top: 20px">--}}
  111. {{-- <canvas id="bar-line" width="505" height="252"--}}
  112. {{-- class="chartjs-render-monitor"></canvas>--}}
  113. {{-- <script>--}}
  114. {{-- $(function () {--}}
  115. {{-- function randomScalingFactor() {--}}
  116. {{-- return Math.floor(Math.random() * 100)--}}
  117. {{-- }--}}
  118. {{-- function getDataLabels(type = 1) {--}}
  119. {{-- var labels = {}--}}
  120. {{-- $.ajax({--}}
  121. {{-- url: '/admin/getDataLabels',--}}
  122. {{-- type: 'get',--}}
  123. {{-- data: {type: type},--}}
  124. {{-- dataType: 'json',--}}
  125. {{-- async: false,--}}
  126. {{-- success: function (res) {--}}
  127. {{-- labels = res;--}}
  128. {{-- }--}}
  129. {{-- })--}}
  130. {{-- return labels;--}}
  131. {{-- }--}}
  132. {{-- function getData(type = 1) {--}}
  133. {{-- var data = {}--}}
  134. {{-- $.ajax({--}}
  135. {{-- url: '/admin/data',--}}
  136. {{-- type: 'get',--}}
  137. {{-- data: {type: type},--}}
  138. {{-- dataType: 'json',--}}
  139. {{-- async: false,--}}
  140. {{-- success: function (res) {--}}
  141. {{-- data = res;--}}
  142. {{-- }--}}
  143. {{-- })--}}
  144. {{-- return data;--}}
  145. {{-- }--}}
  146. {{-- window.chartColors = {--}}
  147. {{-- red: 'rgb(255, 99, 132)',--}}
  148. {{-- orange: 'rgb(255, 159, 64)',--}}
  149. {{-- yellow: 'rgb(255, 205, 86)',--}}
  150. {{-- green: 'rgb(75, 192, 192)',--}}
  151. {{-- blue: 'rgb(54, 162, 235)',--}}
  152. {{-- purple: 'rgb(153, 102, 255)',--}}
  153. {{-- grey: 'rgb(201, 203, 207)'--}}
  154. {{-- };--}}
  155. {{-- var chartData = {--}}
  156. {{-- labels: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '五月', '六月', '七月'],--}}
  157. {{-- datasets: [{--}}
  158. {{-- type: 'line',--}}
  159. {{-- label: '每天用户增长情况',--}}
  160. {{-- borderColor: window.chartColors.blue,--}}
  161. {{-- borderWidth: 2,--}}
  162. {{-- fill: false,--}}
  163. {{-- data: getData(1)--}}
  164. {{-- }, {--}}
  165. {{-- type: 'bar',--}}
  166. {{-- label: '模型 2',--}}
  167. {{-- backgroundColor: window.chartColors.red,--}}
  168. {{-- data: getData(2),--}}
  169. {{-- borderColor: 'white',--}}
  170. {{-- borderWidth: 2--}}
  171. {{-- }, {--}}
  172. {{-- type: 'bar',--}}
  173. {{-- label: '模型 3',--}}
  174. {{-- backgroundColor: window.chartColors.green,--}}
  175. {{-- data: getData(3)--}}
  176. {{-- }]--}}
  177. {{-- };--}}
  178. {{-- var ctx = document.getElementById('bar-line').getContext('2d');--}}
  179. {{-- new Chart(ctx, {--}}
  180. {{-- type: 'bar',--}}
  181. {{-- data: chartData,--}}
  182. {{-- options: {--}}
  183. {{-- responsive: true,--}}
  184. {{-- title: {--}}
  185. {{-- display: true,--}}
  186. {{-- text: '用户模型'--}}
  187. {{-- },--}}
  188. {{-- tooltips: {--}}
  189. {{-- mode: 'index',--}}
  190. {{-- intersect: true--}}
  191. {{-- }--}}
  192. {{-- }--}}
  193. {{-- });--}}
  194. {{-- });--}}
  195. {{-- </script>--}}
  196. {{-- </div>--}}
  197. {{-- --}}{{-- ////////////////////////////--}}
  198. {{-- <div class="col-md-6" style="margin-top: 20px">--}}
  199. {{-- <canvas id="scatter" style="width: 505px; display: block; height: 252px;" width="505" height="252"--}}
  200. {{-- class="chartjs-render-monitor"></canvas>--}}
  201. {{-- <script>--}}
  202. {{-- $(function () {--}}
  203. {{-- function randomScalingFactor() {--}}
  204. {{-- return Math.floor(Math.random() * 100)--}}
  205. {{-- }--}}
  206. {{-- window.chartColors = {--}}
  207. {{-- red: 'rgb(255, 99, 132)',--}}
  208. {{-- orange: 'rgb(255, 159, 64)',--}}
  209. {{-- yellow: 'rgb(255, 205, 86)',--}}
  210. {{-- green: 'rgb(75, 192, 192)',--}}
  211. {{-- blue: 'rgb(54, 162, 235)',--}}
  212. {{-- purple: 'rgb(153, 102, 255)',--}}
  213. {{-- grey: 'rgb(201, 203, 207)'--}}
  214. {{-- };--}}
  215. {{-- var ctx = document.getElementById("scatter").getContext('2d');--}}
  216. {{-- var scatterChart = new Chart(ctx, {--}}
  217. {{-- type: 'scatter',--}}
  218. {{-- data: {--}}
  219. {{-- datasets: [{--}}
  220. {{-- label: 'My First dataset',--}}
  221. {{-- borderColor: window.chartColors.red,--}}
  222. {{-- data: [{--}}
  223. {{-- x: randomScalingFactor(),--}}
  224. {{-- y: randomScalingFactor(),--}}
  225. {{-- }, {--}}
  226. {{-- x: randomScalingFactor(),--}}
  227. {{-- y: randomScalingFactor(),--}}
  228. {{-- }, {--}}
  229. {{-- x: randomScalingFactor(),--}}
  230. {{-- y: randomScalingFactor(),--}}
  231. {{-- }, {--}}
  232. {{-- x: randomScalingFactor(),--}}
  233. {{-- y: randomScalingFactor(),--}}
  234. {{-- }, {--}}
  235. {{-- x: randomScalingFactor(),--}}
  236. {{-- y: randomScalingFactor(),--}}
  237. {{-- }, {--}}
  238. {{-- x: randomScalingFactor(),--}}
  239. {{-- y: randomScalingFactor(),--}}
  240. {{-- }, {--}}
  241. {{-- x: randomScalingFactor(),--}}
  242. {{-- y: randomScalingFactor(),--}}
  243. {{-- }]--}}
  244. {{-- }, {--}}
  245. {{-- label: 'My Second dataset',--}}
  246. {{-- borderColor: window.chartColors.blue,--}}
  247. {{-- data: [{--}}
  248. {{-- x: randomScalingFactor(),--}}
  249. {{-- y: randomScalingFactor(),--}}
  250. {{-- }, {--}}
  251. {{-- x: randomScalingFactor(),--}}
  252. {{-- y: randomScalingFactor(),--}}
  253. {{-- }, {--}}
  254. {{-- x: randomScalingFactor(),--}}
  255. {{-- y: randomScalingFactor(),--}}
  256. {{-- }, {--}}
  257. {{-- x: randomScalingFactor(),--}}
  258. {{-- y: randomScalingFactor(),--}}
  259. {{-- }, {--}}
  260. {{-- x: randomScalingFactor(),--}}
  261. {{-- y: randomScalingFactor(),--}}
  262. {{-- }, {--}}
  263. {{-- x: randomScalingFactor(),--}}
  264. {{-- y: randomScalingFactor(),--}}
  265. {{-- }, {--}}
  266. {{-- x: randomScalingFactor(),--}}
  267. {{-- y: randomScalingFactor(),--}}
  268. {{-- }]--}}
  269. {{-- }]--}}
  270. {{-- },--}}
  271. {{-- options: {--}}
  272. {{-- scales: {--}}
  273. {{-- xAxes: [{--}}
  274. {{-- type: 'linear',--}}
  275. {{-- position: 'bottom'--}}
  276. {{-- }]--}}
  277. {{-- }--}}
  278. {{-- }--}}
  279. {{-- });--}}
  280. {{-- });--}}
  281. {{-- </script>--}}
  282. {{-- </div>--}}
  283. {{-- <div class="col-md-6" style="margin-top: 20px">--}}
  284. {{-- <canvas id="doughnut" style="width: 505px; display: block; height: 252px;" width="505" height="252"--}}
  285. {{-- class="chartjs-render-monitor"></canvas>--}}
  286. {{-- <script>--}}
  287. {{-- $(function () {--}}
  288. {{-- function randomScalingFactor() {--}}
  289. {{-- return Math.floor(Math.random() * 100)--}}
  290. {{-- }--}}
  291. {{-- window.chartColors = {--}}
  292. {{-- red: 'rgb(255, 99, 132)',--}}
  293. {{-- orange: 'rgb(255, 159, 64)',--}}
  294. {{-- yellow: 'rgb(255, 205, 86)',--}}
  295. {{-- green: 'rgb(75, 192, 192)',--}}
  296. {{-- blue: 'rgb(54, 162, 235)',--}}
  297. {{-- purple: 'rgb(153, 102, 255)',--}}
  298. {{-- grey: 'rgb(201, 203, 207)'--}}
  299. {{-- };--}}
  300. {{-- var config = {--}}
  301. {{-- type: 'doughnut',--}}
  302. {{-- data: {--}}
  303. {{-- datasets: [{--}}
  304. {{-- data: [--}}
  305. {{-- randomScalingFactor(),--}}
  306. {{-- randomScalingFactor(),--}}
  307. {{-- randomScalingFactor(),--}}
  308. {{-- randomScalingFactor(),--}}
  309. {{-- randomScalingFactor(),--}}
  310. {{-- ],--}}
  311. {{-- backgroundColor: [--}}
  312. {{-- window.chartColors.red,--}}
  313. {{-- window.chartColors.orange,--}}
  314. {{-- window.chartColors.yellow,--}}
  315. {{-- window.chartColors.green,--}}
  316. {{-- window.chartColors.blue,--}}
  317. {{-- ],--}}
  318. {{-- label: 'Dataset 1'--}}
  319. {{-- }],--}}
  320. {{-- labels: [--}}
  321. {{-- 'Red',--}}
  322. {{-- 'Orange',--}}
  323. {{-- 'Yellow',--}}
  324. {{-- 'Green',--}}
  325. {{-- 'Blue'--}}
  326. {{-- ]--}}
  327. {{-- },--}}
  328. {{-- options: {--}}
  329. {{-- responsive: true,--}}
  330. {{-- legend: {--}}
  331. {{-- position: 'top',--}}
  332. {{-- },--}}
  333. {{-- title: {--}}
  334. {{-- display: true,--}}
  335. {{-- text: 'Chart.js Doughnut Chart'--}}
  336. {{-- },--}}
  337. {{-- animation: {--}}
  338. {{-- animateScale: true,--}}
  339. {{-- animateRotate: true--}}
  340. {{-- }--}}
  341. {{-- }--}}
  342. {{-- };--}}
  343. {{-- var ctx = document.getElementById('doughnut').getContext('2d');--}}
  344. {{-- new Chart(ctx, config);--}}
  345. {{-- });--}}
  346. {{-- </script>--}}
  347. {{-- </div>--}}
  348. {{-- <div class="col-md-6" style="margin-top: 20px">--}}
  349. {{-- <canvas id="line-stacked" style="width: 505px; display: block; height: 252px;" width="505" height="252"--}}
  350. {{-- class="chartjs-render-monitor"></canvas>--}}
  351. {{-- <script>--}}
  352. {{-- $(function () {--}}
  353. {{-- function randomScalingFactor() {--}}
  354. {{-- return Math.floor(Math.random() * 100)--}}
  355. {{-- }--}}
  356. {{-- window.chartColors = {--}}
  357. {{-- red: 'rgb(255, 99, 132)',--}}
  358. {{-- orange: 'rgb(255, 159, 64)',--}}
  359. {{-- yellow: 'rgb(255, 205, 86)',--}}
  360. {{-- green: 'rgb(75, 192, 192)',--}}
  361. {{-- blue: 'rgb(54, 162, 235)',--}}
  362. {{-- purple: 'rgb(153, 102, 255)',--}}
  363. {{-- grey: 'rgb(201, 203, 207)'--}}
  364. {{-- };--}}
  365. {{-- var config = {--}}
  366. {{-- type: 'line',--}}
  367. {{-- data: {--}}
  368. {{-- labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],--}}
  369. {{-- datasets: [{--}}
  370. {{-- label: 'My First dataset',--}}
  371. {{-- borderColor: window.chartColors.red,--}}
  372. {{-- backgroundColor: window.chartColors.red,--}}
  373. {{-- data: [--}}
  374. {{-- randomScalingFactor(),--}}
  375. {{-- randomScalingFactor(),--}}
  376. {{-- randomScalingFactor(),--}}
  377. {{-- randomScalingFactor(),--}}
  378. {{-- randomScalingFactor(),--}}
  379. {{-- randomScalingFactor(),--}}
  380. {{-- randomScalingFactor()--}}
  381. {{-- ],--}}
  382. {{-- }, {--}}
  383. {{-- label: 'My Second dataset',--}}
  384. {{-- borderColor: window.chartColors.blue,--}}
  385. {{-- backgroundColor: window.chartColors.blue,--}}
  386. {{-- data: [--}}
  387. {{-- randomScalingFactor(),--}}
  388. {{-- randomScalingFactor(),--}}
  389. {{-- randomScalingFactor(),--}}
  390. {{-- randomScalingFactor(),--}}
  391. {{-- randomScalingFactor(),--}}
  392. {{-- randomScalingFactor(),--}}
  393. {{-- randomScalingFactor()--}}
  394. {{-- ],--}}
  395. {{-- }, {--}}
  396. {{-- label: 'My Third dataset',--}}
  397. {{-- borderColor: window.chartColors.green,--}}
  398. {{-- backgroundColor: window.chartColors.green,--}}
  399. {{-- data: [--}}
  400. {{-- randomScalingFactor(),--}}
  401. {{-- randomScalingFactor(),--}}
  402. {{-- randomScalingFactor(),--}}
  403. {{-- randomScalingFactor(),--}}
  404. {{-- randomScalingFactor(),--}}
  405. {{-- randomScalingFactor(),--}}
  406. {{-- randomScalingFactor()--}}
  407. {{-- ],--}}
  408. {{-- }, {--}}
  409. {{-- label: 'My Third dataset',--}}
  410. {{-- borderColor: window.chartColors.yellow,--}}
  411. {{-- backgroundColor: window.chartColors.yellow,--}}
  412. {{-- data: [--}}
  413. {{-- randomScalingFactor(),--}}
  414. {{-- randomScalingFactor(),--}}
  415. {{-- randomScalingFactor(),--}}
  416. {{-- randomScalingFactor(),--}}
  417. {{-- randomScalingFactor(),--}}
  418. {{-- randomScalingFactor(),--}}
  419. {{-- randomScalingFactor()--}}
  420. {{-- ],--}}
  421. {{-- }]--}}
  422. {{-- },--}}
  423. {{-- options: {--}}
  424. {{-- responsive: true,--}}
  425. {{-- title: {--}}
  426. {{-- display: true,--}}
  427. {{-- text: 'Chart.js Line Chart - Stacked Area'--}}
  428. {{-- },--}}
  429. {{-- tooltips: {--}}
  430. {{-- mode: 'index',--}}
  431. {{-- },--}}
  432. {{-- hover: {--}}
  433. {{-- mode: 'index'--}}
  434. {{-- },--}}
  435. {{-- scales: {--}}
  436. {{-- xAxes: [{--}}
  437. {{-- scaleLabel: {--}}
  438. {{-- display: true,--}}
  439. {{-- labelString: 'Month'--}}
  440. {{-- }--}}
  441. {{-- }],--}}
  442. {{-- yAxes: [{--}}
  443. {{-- stacked: true,--}}
  444. {{-- scaleLabel: {--}}
  445. {{-- display: true,--}}
  446. {{-- labelString: 'Value'--}}
  447. {{-- }--}}
  448. {{-- }]--}}
  449. {{-- }--}}
  450. {{-- }--}}
  451. {{-- };--}}
  452. {{-- var ctx = document.getElementById('line-stacked').getContext('2d');--}}
  453. {{-- new Chart(ctx, config);--}}
  454. {{-- });--}}
  455. {{-- </script>--}}
  456. {{-- </div>--}}
  457. </div>