2018.4.10工作总结--折线的虚实交替(一条折线两种样式或者多种样式)

实现效果:
虚实折线.png

实现方式:
通过两条或多条不同样式折线的数据重叠:
var series= [
{
name: '2017年',
type: 'line',
symbolSize: 0,
data: [30, 80, 50, '-', '-', '-', '-', '-', '-', '-', '-', '-'],//重叠的数据,不需要展示此折线样式的用‘-’代替
//不同的样式:
lineStyle: {
normal: {
type: 'solid',
color: '#b9c3cf'
}
},
},
{
name: '2018年',
type: 'line',
symbolSize: 6,
data: ['-', '-', 50, 60, 70, 30, 55, 50, 40, 39, 38, 39,],//重叠的数据,不需要展示此折线样式的用‘-’代替
//不同的样式:
itemStyle: {
normal: {
color: '#0089df'
}
},
lineStyle: {
normal: {
color: '#0089df',
}
},
label: {
normal: {
show: true,
position: 'top',
formatter: '{c}%'
}
},
}
]

数据处理:
设置一个判断条件,获取数据时根据条件相应地给series[0]或series[1]赋值:例如年份

// 数据跨年份的series
var series1 = [
{
name: '2017年',
type: 'line',
label: seriesLabel,
data: [],
lineStyle: {
normal: {
type: 'solid',
color: '#b9c3cf',
}
}
},
{
name: '2018年',
type: 'line',
lineStyle: {
normal: {
color: '#0089df',
type: 'dotted',
}
},
label: seriesLabel,
data: [],
},
];
// 数据不跨年的series
var series2 = [
{
name: '2018年',
type: 'line',

    lineStyle: {
        normal: {
            color: '#0089df',
            type: 'dotted',
        }
    },
    label: seriesLabel,
    data: [],
},

];
var currentYear = currentTime.slice(0, 4);//当期年
if (data.result1 && data.result1.length != 0) {
var result1 = data.result1;
var myChart1 = echarts.dispose(document.getElementById('chart1'));//消除图表
var myChart1 = echarts.init(document.getElementById('chart1'));//初始化图表
var firstDataYear = result1[0].column2; // 第一个数据的年份
var a = 0;//判断Flag
if (firstDataYear != currentYear) {//跨年份的数据处理:
option1.series = series1;//给series赋值
option1.series[0].data = [];//series[0].data清零
option1.series[1].data = [];//series[1].data清零
var fillRateList1 = [];//series[0].data数据
var fillRateList2 = [];//series[1].data数据
var fillRateList=[];//所有数据

    for (var i = 0; i < result1.length; i++) {
        var comparison = result1[i].column2; //年份判断
        var fillRate = (Math.round(result1[i].column4 * 10) / 10).toFixed(1) * 1; // 满足率
        fillRateList.push(fillRate);
        if (comparison != firstDataYear) {
            a = a + 1;//判断Flag
            if (a == 1) {
                fillRateList1.push(fillRate);
                fillRateList2.push(fillRate);
            } else {
                fillRateList1.push('-');
                fillRateList2.push(fillRate);
            }
        } else {
            fillRateList1.push(fillRate);
            fillRateList2.push('-');
        };
    };
    option1.series[0].data = fillRateList1;//第1个年份的数据
    option1.series[1].data = fillRateList2;//第2个年份的数据
 
    var Max1 = getmax(fillRateList);//所有数据的最大值
    Max1=(Math.ceil(Max3/10))*10;//最大值向上取整十
    var Min1 = getmin(fillRateList);//所有数据的最小值
    Min1=(Math.floor(Min3/10))*10;//最小值向下取整十
    option1.yAxis.max = Max1;//y轴刻度的最大值==Max1
    option1.yAxis.min = Min1;//y轴刻度的最小值==Min1
    myChart1.setOption(option1);

} else {//不跨年份的数据处理
    option1.series = series2;//给series赋值
    option1.series[0].data = [];//series[0].data清零
    option1.series[1].data = [];//series[1].data清零
    var fillRateList = [];//series[0].data数据 
    for (var i = 0; i < result1.length; i++) {
        var fillRate = (Math.round(result1[i].column4 * 10) / 10).toFixed(1) * 1; // 满足率
        fillRateList.push(fillRate);
    };
    option1.series[0].data = fillRateList;

    var Max1 = getmax(fillRateList);//所有数据的最大值
    Max1=(Math.ceil(Max3/10))*10;//最大值向上取整十
    var Min1 = getmin(fillRateList);//所有数据的最小值
    Min1=(Math.floor(Min3/10))*10;//最小值向下取整十
    option1.yAxis.max = Max1;//y轴刻度的最大值==Max1
    option1.yAxis.min = Min1;//y轴刻度的最小值==Min1
    myChart1.setOption(option1);

};

};

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 这篇文章主要讲述Echarts设置字体和线条的颜色相关操作笔记,希望文章对你有所帮助,主要是自己的在线笔记吧。我在...
    蓝色梦想家阅读 10,297评论 1 1
  • body{-moz-osx-font-smoothing:grayscale;-webkit-font-smoot...
    wangyw阅读 664评论 0 0
  • HTML 5 HTML5概述 因特网上的信息是以网页的形式展示给用户的,因此网页是网络信息传递的载体。网页文件是用...
    阿啊阿吖丁阅读 4,985评论 0 0
  • 毛梦溪运用弗洛伊德的潜意识给出答案: 1、重塑优秀的自己 自己可以重塑吗?可以的,积极的心理暗示喽,我好牛,我好棒...
    倪家大老爷阅读 592评论 0 0
  • 凛冽寒风吹进我的衣袖 冷颤随之而来 银杏零落在我的面前 哈出一口热气 期待着香气喷鼻的烤红薯 突然想到你 在低头的...
    不会冬眠的小松鼠阅读 303评论 1 2

友情链接更多精彩内容