• vue3+ts做echarts做一个简单的折线渐变图


    vue3做echarts做一个简单的折线渐变图

    效果

    在这里插入图片描述
    代码:

    template>
    <div>
          <div class="date-change">
            <el-date-picker size="small" v-model="dateValue" value-format="YYYY-MM-DD" type="daterange" range-separator="" start-placeholder="开始日期" end-placeholder="截至日期" format="YYYY-MM-DD" @change="changeDate($event)" />
          div>
          <v-chart :option="lineData" :theme="theme" :autoresize="autoResize" />
        div>
    <template>
    <script lang="ts">
    import { defineComponent, reactive, toRefs } from "vue";
    import { CanvasRenderer } from "echarts/renderers";
    import { BarChart, LineChart, PieChart, MapChart, RadarChart, ScatterChart, EffectScatterChart, LinesChart } from "echarts/charts";
    import { GridComponent, PolarComponent, GeoComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, DatasetComponent, ToolboxComponent, DataZoomComponent } from "echarts/components";
    import VChart, { THEME_KEY } from "vue-echarts";
    use([BarChart, LineChart, PieChart, MapChart, RadarChart, ScatterChart, EffectScatterChart, LinesChart, GridComponent, PolarComponent, GeoComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, DatasetComponent, CanvasRenderer, ToolboxComponent, DataZoomComponent]);
    export default defineComponent({
      components: {
        VChart
      },
      provide: {
        [THEME_KEY]: "westeros"
      },
      setup() {
        const data = reactive({
        lineData: {
            tooltip: {
              // show:true,
              // 悬浮显示格式
              formatter: "{a} 
    {b} : {c}%
    {a1}
    {b1} : {c1}%"
    , trigger: "axis" // 触发类型,在饼形图中为item }, color: ["#377AF4", "#F5AE3D"], //标题颜色 legend: { textStyle: { // 设置图例字体 color: "#000000", fontSize: "12" }, //线条样式 圆角 icon: "circle", left: "center", data: ["计划负载", "实际负载"] }, xAxis: { name: "日期", boundaryGap: false, type: "category", data: [] //设置X轴 超出自动隐藏日期 // "axisLabel":{ // interval: 1.5 // } }, yAxis: { type: "value", max: 100, axisLabel: { //Y轴百分比 formatter: function (val: number) { return val + "%"; } } }, series: [ { name: "计划负载", type: "line", smooth: true, label: { normal: { //开启折点显示数据 // show: true, position: "top", textStyle: { color: "#377AF4", width: 2 } } }, areaStyle: { color: { //线性渐变 type: "linear", x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: "rgba(185, 210, 255, 0.43)" // 0% 处的颜色 }, { offset: 1, color: "rgba(237, 243, 255, 0)" // 100% 处的颜色 } ], global: false // 缺省为 false } }, data: [] }, { type: "line", name: "实际负载", smooth: true, label: { normal: { //开启折点显示数据 // show: true, position: "top", textStyle: { //折线颜色 color: "#377AF4", width: 2 } } }, areaStyle: { color: { //线性渐变 x: 0, y: 0, x2: 0, y2: 1, type: "linear", colorStops: [ { offset: 0, color: "rgba(255, 231, 193, 1)" // 0% 处的颜色 }, { offset: 1, color: "rgba(255, 246, 236, 0)" // 100% 处的颜色 } ], global: false // 缺省为 false } }, data: [] } ] as any } as any, theme: "" as any, autoResize: true as boolean }); return { ...toRefs(data) }; } });
    script> <style lang="less" scoped> .echarts { position: absolute; width: 100%; height: 100%; } .date-change { position: absolute; right: 10px; z-index: 1; } style>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
  • 相关阅读:
    Cadence OrCAD Capture 关键网络逐个检查方法
    搜狗微信APP逆向(二)so层
    【Java毕设】基于SpringBoot实现新冠疫情统计系统(Idea+Navicat)
    SwipeRefreshLayout和TextView滑动冲突的暴力解决方法
    数学建模 | 灰色预测原理及python实现
    幸运彩票 分数 15作者 陈越单位 浙江大学
    由于执行触发器导致登录失败,错误号为17892的解决方案
    通通锁接口调用<Response [400]>报错及python示例代码
    如何创作属于自己的NFT?
    cumsum() R函数:用于产生随机变量的累积和
  • 原文地址:https://blog.csdn.net/weixin_45049852/article/details/128186461