• 小程序中使用echarts的相关配置以及折线图案例(简单易懂)


    第一步:引入echarts文件--此文件需要下载:

     下载地址:点击此处进行下载echarts文件

    点击Download ZIP下载压缩包,注意:e-canvas是我从完整的文件中剥离出来的有用的,不会影响项目。

    第二步:把整个文件放入到小程序文件里。

    第三步:在需要的组件中进行正确引入

                   在需要使用echarts的组件的js文件里需要引入

    第四步:案例实现

     4-1:在index.js中

    1. import * as echarts from '../../ec-canvas/echarts';
    2. function initChart(canvas, width, height, dpr) {
    3. const chart = echarts.init(canvas, null, {
    4. width: width,
    5. height: height,
    6. devicePixelRatio: dpr // new
    7. });
    8. canvas.setChart(chart);
    9. var option = {
    10. label: {
    11. normal: {
    12. show: true
    13. }
    14. },
    15. grid: {
    16. containLabel: true,
    17. x: 10, //左
    18. y: 40, //上
    19. x2: 10, //右
    20. y2: 10, //下
    21. borderWidth: 1,
    22. },
    23. legend:{
    24. icon:'square',
    25. data:['室内温度','室外温度'],
    26. right:'10',
    27. itemWidth: 15,//图标宽
    28. itemHeight: 15,//图标高
    29. itemGap: 13,//间距
    30. textStyle:{
    31. color:'#9FA0A3',
    32. fontSize: 12,
    33. },
    34. },
    35. tooltip: {
    36. trigger: 'axis',
    37. backgroundColor: 'rgba(255, 255, 255, 0.8)',
    38. },
    39. xAxis: {
    40. type: 'category',
    41. boundaryGap: false,
    42. data: ['10:00', '10:15', '10:30', '10:45', '11:00'],
    43. // show: false
    44. },
    45. yAxis: {
    46. type: 'value',
    47. min: 0,
    48. max: 60,
    49. interval: 15,
    50. axisLabel: {
    51. formatter: '{value}'
    52. },
    53. splitLine: {
    54. lineStyle: {
    55. type: 'dashed',
    56. color:'#9FA0A3'
    57. }
    58. }
    59. // show: false
    60. },
    61. series: [{
    62. name: '室内温度',
    63. type: 'line',
    64. smooth: true,
    65. data: [15, 16, 15, 17, 15, 16, 17],
    66. itemStyle:{
    67. normal:{
    68. color:'#12A0FF'
    69. }
    70. }
    71. }, {
    72. name: '室外温度',
    73. type: 'line',
    74. smooth: true,
    75. data: [30, 20, 30, 35, 30, 25, 38],
    76. itemStyle:{
    77. normal:{
    78. color:'#D83D6C'
    79. }
    80. }
    81. }, ]
    82. };
    83. chart.setOption(option);
    84. return chart;
    85. }
    86. Page({
    87. data: {
    88. ec: {
    89. onInit: initChart,
    90. },
    91. })

    4.2:在index.wxml中

    1. <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}">ec-canvas>

    最后结果

  • 相关阅读:
    嵌入式分享合集92
    GCC
    json和axion结合
    慢查询SQL如何优化
    Bearly:基于人工智能的AI写作文章生成工具
    MQ 延迟队列
    React技术栈 --》组件生命周期和Vue拓展 ## Day6
    Cholesterol-PEG-FITC,Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素供应
    ubuntu20.04屏幕亮度无法调节的解决方法->安装 brightness-controller-simple 软件
    中级程序员——vue3+js+git面试题
  • 原文地址:https://blog.csdn.net/qq_59599812/article/details/133693699