Echarts学习精华的提炼,不了解这些多线程的基础知识很难学懂前端

67 阅读10分钟

学习笔记

主要内容包括html,css,html5,css3,JavaScript,正则表达式,函数,BOM,DOM,jQuery,AJAX,vue等等

HTML/CSS

**HTML:**HTML基本结构,标签属性,事件属性,文本标签,多媒体标签,列表 / 表格 / 表单标签,其他语义化标签,网页结构,模块划分

**CSS:**CSS代码语法,CSS 放置位置,CSS的继承,选择器的种类/优先级,背景样式,字体样式,文本属性,基本样式,样式重置,盒模型样式,浮动float,定位position,浏览器默认样式

HTML5 /CSS3

**HTML5:**HTML5 的优势,HTML5 废弃元素,HTML5 新增元素,HTML5 表单相关元素和属性

**CSS3:**CSS3 新增选择器,CSS3 新增属性,新增变形动画属性,3D变形属性,CSS3 的过渡属性,CSS3 的动画属性,CSS3 新增多列属性,CSS3新增单位,弹性盒模型

JavaScript

**JavaScript:**JavaScript基础,JavaScript数据类型,算术运算,强制转换,赋值运算,关系运算,逻辑运算,三元运算,分支循环,switch,while,do-while,for,break,continue,数组,数组方法,二维数组,字符串

开源分享:docs.qq.com/doc/DSmRnRG… center: ['50%', '50%'],

roseType: 'radius',

itemStyle: {

borderRadius: 5

},

data: [ //存放自己的数据

{ value: 20, name: '云南' },

{ value: 26, name: '北京' },

{ value: 24, name: '山东' },

{ value: 25, name: '河北' },

{ value: 20, name: '江苏' },

{ value: 25, name: '浙江' },

{ value: 30, name: '四川' },

{ value: 42, name: '湖北' }

],

label: { // label对象用于修饰图表中的字体

fontSize: 12,

},

labelLine: { // labelLine中注释的线

length: 6,

length2: 8 //其实饼状图上默认有两条注释线引申出来控制线的长短

}

}

],

yAxis为y轴;xAxis为x轴

grid绘图网格

legend图例组件

如下图所示:

柱状图

===

插入本案例中的代码如下:

// 柱状图

(function() {

// 把柱形图中的效果放在一个变量中使用时引用

var item = {

value: 1200,

// itemStyle是对柱子样式进行修改

itemStyle: {

color: '#254065'

},

// 当鼠标在柱子上没有高光效果

emphasis: {

itemStyle: {

color: '#254065'

}

},

// 当鼠标经过提示框中没有提示效果

tooltip: {

extraCssText: 'opacity:0'

}

};

var myChart = echarts.init(document.querySelector(".bar"));

var option = {

color: new echarts.graphic.LinearGradient(

// (x1,y2) 点到点 (x2,y2) 之间进行渐变

0, 0, 0, 1, [

{ offset: 0, color: '#00fffb' }, // 0 起始颜色

{ offset: 1, color: '#0061ce' } // 1 结束颜色

]

),

tooltip: {

trigger: 'item',

},

grid: {

top: "3%",

left: '0%',

right: '3%',

bottom: '3%',

containLabel: true,

//

show: true,

borderColor: 'rgba(0, 240, 255, 0.3)'

},

xAxis: [{

type: 'category',

data: ['上海', '广州', '北京', '深圳', '合肥', '', '......', '', '杭州', '厦门', '济南', '成都', '重庆'],

// 刻度设置

axisTick: {

// true 图形在刻度中间

alignWithLabel: false,

show: false // 不出现刻度

},

axisLabel: {

color: "#4c9bfd"

},

// x坐标轴颜色设置

axisLine: {

lineStyle: {

color: 'rgba(0, 240, 255, 0.3)',

}

}

}],

yAxis: [{

type: 'value',

// 刻度设置

axisTick: {

// true 图形在刻度中间

alignWithLabel: false,

show: false // 不出现刻度

},

axisLabel: {

color: "#4c9bfd"

},

// x坐标轴颜色设置

axisLine: {

lineStyle: {

color: 'rgba(0, 240, 255, 0.3)',

}

}

}],

series: [{

name: 'Direct',

type: 'bar',

barWidth: '60%',

data: [2100, 1900, 1700, 1560, 1400, item,

item,

item,

900, 750, 600, 480, 240

]

}]

};

myChart.setOption(option);

// 4.图标也可以自适应我们的屏幕

window.addEventListener("resize", function() {

myChart.resize();

});

})();

itemStyle:

itemStyle: { // itemStyle是对柱子样式进行修改

color: '#254065'

},

 emphasis:

emphasis: { // 当鼠标在柱子上没有高光效果

itemStyle: {

color: '#254065'

}

},

柱状图中的渐变效果:

color: new echarts.graphic.LinearGradient(

0, 0, 0, 1, [ // (x1,y2) 点到点 (x2,y2) 之间进行渐变

{ offset: 0, color: '#00fffb' }, // 0 起始颜色

{ offset: 1, color: '#0061ce' } // 1 结束颜色

]

)

 grid系列之刻度线:

grid: {

top: "3%",

left: '0%',

right: '3%',

bottom: '3%',

containLabel: true, // 刻度线出现

show: true, //边框x轴y轴的出现

borderColor: 'rgba(0, 240, 255, 0.3)' //边框x轴y轴的颜色

}

xAxis系列参数:

xAxis: [{

type: 'category',

data: ['上海', '广州', '北京', '深圳', '合肥', '', '......', '', '杭州', '厦门', '济南', '成都', '重庆'],

axisTick: {// 刻度设置

alignWithLabel: false, // true 图形在刻度中间

show: false // 不出现刻度

},

axisLabel: { //x轴的颜色

color: "#4c9bfd"

},

axisLine: { // x坐标轴颜色设置

lineStyle: {

color: 'rgba(0, 240, 255, 0.3)',

}

}

}]

折线图

===

插入本案例中的代码如下:

// 折线图

(function() {

// 准备数据

var data = {

year: [

[24, 40, 101, 134, 90, 230, 210, 230, 120, 230, 210, 120],

[40, 64, 191, 324, 290, 330, 310, 213, 180, 200, 180, 79]

],

quarter: [

[23, 75, 12, 97, 21, 67, 98, 21, 43, 64, 76, 38],

[43, 31, 65, 23, 78, 21, 82, 64, 43, 60, 19, 34]

],

month: [

[34, 87, 32, 76, 98, 12, 32, 87, 39, 36, 29, 36],

[56, 43, 98, 21, 56, 87, 43, 12, 43, 54, 12, 98]

],

week: [

[43, 73, 62, 54, 91, 54, 84, 43, 86, 43, 54, 53],

[32, 54, 34, 87, 32, 45, 62, 68, 93, 54, 54, 24]

]

}

var myChart = echarts.init(document.querySelector(".line"));

var option = {

tooltip: {

trigger: 'axis'

},

legend: {

textStyle: {

color: '#4c9bfd' // 图例文字颜色

},

right: '10%', // 距离右边10%

// 如果series 里面设置了name,那么此时图里组件的data可以省略!!!

// data: ['Email', 'Union Ads']

},

grid: {

top: "20%",

left: '3%',

right: '4%',

bottom: '3%',

show: true, //显示边框

borderColor: '#012f4a', // 边框颜色

containLabel: true

},

xAxis: {

type: 'category',

boundaryGap: false, // 去除轴内间距

axisTick: {

show: false // 去除刻度线

},

axisLabel: {

color: '#4c9bfd' // 文本颜色

},

axisLine: {

show: false // 去除轴线

},

data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']

},

yAxis: {

type: 'value',

axisTick: {

show: false // 去除刻度

},

axisLabel: {

color: '#4c9bfd' // 文字颜色

},

splitLine: {

lineStyle: {

color: '#012f4a' // 分割线颜色

}

}

},

color: ['#00f2f1', '#ed3f35'], //两条曲线改变颜色

series: [{

name: '预期销售额',

type: 'line',

smooth: true,

stack: "总量",

data: data.year[0]

},

{

name: '实际销售额',

type: 'line',

smooth: true,

stack: "总量",

data: data.year[1]

}

]

};

myChart.setOption(option);

// 4.图标也可以自适应我们的屏幕

window.addEventListener("resize", function() {

myChart.resize();

legend系列之改变位置:

legend: {

textStyle: {

color: '#4c9bfd' // 图例文字颜色

},

right: '10%', // 距离右边10%

// data: ['Email', 'Union Ads']

// 如果series 里面设置了name,那么此时图里组件的data可以省略!!!

}

yAxis系列之splitLine:

yAxis: {

type: 'value',

axisTick: {

show: false // 去除刻度

},

axisLabel: {

color: '#4c9bfd' // 文字颜色

},

splitLine: {

lineStyle: {

color: '#012f4a' // 分割线颜色

}

}

}

color图表中的折线线条颜色:

color: ['#00f2f1', '#ed3f35'], //两条曲线改变颜色

雷达图

===

插入本案例中的代码如下:

// 雷达图

(function() {

var myChart = echarts.init(document.querySelector(".radar"));

var dataBJ = [

[90, 19, 56, 11, 34]

];

var lineStyle = {

width: 1,

opacity: 0.5

};

var option = {

tooltip: {

show: true,

// 控制提示框组件的显示位置

position: ['60%', '10%'],

},

legend: {

bottom: 5,

data: ['Beijing'],

itemGap: 20,

textStyle: {

color: '#fff',

fontSize: 14

},

selectedMode: 'single'

},

radar: {

center: ['50%', '50%'],

// radius 外半径(最大的圆)占据容器大小

radius: '65%',

indicator: [

{ name: '机场', max: 100 },

{ name: '商场', max: 100 },

{ name: '火车站', max: 100 },

{ name: '汽车站', max: 100 },

{ name: '地铁', max: 100 }

],

shape: 'circle',

// 指示器轴的分割段数

splitNumber: 4,

axisName: {

color: 'rgb(238, 197, 102)'

},

splitLine: {

// 坐标轴在 grid 区域中的分隔线(圆圈)

lineStyle: {

color: 'rgba(255, 255, 255, 0.5)',

}

// 如果说要圆圈渐变的效果就用color数组装不同的颜色

/* color: [

"rgba(238, 197, 102, 0.1)",

"rgba(238, 197, 102, 0.2)",

"rgba(238, 197, 102, 0.4)",

"rgba(238, 197, 102, 0.6)",

"rgba(238, 197, 102, 0.8)",

"rgba(238, 197, 102, 1)"

].reverse() */

},

splitArea: {

show: false

},

// axisLine也就是雷达图的分割线也是坐标轴

axisLine: {

show: true,

lineStyle: {

color: 'rgba(255, 255, 255, 0.5)'

}

}

},

series: [{

name: "北京",

type: 'radar',

// 填充区域的线条颜色

lineStyle: lineStyle = {

normal: {

color: '#fff',

// width: 1

}

},

data: dataBJ,

// data: [[90, 19, 56, 11, 34]],也可以直接这么表达

// symbol 标记的样式(拐点),还可以取值'rect' 方块 ,'arrow' 三角等

symbol: 'circle',

// 拐点的大小

symbolSize: 5,

// 小圆点(拐点)设置为白色

itemStyle: {

color: '#fff'

},

// 在圆点上显示相关数据

label: {

show: true,

color: '#fff',

fontSize: 10

},

areaStyle: {

opacity: 0.1

},

name: {

// 修饰雷达图文本颜色

textStyle: {

color: '#4c9bfd'

}

},

// 区域填充的背景颜色设置

areaStyle: {

color: 'rgba(238, 197, 102, 0.6)',

},

}]

};

myChart.setOption(option);

window.addEventListener("resize", function() {

myChart.resize();

});

})();

radar系列之splitLine、splitArea、axisLine

radar: {

center: ['50%', '50%'],

// radius 外半径(最大的圆)占据容器大小

radius: '65%',

indicator: [

{ name: '机场', max: 100 },

{ name: '商场', max: 100 },

{ name: '火车站', max: 100 },

{ name: '汽车站', max: 100 },

{ name: '地铁', max: 100 }

],

shape: 'circle',

splitNumber: 4, // 指示器轴的分割段数

axisName: {

color: 'rgb(238, 197, 102)'

},

splitLine: {

lineStyle: { // 坐标轴在 grid 区域中的分隔线(圆圈)

color: 'rgba(255, 255, 255, 0.5)',

}

// 如果说要圆圈渐变的效果就用color数组装不同的颜色

/* color: [

"rgba(238, 197, 102, 0.1)",

"rgba(238, 197, 102, 0.2)",

"rgba(238, 197, 102, 0.4)",

"rgba(238, 197, 102, 0.6)",

"rgba(238, 197, 102, 0.8)",

"rgba(238, 197, 102, 1)"

].reverse() */

},

splitArea: {

show: false //grid区域中的分隔区域,默认不显示

},

axisLine: { // axisLine也就是雷达图的分割线也是坐标轴

show: true,

lineStyle: {

color: 'rgba(255, 255, 255, 0.5)'

}

}

}

series系列之symbol、symbolSize、itemStyle、areaeStyle

series: [{

name: "北京",

type: 'radar',

// 填充区域的线条颜色

lineStyle: lineStyle = {

normal: {

color: '#fff',

// width: 1

}

},

data: [[90, 19, 56, 11, 34]],

symbol: 'circle', // symbol 标记的样式(拐点),

//还可以取值'rect' 方块 ,'arrow' 三角等

symbolSize: 5, // 拐点的大小

itemStyle: { // 小圆点(拐点)设置为白色

color: '#fff'

},

label: { // 在圆点上显示相关数据

show: true,

color: '#fff',

fontSize: 10

},

areaStyle: {

opacity: 0.1

},

name: {

textStyle: { // 修饰雷达图文本颜色

color: '#4c9bfd'

}

},

areaStyle: { // 区域填充的背景颜色设置

color: 'rgba(238, 197, 102, 0.6)',

},

}]

饼图之环形图

======

插入本案例中的代码如下:

// 半圆形的饼形图gauge

(function() {

var myChart = echarts.init(document.querySelector(".gauge"));

var option = {

series: [{

name: "销售进度",

type: "pie",

// 放大图形

radius: ['130%', '150%'],

// 移动下位置 套住50%文字

center: ['48%', '80%'],

//是否启用防止标签重叠策略

// avoidLabelOverlap: false,

labelLine: {

normal: {

show: false

}

},

// 起始角度,支持范围[0, 360]

startAngle: 180,

// 鼠标经过不变大

hoverOffset: 0,

data: [{

value: 100,

itemStyle: {

// 颜色渐变#00c9e0->#005fc1

color: new echarts.graphic.LinearGradient(

// (x1,y2) 点到点 (x2,y2) 之间进行渐变

0,

0,

0,

1, [

{ offset: 0, color: "#00c9e0" }, // 0 起始颜色

{ offset: 1, color: "#005fc1" } // 1 结束颜色

]

)

}

}, { value: 100, itemStyle: { color: '#12274d' } },

{ value: 200, itemStyle: { color: 'transparent' } } // 透明隐藏第三块区域

]

最后

文章到这里就结束了,如果觉得对你有帮助可以点个赞哦

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】