av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)ECharts教程:ECharts自定義系列的渲染邏輯

renderItem 

ECharts 自定義(custom)系列需要開發(fā)者自己提供圖形渲染的邏輯。這個渲染邏輯一般命名為 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
    }]
}

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

renderItem 函數(shù)提供了兩個參數(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 中的兩個函數(shù):

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

有時候還需要用到 api.size(...) 函數(shù),表示得到坐標(biāo)系上一段數(shù)值范圍對應(yī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ù)的詳細介紹,請參考下述內(nèi)容。

  • params

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

    {
        context: // {Object} 一個可供開發(fā)者暫存東西的對象。
        seriesId: // {string} 本系列 id。
        seriesName: // {string} 本系列 name。
        seriesIndex: // {number} 本系列 index。
        dataIndex: // {number} 數(shù)據(jù)項的 index。
        dataIndexInside: // {number} 數(shù)據(jù)項在當(dāng)前坐標(biāo)系中可見的數(shù)據(jù)的 index(即 dataZoom 當(dāng)前窗口中的數(shù)據(jù)的 index)。
        dataInsideLength: // {number} 當(dāng)前坐標(biāo)系中可見的數(shù)據(jù)長度(即 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,因為從 dataIndex 轉(zhuǎn)換成 dataIndexInside 需要時間開銷。

  • api

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