根据提供的信息,我们可以深入探讨如何在 ECharts 中实现双折线图,并且让其中一条折线显示为虚线。此示例代码虽然未完全展示,但已经足够让我们理解其核心概念和技术要点。 ### 一、ECharts 双折线图简介 #### 1.1 双折线图的概念 双折线图是一种图表形式,它在同一图表中同时展示两条折线,通常用于比较两个数据系列随时间的变化趋势或关系。这种图表非常适合展现数据随时间变化的情况,例如销售额对比、股票价格变动等场景。 #### 1.2 折线图的实现方法 在 ECharts 中,创建双折线图需要定义至少两个 `series` 对象,每个对象都配置了不同类型的数据。此外,还需要设置 `xAxis` 和 `yAxis` 来确定图表的坐标轴。 ### 二、ECharts 双折线图的具体实现步骤 #### 2.1 数据准备 我们需要准备数据。在本例中,数据被组织成一个名为 `data` 的对象,包含多个属性,如 `title`、`plan_production`、`actual_production` 等。这些数据将作为图表的基础。 ```javascript var data = { title: ['总计', '12-01', '12-02', '12-03', '12-04', '12-05', '12-06', '12-07', '12-08', '12-09'], plan_production: [500, 300, 490, 333, 346, 777, 888, 864, 789, 765], actual_production: [300, 400, 500, 300, 400, 500, 300, 400, 500, 500], // ... 其他数据 }; ``` #### 2.2 图表初始化 使用 ECharts 的 `init` 方法初始化图表实例: ```javascript var myChart = this.$echarts.init(document.getElementById('main')); ``` #### 2.3 配置图表选项 接下来,我们通过 `setOption` 方法设置图表的配置选项。这些选项包括标题、坐标轴、图例以及数据系列等。例如: ```javascript myChart.setOption({ title: [{ text: '\n实际产出\n达成率\n生产效率', bottom: 72, left: 10, textStyle: { lineHeight: 20, fontSize: 13, fontWeight: 'normal', formatter: function (value) { return '{table|' + value + '}'; }, rich: { table: { align: 'center' } } } }], grid: { bottom: 150, left: 80, right: 80 }, xAxis: [{ type: 'category', boundaryGap: true, data: data.title, axisTick: { length: 70 }, axisLabel: { formatter: function (value, index) { return '{table|' + value + '}\n{table|' + data.plan_production[index] + '}\n{table|' + data.actual_production[index] + '}'; }, rich: { table: { lineHeight: 20, align: 'center' } } } }], yAxis: [{ type: 'value', scale: false, minInterval: 1, name: '数量', axisTick: { show: false }, splitLine: { show: true }, axisLine: { show: false } }], series: [ { name: '达成率', type: 'line', smooth: false, itemStyle: { normal: { lineStyle: { width: 1, type: 'dotted' } } }, label: { show: true, position: 'top', formatter: '{c}%' }, yAxisIndex: 0, data: data.attainment_rate }, { name: '实际产出', type: 'line', smooth: false, itemStyle: { normal: { lineStyle: { width: 2, type: 'solid' } } }, label: { show: true, position: 'top', formatter: '{c}' }, yAxisIndex: 0, data: data.actual_production } ] }); ``` ### 三、实现虚线效果 在上述代码中,通过 `itemStyle.normal.lineStyle.type` 设置为 `'dotted'` 来实现虚线效果。这是 ECharts 提供的一种简单方法来改变折线的样式。例如: ```javascript itemStyle: { normal: { lineStyle: { width: 1, type: 'dotted' // 设置虚线 } } } ``` ### 四、其他配置项 除了上述基本配置外,还可以进一步定制图表的样式和行为。例如,可以通过 `grid` 控制图表的边距;通过 `axisLabel.formatter` 自定义坐标轴标签的格式等。 ### 五、总结 本文详细介绍了如何在 ECharts 中实现双折线图,并让其中一条折线显示为虚线的方法。通过上述步骤,可以轻松地在网页上展示动态、直观的图表,从而帮助用户更好地理解和分析数据。同时,ECharts 还提供了丰富的配置选项,允许开发者根据具体需求进行自定义。

















<div>
双折现
<div id="main"></div>
</div>
</template>
<script>
export default {
props:['lines'],
data(){
return{
}
},
mounted(){
var data = {
title: ['总计', '12-01', '12-02', '12-03', '12-04', '12-05', '12-06', '12-07', '12-08', '12-09'],
plan_production: [500, 300, 490, 333, 346, 777, 888, 864, 789, 765],
actual_production: [300, 400, 500, 300, 400, 500, 300, 400, 500, 500],
attainment_rate: [60, 80, 90, 60, 70, 80, 90, 60, 70, 90],
productivity: [30, 45, 88, 100, 110, 70, 80, 90, 100, 100]
};
for (var pr in data) {
data[pr] = data[pr].slice(1, -1);
}
function getTableLine(num) {
var list = [];
var bottom = 122;
var height = 20;
for (var i = 0; i < num; i++) {
list.push({
type: 'line',
bottom: bottom - i * height,
// 偏移量
right: 80,
style: {
fill: '#333'
},
shape: {
x1: 0,
y1: 0,
// 控制坐标做线条
x2: 0,
y2: 0
}
});
}
return list;
}
// getTableLine参数代表行
var lineList = getTableLine(3);
// 获取页面标签
var myChart = this.$echarts.init(document.getElementById('main'));
//指定图标的配置和数据
myChart.setOption({
剩余5页未读,继续阅读

- PhiHongDG2020-06-30辣鸡玩意 分还那么高

- 粉丝: 84
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 网络教学模式省名师优质课赛课获奖课件市赛课百校联赛优质课一等奖课件.pptx
- 电子商务概论-李琪版的ppt课件.ppt
- 基于SVM的乳腺癌图像识别,使用DDSM公开数据集
- 教育软件代理协议书.docx
- 基于单片机的自动避障小车设计与实现.doc
- 软件工程基础习题集.docx
- 云桌面虚拟化解决方案.docx
- 招聘成功的人才微软招聘过程及经验(最终).pptx
- 综合布线毕业设计论文.doc
- 网络营销--如何让你的网店人尽皆知.pptx
- 2019金融数据科技信息区块链PPT模板.pptx
- SQLServer数据库系统设计与实现指导书.doc
- 鄂教版七上语文大自然语言图文.pptx
- 2022年C语言知识点总结正式版.doc
- 干货分享区块链核心技术之共识机制样本.docx
- 通信公司企业文化诊断报告终稿.pptx


