天气曲线echarts

 

1. 用多x轴实现日期,图标,控制定位固定显示高度

2.背景遮罩抛开echarts另外用div

3.设置grid的offset控制温度折线的范围

html

  <div class="right_bottom">
    <basicEcharts
      style="height: 400px; width: 1200px"
      :option="chartOptions"
      :key="chartUpdate"
    />
    <div
      class="test"
      v-for="(item, index) in gridArr"
      :key="index"
      :style="{ left: item.left }"
    ></div>
  </div>

 遮罩层left值数组

let gridArr = [
    {
        "left": "26px"
    },
    {
        "left": "104px"
    },
    {
        "left": "182px"
    },
    {
        "left": "260px"
    },
    {
        "left": "338px"
    },
    {
        "left": "416px"
    },
    {
        "left": "494px"
    },
    {
        "left": "572px"
    },
    {
        "left": "650px"
    },
    {
        "left": "728px"
    },
    {
        "left": "806px"
    },
    {
        "left": "884px"
    },
    {
        "left": "962px"
    },
    {
        "left": "1040px"
    },
    {
        "left": "1118px"
    }
]

css

.test {
  height: 350px;
  width: 70px;
  background-color: rgba(69, 89, 114, 0.5);
  position: absolute;
  top: 50px;
  left: 38px;
}

echarts的options

{
    "color": [
        "#fff",
        "#fff"
    ],
    "title": {
        "text": "未来15日天气",
        "textStyle": {
            "color": "#fff"
        }
    },
    "grid": {
        "left": "5%",
        "right": "4%",
        "bottom": 0,
        "top": 240
    },
    "tooltip": {
        "trigger": "axis"
    },
    "legend": {
        "show": false
    },
    "xAxis": [
        {
            "type": "category",
            "boundaryGap": false,
            "position": "top",
            "offset": 160,
            "zlevel": 100,
            "axisLine": {
                "show": false
            },
            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,
                "color": "rgba(255, 255, 255, 1)",
                "formatter": "{a|{value}}",
                "rich": {
                    "a": {
                        "fontSize": 14
                    }
                }
            },
            "nameTextStyle": {
                "fontWeight": "bold",
                "fontSize": 19
            },
            "data": [
                "周四",
                "周五",
                "周六",
                "周日",
                "周一",
                "周二",
                "周三",
                "周四",
                "周五",
                "周六",
                "周日",
                "周一",
                "周二",
                "周三",
                "周四"
            ]
        },
        {
            "type": "category",
            "boundaryGap": false,
            "position": "top",
            "offset": 120,
            "zlevel": 100,
            "axisLine": {
                "show": false
            },
            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,
                "color": "rgba(255, 255, 255, 1)",
                "formatter": "{a|{value}}",
                "rich": {
                    "a": {
                        "fontSize": 18
                    }
                }
            },
            "nameTextStyle": {},
            "data": [
                "08/01",
                "08/02",
                "08/03",
                "08/04",
                "08/05",
                "08/06",
                "08/07",
                "08/08",
                "08/09",
                "08/10",
                "08/11",
                "08/12",
                "08/13",
                "08/14",
                "08/15"
            ]
        },
        {
            "type": "category",
            "boundaryGap": false,
            "position": "top",
            "offset": 40,
            "zlevel": 100,
            "axisLine": {
                "show": false
            },
            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "color": "rgba(255, 255, 255, 1)",
                "interval": 0,
                "rich": [
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    },
                    {
                        "backgroundColor": {
                            "image": "/images/weather/W1.png"
                        },
                        "height": 40,
                        "width": 40
                    }
                ]
            },
            "nameTextStyle": {
                "fontWeight": "bold",
                "fontSize": 19
            },
            "data": [
                "小雨",
                "小雨",
                "小雨",
                "多云",
                "中雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨",
                "小雨"
            ]
        }
    ],
    "yAxis": {
        "type": "value",
        "show": false,
        "axisLabel": {
            "formatter": "{value} °C",
            "color": "white"
        }
    },
    "series": [
        {
            "name": "最高气温",
            "type": "line",
            "data": [
                "31",
                "31",
                "32",
                "32",
                "30",
                "29",
                "27",
                "28",
                "29",
                "32",
                "32",
                "30",
                "32",
                "33",
                "33"
            ],
            "symbol": "emptyCircle",
            "symbolSize": 10,
            "showSymbol": true,
            "smooth": true,
            "itemStyle": {
                "normal": {}
            },
            "label": {
                "show": true,
                "position": "top",
                "formatter": "{c} °C"
            },
            "lineStyle": {
                "width": 1
            },
            "areaStyle": {
                "opacity": 1,
                "color": "transparent"
            }
        },
        {
            "name": "最低气温",
            "type": "line",
            "data": [
                "23",
                "22",
                "24",
                "23",
                "22",
                "22",
                "19",
                "20",
                "20",
                "21",
                "21",
                "21",
                "19",
                "21",
                "21"
            ],
            "symbol": "emptyCircle",
            "symbolSize": 10,
            "showSymbol": true,
            "smooth": true,
            "itemStyle": {
                "normal": {}
            },
            "label": {
                "show": true,
                "position": "bottom",
                "formatter": "{c} °C"
            },
            "lineStyle": {
                "width": 1
            },
            "areaStyle": {
                "opacity": 1,
                "color": "transparent"
            }
        }
    ]
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ECharts 是一个基于 JavaScript 的开源可视化库,可以用于制作各种交互式的图表,包括曲线图。 要制作曲线图,可以使用 ECharts 的折线图(line)系列。在该系列中,可以通过添加数据来绘制曲线。同时,ECharts 还支持对曲线进行样式、标记等的设置,以及对数据进行筛选和排序等操作。 以下是一个简单的 ECharts 曲线图的示例代码: ```javascript // 初始化 ECharts 实例 var myChart = echarts.init(document.getElementById('myChart')); // 配置项 var option = { // 设置 x 轴和 y 轴的数据 xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, // 设置曲线的数据 series: [{ data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }] }; // 使用刚指定的配置项和数据显示图表 myChart.setOption(option); ``` 在该示例中,我们设置了 x 轴和 y 轴的数据,并在折线图系列中添加了曲线的数据。最后,使用 `setOption` 方法将配置项和数据应用到图表中,即可显示出曲线图。 ### 回答2: ECharts是一种开源的JavaScript可视化库,它提供了丰富多样的图表展示方式。其中,ECharts曲线是一种常用的图表形式,用于展示数据随时间变化的趋势。 ECharts曲线具有灵活性和可扩展性。它可以显示多条曲线,每条曲线代表一个指标或变量的变化情况。在ECharts中,可以对曲线进行自定义,包括曲线的样式、颜色、标记点等,从而使数据更加直观和易于理解。此外,ECharts还支持通过绘制不同类型的曲线(如折线图、面积图、曲面图等)来展示数据,以满足不同的需求。 对于数据分析和可视化需求而言,ECharts曲线提供了一种直观的方式来展示数据的变化趋势。通过观察曲线的形状和趋势,我们可以了解数据的走势以及数据之间的关系。例如,在股市分析中,使用ECharts曲线可以展示股票价格的变化,供投资者进行决策。在气象预报中,可以使用ECharts曲线展示温度、湿度等指标的变化情况,方便人们了解天气变化。在销售数据分析中,ECharts曲线可以展示销售额、利润等指标的变化趋势,帮助企业制定营销策略。 总的来说,ECharts曲线是一种强大的数据可视化工具,可以帮助我们更好地理解数据的趋势和关系,从而作出更准确的决策。无论是在研究、商业分析还是其他领域,ECharts曲线都是一种非常有用的视觉展示方式。 ### 回答3: ECharts 是一款用于可视化图表展示的前端开源库,而曲线ECharts 中常用的一种图表类型。 ECharts 提供了丰富的配置项和交互功能,使得曲线图的创建和定制变得简单快捷。通过设置数据源和配置项,我们可以创建出各种各样的曲线图,例如折线图、面积图、曲面图等。 在创建曲线图时,我们需要先确定好数据源。通常情况下,曲线图的数据源可以是一个数组,数组中的每个元素代表一个数据点,包括横坐标和纵坐标两个值。我们可以根据需求自行设置数据点的值,以展现不同的曲线形状和趋势。 在配置项方面,ECharts 提供了丰富的选项供我们修改。我们可以设置横轴和纵轴的刻度、标签样式、线条样式、图例配置等等。除此之外,ECharts 还支持多系列的曲线图,即在一个图表中展示多条曲线,使得数据的对比和分析更加清晰明了。 除了基本的展示功能外,ECharts 还提供了丰富的交互功能,例如数据点的点击、拖拽和缩放等。这些交互功能可以帮助用户更加深入地探索数据,并进行更加精细的分析和比较。 总之,ECharts曲线图功能使得我们能够以直观的方式展示数据的趋势和关联性。通过简单的配置和交互功能,我们可以创建出漂亮而实用的曲线图,帮助用户深入了解数据背后的意义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值