chart.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>chart</title>
  5. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  6. <!-- <script src='./jsonUpload.js'></script> -->
  7. </head>
  8. <body>
  9. <div id='chart'>
  10. <div>
  11. <input type='file' id='jsonfile'/>
  12. </div>
  13. </div>
  14. <script>
  15. var jsonData;
  16. var inputElement = document.getElementById('jsonfile');
  17. inputElement.addEventListener('change', handleFiles, false);
  18. function handleFiles() {
  19. let selectedFile = document.getElementById('jsonfile').files[0];
  20. let reader = new FileReader();
  21. reader.readAsText(selectedFile);
  22. reader.onload = function () {
  23. console.log("读取结果:",this.result);
  24. // jsonData = this.result;
  25. let json = JSON.parse(this.result);
  26. console.log(json[0]['uuid']);
  27. console.log(json[0]['major']);
  28. jsonData = json
  29. }
  30. }
  31. setTimeout(() => {
  32. let example = []
  33. for (let obj of jsonData) {
  34. if (obj.id == '10001') {
  35. example.push(obj.distance)
  36. }
  37. }
  38. var options = {
  39. series: [{
  40. name: "Desktops",
  41. data: example
  42. }],
  43. chart: {
  44. height: 350,
  45. type: 'line',
  46. zoom: {
  47. enabled: false
  48. }
  49. },
  50. dataLabels: {
  51. enabled: false
  52. },
  53. stroke: {
  54. curve: 'straight'
  55. },
  56. title: {
  57. text: 'Product Trends by Month',
  58. align: 'left'
  59. },
  60. grid: {
  61. row: {
  62. colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
  63. opacity: 0.5
  64. },
  65. },
  66. xaxis: {
  67. // categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],
  68. categories: Array.from({ length: example.length }, (item, index) => index + 1)
  69. }
  70. };
  71. var chart = new ApexCharts(document.querySelector("#chart"), options);
  72. chart.render();
  73. }, 7000);
  74. </script>
  75. </body>
  76. </html>