日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)ECharts教程:ECharts自定義系列的渲染邏輯

renderItem 

ECharts 自定義(custom)系列需要開發(fā)者自己提供圖形渲染的邏輯。這個(gè)渲染邏輯一般命名為 renderItem。例如:

成都創(chuàng)新互聯(lián)公司主營上城網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,上城h5小程序制作搭建,上城網(wǎng)站營銷推廣歡迎上城等地區(qū)企業(yè)咨詢

var option = {
    ...,
    series: [{
        type: 'custom',
        renderItem: function (params, api) {
            var categoryIndex = api.value(0);
            var start = api.coord([api.value(1), categoryIndex]);
            var end = api.coord([api.value(2), categoryIndex]);
            var height = api.size([0, 1])[1] * 0.6;

            return {
                type: 'rect',
                shape: echarts.graphic.clipRectByRect({
                    x: start[0],
                    y: start[1] - height / 2,
                    width: end[0] - start[0],
                    height: height
                }, {
                    x: params.coordSys.x,
                    y: params.coordSys.y,
                    width: params.coordSys.width,
                    height: params.coordSys.height
                }),
                style: api.style()
            };
        },
        data: data
    }]
}

對(duì)于 data 中的每個(gè)數(shù)據(jù)項(xiàng)(為方便描述,這里稱為 dataItem),會(huì)調(diào)用此 renderItem 函數(shù)。

renderItem 函數(shù)提供了兩個(gè)參數(shù):

  • params:包含了當(dāng)前數(shù)據(jù)信息和坐標(biāo)系的信息。
  • api:是一些開發(fā)者可調(diào)用的方法集合。

renderItem 函數(shù)須返回根據(jù)此 dataItem 繪制出的圖形元素的定義信息,參見 renderItem.return。

一般來說,renderItem 函數(shù)的主要邏輯,是將 dataItem 里的值映射到坐標(biāo)系上的圖形元素。這一般需要用到 renderItem.arguments.api 中的兩個(gè)函數(shù):

  • api.value(...):意思是取出 dataItem 中的數(shù)值。例如 api.value(0) 表示取出當(dāng)前 dataItem 中第一個(gè)維度的數(shù)值。
  • api.coord(...):意思是進(jìn)行坐標(biāo)轉(zhuǎn)換計(jì)算。例如 var point = api.coord([api.value(0), api.value(1)]) 表示 dataItem 中的數(shù)值轉(zhuǎn)換成坐標(biāo)系上的點(diǎn)。

有時(shí)候還需要用到 api.size(...) 函數(shù),表示得到坐標(biāo)系上一段數(shù)值范圍對(duì)應(yīng)的長(zhǎng)度。

返回值中樣式的設(shè)置可以使用 api.style(...) 函數(shù),他能得到 series.itemStyle.normal 中定義的樣式信息,以及視覺映射的樣式信息。也可以用這種方式覆蓋這些樣式信息:api.style({fill: 'green', stroke: 'yellow'})。

renderItem 函數(shù)的參數(shù)

arguments

arguments 是 renderItem 函數(shù)的參數(shù),包括了 params 參數(shù)和 api 參數(shù),關(guān)于這兩參數(shù)的詳細(xì)介紹,請(qǐng)參考下述內(nèi)容。

  • params

    renderItem 函數(shù)的第一個(gè)參數(shù),含有:

    {
        context: // {Object} 一個(gè)可供開發(fā)者暫存東西的對(duì)象。
        seriesId: // {string} 本系列 id。
        seriesName: // {string} 本系列 name。
        seriesIndex: // {number} 本系列 index。
        dataIndex: // {number} 數(shù)據(jù)項(xiàng)的 index。
        dataIndexInside: // {number} 數(shù)據(jù)項(xiàng)在當(dāng)前坐標(biāo)系中可見的數(shù)據(jù)的 index(即 dataZoom 當(dāng)前窗口中的數(shù)據(jù)的 index)。
        dataInsideLength: // {number} 當(dāng)前坐標(biāo)系中可見的數(shù)據(jù)長(zhǎng)度(即 dataZoom 當(dāng)前窗口中的數(shù)據(jù)數(shù)量)。
        coordSys: // 不同的坐標(biāo)系中,coordSys 里的信息不一樣,含有如下這些可能:
        coordSys: {
            type: 'cartesian2d',
            x: // {number} grid rect 的 x
            y: // {number} grid rect 的 y
            width: // {number} grid rect 的 width
            height: // {number} grid rect 的 height
        },
        coordSys: {
            type: 'calendar',
            x: // {number} calendar rect 的 x
            y: // {number} calendar rect 的 y
            width: // {number} calendar rect 的 width
            height: // {number} calendar rect 的 height
            cellWidth: // {number} calendar cellWidth
            cellHeight: // {number} calendar cellHeight
            rangeInfo: {
                start: // calendar 日期開端
                end: // calendar 日期結(jié)尾
                weeks: // calendar 周數(shù)
                dayCount: // calendar 日數(shù)
            }
        },
        coordSys: {
            type: 'geo',
            x: // {number} geo rect 的 x
            y: // {number} geo rect 的 y
            width: // {number} geo rect 的 width
            height: // {number} geo rect 的 height
        },
        coordSys: {
            type: 'polar',
            cx: // {number} polar 的中心坐標(biāo)
            cy: // {number} polar 的中心坐標(biāo)
            r: // {number} polar 的外半徑
            r0: // {number} polar 的內(nèi)半徑
        },
        coordSys: {
            type: 'singleAxis',
            x: // {number} singleAxis rect 的 x
            y: // {number} singleAxis rect 的 y
            width: // {number} singleAxis rect 的 width
            height: // {number} singleAxis rect 的 height
        }
    }

    其中,關(guān)于 dataIndex 和 dataIndexInside 的區(qū)別:

    • dataIndex 指的 dataItem 在原始數(shù)據(jù)中的 index。
    • dataIndexInside 指的是 dataItem 在當(dāng)前數(shù)據(jù)窗口(參見 dataZoom)中的 index。

    renderItem.arguments.api 中使用的參數(shù)都是 dataIndexInside 而非 dataIndex,因?yàn)閺?nbsp;dataIndex 轉(zhuǎn)換成 dataIndexInside 需要時(shí)間開銷。

  • api

    renderItem 函數(shù)的第二個(gè)參數(shù),它具有以下的屬性: