demo.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
  6. <style>
  7. body {
  8. margin: 0;
  9. }
  10. #plot {
  11. width: 100vw;
  12. height: 100vh;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="plot"></div>
  18. <script>
  19. //反转字符串
  20. // let str = "1234567";
  21. // 方法1:
  22. // str.split("").reverse().join("");
  23. // 方法2:
  24. // const brr = str.split("").reduce((rev, ch) => {
  25. // return ch + rev;
  26. // }, "");
  27. // console.log(brr, "brr");
  28. // //递归
  29. // function recursionFn(n) {
  30. // if (n === 0) return 0; // 递归终止条件
  31. // return n + recursionFn(n - 1);
  32. // }
  33. // console.log(recursionFn(10));
  34. //js map 方法
  35. // if (!Array.prototype.myMap) {
  36. // Array.prototype.myMap = function (callback, thisArg) {
  37. // if (typeof callback !== "function") {
  38. // console.error("callback 必须是一个函数");
  39. // }
  40. // console.log(this, thisArg);
  41. // const arr = this;
  42. // const result = new Array(arr.length);
  43. // for (let i = 0; i < arr.length; i++) {
  44. // if (!(i in arr)) continue;
  45. // result[i] = callback.call(thisArg, arr[i], i, arr);
  46. // }
  47. // return result;
  48. // };
  49. // }
  50. // const numArray = [1, 4, null, 7, 3];
  51. // const numResult = numArray.myMap(
  52. // function (val, index) {
  53. // console.log("myMap 回调函数", this.obj, val, index);
  54. // return this.obj + val;
  55. // },
  56. // { obj: "这个是this" }
  57. // );
  58. // console.log(numResult, "numResult");
  59. // const xLabels = ["A", "B", "C"];
  60. // const yLabels = ["Monday", "Tuesday", "Wednesday"];
  61. // const dataMatrix = [
  62. // [5, 8, 6],
  63. // [4, 2, 9],
  64. // [7, 3, 5],
  65. // ];
  66. // // 构造立方体柱子
  67. // const traces = [];
  68. // const barWidth = 0.8;
  69. // for (let xi = 0; xi < xLabels.length; xi++) {
  70. // for (let yi = 0; yi < yLabels.length; yi++) {
  71. // const height = dataMatrix[yi][xi];
  72. // const x = xi;
  73. // const y = yi;
  74. // const z = 0;
  75. // // 立方体8个顶点
  76. // const vertices = [
  77. // [x, y, z],
  78. // [x + barWidth, y, z],
  79. // [x + barWidth, y + barWidth, z],
  80. // [x, y + barWidth, z],
  81. // [x, y, z + height],
  82. // [x + barWidth, y, z + height],
  83. // [x + barWidth, y + barWidth, z + height],
  84. // [x, y + barWidth, z + height],
  85. // ];
  86. // // 每个立方体的面(两个三角形组成一个面)
  87. // const faces = [
  88. // [0, 1, 2],
  89. // [0, 2, 3], // bottom
  90. // [4, 5, 6],
  91. // [4, 6, 7], // top
  92. // [0, 1, 5],
  93. // [0, 5, 4], // front
  94. // [1, 2, 6],
  95. // [1, 6, 5], // right
  96. // [2, 3, 7],
  97. // [2, 7, 6], // back
  98. // [3, 0, 4],
  99. // [3, 4, 7], // left
  100. // ];
  101. // // 拆解为 Plotly mesh3d 的输入格式
  102. // const xVals = vertices.map((v) => v[0]);
  103. // const yVals = vertices.map((v) => v[1]);
  104. // const zVals = vertices.map((v) => v[2]);
  105. // const i = faces.map((f) => f[0]);
  106. // const j = faces.map((f) => f[1]);
  107. // const k = faces.map((f) => f[2]);
  108. // traces.push({
  109. // type: "mesh3d",
  110. // x: xVals,
  111. // y: yVals,
  112. // z: zVals,
  113. // i,
  114. // j,
  115. // k,
  116. // opacity: 1,
  117. // color: `rgb(${50 + xi * 50}, ${100 + yi * 50}, 200)`,
  118. // flatshading: true,
  119. // showscale: false,
  120. // });
  121. // }
  122. // }
  123. // const layout = {
  124. // scene: {
  125. // xaxis: {
  126. // title: "X",
  127. // tickvals: [0.4, 1.4, 2.4],
  128. // ticktext: xLabels,
  129. // },
  130. // yaxis: {
  131. // title: "Y",
  132. // tickvals: [0.4, 1.4, 2.4],
  133. // ticktext: yLabels,
  134. // },
  135. // zaxis: { title: "Z" },
  136. // aspectratio: {
  137. // x: 2.2,
  138. // y: 1.7,
  139. // z: 1,
  140. // },
  141. // bgcolor: "#e5ecf6",
  142. // aspectmode: "manual",
  143. // gridcolor: "#fff",
  144. // camera: {
  145. // up: {
  146. // x: 0.200292643688136,
  147. // y: 0.2488259353493132,
  148. // z: 0.947612004346693,
  149. // },
  150. // center: {
  151. // x: -0.052807476121180814,
  152. // y: 0.02451796399554085,
  153. // z: -0.022911006648570736,
  154. // },
  155. // eye: {
  156. // x: -2.126379643342493,
  157. // y: -2.551422475965373,
  158. // z: 1.0917667684145647,
  159. // },
  160. // projection: {
  161. // type: "orthographic",
  162. // },
  163. // },
  164. // staticPlot: false,
  165. // showlegend: true,
  166. // legend: {
  167. // itemsizing: "constant", // ✅ 统一图例 marker 大小
  168. // font: {
  169. // size: 12,
  170. // },
  171. // marker: {
  172. // size: 10,
  173. // },
  174. // },
  175. // },
  176. // margin: { t: 50, b: 50, l: 50, r: 50 },
  177. // };
  178. // Plotly.newPlot("plot", traces, layout);
  179. </script>
  180. </body>
  181. </html>