Echarts中l(wèi)egend屬性使用的方法詳解
Echarts的legend屬性是對圖例組件的相關(guān)配置
而legend就是Echarts圖表中對圖形的解釋部分:
其中l(wèi)egend自身常用的配置屬性如下:
orient
設(shè)置圖例的朝向
屬性值:
vertical // 垂直顯示
或者
horizontal // 水平顯示
legend: { orient: 'vertical' }
legend: { orient: 'horizontal' }
x/y(left/top)
設(shè)置圖例在X軸方向上的位置以及在Y軸方向上的位置
位置 | 取值 |
---|---|
x/left | left/center/right |
y /top | top/center/bottom |
例子:
legend: { orient: 'vertical', x:'right', y:'center' }
樣式設(shè)置
屬性 | 說明 |
---|---|
backgroundColor | 背景顏色 |
borderColor | 邊框顏色 |
borderWidth | 邊框?qū)挾?/td> |
padding | 內(nèi)邊距 |
注意:邊框?qū)挾群蛢?nèi)邊距屬性值為數(shù)值,不加單位。
legend: { orient: 'vertical', x:'center', y:'top', backgroundColor: '#fac858', borderColor: '#5470c6', borderWidth: '200', }
itemGap
控制每一項的間距,也就是圖例之間的距離屬性值為數(shù)值,不帶單位
legend: { orient: 'horizontal', x:'center', y:'top', itemGap: 40 }
itemHeight
控制圖例圖形的高度屬性值為數(shù)字,不加單位
legend: { orient: 'horizontal', x:'center', y:'top', itemHeight: 5 }
textStyle
設(shè)置圖例文字樣式屬性值為一個對象
legend: { orient: 'horizontal', x:'center', y:'top', textStyle: { color: 'red', fontSize: '20px', fontWeight: 700 } }
selected
設(shè)置圖例的某個選項的數(shù)據(jù)默認是顯示還是隱藏。
false: 隱藏
屬性值:對象,屬性值內(nèi)容:圖例上的數(shù)據(jù)與boolean構(gòu)成鍵值對
如果某選項設(shè)置為false,那么圖標上的數(shù)據(jù)也會默認不顯示,而圖例會以灰色樣式顯示
legend: { orient: 'horizontal', x:'center', y:'top', selected:{ '搜索引擎': false, '聯(lián)盟廣告': false } }
data
圖例上顯示的文字信息,如果不設(shè)置該項,默認會以series設(shè)置的信息作為圖例信息。如果設(shè)置該項,必須與series設(shè)置的信息一致,才會生效。
而該屬性的作用:可以單獨對圖例中某個選項進行單獨設(shè)置樣式
比如:
legend: { orient: 'horizontal', x:'center', y:'top', data:[{ name: '搜索引擎', icon: 'circle', textStyle: {fontWeight: 'bold', color: 'orange'} },'直接訪問','郵件營銷','聯(lián)盟廣告','視頻廣告'] }
以上單獨設(shè)置中
name:指定該項的名稱,必填
icon:指定圖例項的icon,可以為內(nèi)置的圖形7個圖形,或者自定義圖標的形式:'image://url'
textStyle::設(shè)置文本樣式
補充:自定義legend屬性
legend: [{ itemWidth: 26, data: [{ name: nowIndex.name, icon: "rect" }], left: "0", itemHeight: 6, textStyle: { fontSize: 12, color: "#333", padding: [0, 0,-3, 0], // 修改文字和圖標距離 }, }, { itemWidth: 26, data: [{ name: oldIndex.name, icon: "rect" }], left: "35%", itemHeight: 6, textStyle: { fontSize: 12, color: "#333", padding: [0, 0,-3, 0], // 修改文字和圖標距離 }, }, { itemWidth: 26, data: [{ name: danger.name, icon: "roundRect" }], right: "0", itemHeight: 6, textStyle: { fontSize: 12, color: "#333", padding: [0, 0,-3, 0], // 修改文字和圖標距離 }, } ],
實現(xiàn)效果
總結(jié)
到此這篇關(guān)于Echarts中l(wèi)egend屬性使用的文章就介紹到這了,更多相關(guān)Echarts legend屬性使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
js showModalDialog 彈出對話框的簡單實例(子窗體)
本篇文章主要是對js_showModalDialog彈出對話框的簡單實例(子窗體) 進行了詳細的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01JavaScript實現(xiàn)網(wǎng)頁版貪吃蛇游戲
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)網(wǎng)頁版貪吃蛇游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-07-07JavaScript對象的特性與實踐應(yīng)用深入詳解
這篇文章主要介紹了JavaScript對象的特性與實踐應(yīng)用,結(jié)合實例形式較為深入的分析了javascript對象的相關(guān)概念、操作方法及注意事項,需要的朋友可以參考下2018-12-12詳解promise.then,process.nextTick, setTimeout 以及 setImmediate的
這篇文章主要介紹了詳解promise.then,process.nextTick, setTimeout 以及 setImmediate的執(zhí)行順序2018-11-11如何在現(xiàn)代JavaScript中編寫異步任務(wù)
這篇文章主要給大家介紹了關(guān)于如何在現(xiàn)代JavaScript中編寫異步任務(wù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01