blob: 591e5f0fb1324233a0f5c41ada3c50bd1d12c668 [file] [log] [blame]
__NUXT_JSONP__("/zh/concepts/dataset", (function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,$,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an,ao,ap,aq,ar,as,at,au){return {data:[{article:{slug:x,toc:[{id:I,depth:u,text:I},{id:J,depth:u,text:J},{id:K,depth:u,text:K},{id:V,depth:u,text:W},{id:X,depth:u,text:Y},{id:Z,depth:u,text:_},{id:$,depth:u,text:aa},{id:ab,depth:u,text:ac},{id:L,depth:u,text:L},{id:M,depth:u,text:M},{id:ad,depth:u,text:ae},{id:af,depth:u,text:ag},{id:N,depth:u,text:N}],body:{type:"root",children:[{type:b,tag:"h1",props:{id:z},children:[{type:b,tag:f,props:{href:"#%E6%95%B0%E6%8D%AE%E9%9B%86",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:z}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:z}]},{type:a,value:O},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:")是专门用来管理数据的组件。虽然每个系列都可以在 "},{type:b,tag:d,props:{},children:[{type:a,value:F}]},{type:a,value:" 中设置数据,但是从 ECharts4 支持 "},{type:b,tag:d,props:{},children:[{type:a,value:z}]},{type:a,value:" 开始,更推荐使用 "},{type:b,tag:d,props:{},children:[{type:a,value:z}]},{type:a,value:" 来管理数据。因为这样,数据可以被多个组件复用,也方便进行 “数据和其他配置” 分离的配置风格。毕竟,在运行时,数据是最常改变的,而其他配置大多并不会改变。"}]},{type:a,value:c},{type:b,tag:v,props:{id:I},children:[{type:b,tag:f,props:{href:"#%E5%9C%A8%E7%B3%BB%E5%88%97%E4%B8%AD%E8%AE%BE%E7%BD%AE%E6%95%B0%E6%8D%AE",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:I}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"如果数据设置在 "},{type:b,tag:d,props:{},children:[{type:a,value:ah}]},{type:a,value:O},{type:b,tag:d,props:{},children:[{type:a,value:ai}]},{type:a,value:")中,例如:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:aj}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"这种方式的优点是,适于对一些特殊的数据结构(如“树”、“图”、超大数据)进行一定的数据类型定制。\n但是缺点是,常需要用户先处理数据,把数据分割设置到各个系列(和类目轴)中。此外,不利于多个系列共享一份数据,也不利于基于原始数据进行图表类型、系列的映射安排。"}]},{type:a,value:c},{type:b,tag:v,props:{id:J},children:[{type:b,tag:f,props:{href:"#%E5%9C%A8%E6%95%B0%E6%8D%AE%E9%9B%86%E4%B8%AD%E8%AE%BE%E7%BD%AE%E6%95%B0%E6%8D%AE",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:J}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"而数据设置在 "},{type:b,tag:d,props:{},children:[{type:a,value:z}]},{type:a,value:O},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:")中,会有这些好处:"}]},{type:a,value:c},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"能够贴近数据可视化常见思维方式:(I)提供数据,(II)指定数据到视觉的映射,从而形成图表。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"数据和其他配置可以被分离开来。数据常变,其他配置常不变。分开易于分别管理。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"数据可以被多个系列或者组件复用,对于大数据量的场景,不必为每个系列创建一份数据。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"支持更多的数据的常用格式,例如二维数组、对象数组等,一定程度上避免使用者为了数据格式而进行转换。"}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"下面是一个最简单的 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:" 的例子:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:"option = {\n legend: {},\n tooltip: {},\n dataset: {\n \u002F\u002F 提供一份数据。\n source: [\n ['product', '2015', '2016', '2017'],\n ['Matcha Latte', 43.3, 85.8, 93.7],\n ['Milk Tea', 83.1, 73.4, 55.1],\n ['Cheese Cocoa', 86.4, 65.2, 82.5],\n ['Walnut Brownie', 72.4, 53.9, 39.1]\n ]\n },\n \u002F\u002F 声明一个 X 轴,类目轴(category)。默认情况下,类目轴对应到 dataset 第一列。\n xAxis: { type: 'category' },\n \u002F\u002F 声明一个 Y 轴,数值轴。\n yAxis: {},\n \u002F\u002F 声明多个 bar 系列,默认情况下,每个系列会自动对应到 dataset 的每一列。\n series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"或者也可以使用常见的“对象数组”的格式:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:"option = {\n legend: {},\n tooltip: {},\n dataset: {\n \u002F\u002F 用 dimensions 指定了维度的顺序。直角坐标系中,如果 X 轴 type 为 category,\n \u002F\u002F 默认把第一个维度映射到 X 轴上,后面维度映射到 Y 轴上。\n \u002F\u002F 如果不指定 dimensions,也可以通过指定 series.encode\n \u002F\u002F 完成映射,参见后文。\n dimensions: ['product', '2015', '2016', '2017'],\n source: [\n { product: 'Matcha Latte', '2015': 43.3, '2016': 85.8, '2017': 93.7 },\n { product: 'Milk Tea', '2015': 83.1, '2016': 73.4, '2017': 55.1 },\n { product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5 },\n { product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1 }\n ]\n },\n xAxis: { type: 'category' },\n yAxis: {},\n series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]\n};\n"}]}]},{type:a,value:c},{type:b,tag:v,props:{id:K},children:[{type:b,tag:f,props:{href:"#%E6%95%B0%E6%8D%AE%E5%88%B0%E5%9B%BE%E5%BD%A2%E7%9A%84%E6%98%A0%E5%B0%84",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:K}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"如上所述,数据可视化的一个常见思路是:(I)提供数据,(II)指定数据到视觉的映射。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"简而言之,可以进行这些映射的设定:"}]},{type:a,value:c},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"指定 "},{type:b,tag:d,props:{},children:[{type:a,value:z}]},{type:a,value:" 的列(column)还是行(row)映射为 "},{type:b,tag:d,props:{},children:[{type:a,value:ah}]},{type:a,value:O},{type:b,tag:d,props:{},children:[{type:a,value:ai}]},{type:a,value:")。这件事可以使用 "},{type:b,tag:f,props:{href:ak,rel:[g,h,i],target:j},children:[{type:a,value:"series.seriesLayoutBy"}]},{type:a,value:" 属性来配置。默认是按照列(column)来映射。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"指定维度映射的规则:如何从 dataset 的维度(一个“维度”的意思是一行\u002F列)映射到坐标轴(如 X、Y 轴)、提示框(tooltip)、标签(label)、图形元素大小颜色等(visualMap)。这件事可以使用 "},{type:b,tag:f,props:{href:al,rel:[g,h,i],target:j},children:[{type:a,value:D}]},{type:a,value:" 属性,以及 "},{type:b,tag:f,props:{href:R,rel:[g,h,i],target:j},children:[{type:a,value:S}]},{type:a,value:" 组件来配置(如果有需要映射颜色大小等视觉维度的话)。上面的例子中,没有给出这种映射配置,那么 ECharts 就按最常见的理解进行默认映射:X 坐标轴声明为类目轴,默认情况下会自动对应到 "},{type:b,tag:d,props:{},children:[{type:a,value:P}]},{type:a,value:" 中的第一列;三个柱图系列,一一对应到 "},{type:b,tag:d,props:{},children:[{type:a,value:P}]},{type:a,value:" 中后面每一列。"}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"下面详细解释这些映射的设定。"}]},{type:a,value:c},{type:b,tag:v,props:{id:V},children:[{type:b,tag:f,props:{href:"#%E6%8A%8A%E6%95%B0%E6%8D%AE%E9%9B%86%EF%BC%88-dataset-%EF%BC%89%E7%9A%84%E8%A1%8C%E6%88%96%E5%88%97%E6%98%A0%E5%B0%84%E4%B8%BA%E7%B3%BB%E5%88%97%EF%BC%88series%EF%BC%89",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:W}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"有了数据表之后,使用者可以灵活地配置:数据如何对应到轴和图形系列。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"用户可以使用 "},{type:b,tag:d,props:{},children:[{type:a,value:T}]},{type:a,value:" 配置项,改变图表对于行列的理解。"},{type:b,tag:d,props:{},children:[{type:a,value:T}]},{type:a,value:" 可取值:"}]},{type:a,value:c},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"'column': 默认值。系列被安放到 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:" 的列上面。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"'row': 系列被安放到 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:" 的行上面。"}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"看这个例子:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:"option = {\n legend: {},\n tooltip: {},\n dataset: {\n source: [\n ['product', '2012', '2013', '2014', '2015'],\n ['Matcha Latte', 41.1, 30.4, 65.1, 53.3],\n ['Milk Tea', 86.5, 92.1, 85.7, 83.1],\n ['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4]\n ]\n },\n xAxis: [\n { type: 'category', gridIndex: 0 },\n { type: 'category', gridIndex: 1 }\n ],\n yAxis: [{ gridIndex: 0 }, { gridIndex: 1 }],\n grid: [{ bottom: '55%' }, { top: '55%' }],\n series: [\n \u002F\u002F 这几个系列会出现在第一个直角坐标系中,每个系列对应到 dataset 的每一行。\n { type: 'bar', seriesLayoutBy: 'row' },\n { type: 'bar', seriesLayoutBy: 'row' },\n { type: 'bar', seriesLayoutBy: 'row' },\n \u002F\u002F 这几个系列会出现在第二个直角坐标系中,每个系列对应到 dataset 的每一列。\n { type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },\n { type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },\n { type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },\n { type: 'bar', xAxisIndex: 1, yAxisIndex: 1 }\n ]\n};\n"}]}]},{type:a,value:c},{type:b,tag:v,props:{id:X},children:[{type:b,tag:f,props:{href:"#%E7%BB%B4%E5%BA%A6%EF%BC%88-dimension-%EF%BC%89",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:Y}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"常用图表所描述的数据大部分是“二维表”结构,上述的例子中,我们都使用二维数组来容纳二维表。现在,当我们把系列( series )对应到“列”的时候,那么每一列就称为一个“维度( dimension )”,而每一行称为数据项( item )。反之,如果我们把系列( series )对应到表行,那么每一行就是“维度( dimension )”,每一列就是数据项( item )。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"维度可以有单独的名字,便于在图表中显示。维度名( dimension name )可以在定义在 dataset 的第一行(或者第一列)。例如上面的例子中,"},{type:b,tag:d,props:{},children:[{type:a,value:"'score'"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"'amount'"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"'product'"}]},{type:a,value:" 就是维度名。从第二行开始,才是正式的数据。"},{type:b,tag:d,props:{},children:[{type:a,value:P}]},{type:a,value:" 中第一行(列)到底包含不包含维度名,ECharts 默认会自动探测。当然也可以设置 "},{type:b,tag:d,props:{},children:[{type:a,value:"dataset.sourceHeader: true"}]},{type:a,value:" 显示声明第一行(列)就是维度,或者 "},{type:b,tag:d,props:{},children:[{type:a,value:"dataset.sourceHeader: false"}]},{type:a,value:" 表明第一行(列)开始就直接是数据。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"维度的定义,也可以使用单独的 "},{type:b,tag:d,props:{},children:[{type:a,value:"dataset.dimensions"}]},{type:a,value:am},{type:b,tag:d,props:{},children:[{type:a,value:"series.dimensions"}]},{type:a,value:" 来定义,这样可以同时指定维度名,和维度的类型( dimension type ):"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"var option1 = {\n dataset: {\n dimensions: [\n { name: 'score' },\n \u002F\u002F 可以简写为 string ,表示 dimension name 。\n 'amount',\n \u002F\u002F 可以在 type 中指定维度类型。\n { name: 'product', type: 'ordinal' }\n ],\n source: [\n \u002F\u002F...\n ]\n }\n \u002F\u002F ...\n};\n\nvar option2 = {\n dataset: {\n source: [\n \u002F\u002F ...\n ]\n },\n series: {\n type: 'line',\n \u002F\u002F series.dimensions 会更优先于 dataset.dimension 采纳。\n dimensions: [\n null, \u002F\u002F 可以设置为 null 表示不想设置维度名\n 'amount',\n { name: 'product', type: 'ordinal' }\n ]\n }\n \u002F\u002F ...\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"大多数情况下,我们并不需要去设置维度类型,因为 ECharts 会自动尝试判断。但是如果不足够准确时,可以手动设置维度类型。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"维度类型( dimension type )可以取这些值:"}]},{type:a,value:c},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:"'number'"}]},{type:a,value:": 默认,表示普通数据。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:"'ordinal'"}]},{type:a,value:": 对于类目、文本这些 string 类型的数据,如果需要能在数轴上使用,须是 'ordinal' 类型。ECharts 默认会试图自动判断这个类型。但是自动判断也可能不准确,所以使用者也可以手动强制指定。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:Q}]},{type:a,value:": 表示时间数据。设置成 "},{type:b,tag:d,props:{},children:[{type:a,value:Q}]},{type:a,value:" 则能支持自动解析数据成时间戳(timestamp),比如该维度的数据是 '2017-05-10',会自动被解析。如果这个维度被用在时间数轴("},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##xAxis.type",rel:[g,h,i],target:j},children:[{type:a,value:"axis.type"}]},{type:a,value:" 为 "},{type:b,tag:d,props:{},children:[{type:a,value:Q}]},{type:a,value:")上,那么会被自动设置为 "},{type:b,tag:d,props:{},children:[{type:a,value:Q}]},{type:a,value:" 类型。时间类型的支持参见 "},{type:b,tag:f,props:{href:G,rel:[g,h,i],target:j},children:[{type:a,value:"data"}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:an}]},{type:a,value:ao},{type:b,tag:d,props:{},children:[{type:a,value:an}]},{type:a,value:ap},{type:b,tag:d,props:{},children:[{type:a,value:aq}]},{type:a,value:ar}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:as}]},{type:a,value:ao},{type:b,tag:d,props:{},children:[{type:a,value:as}]},{type:a,value:ap},{type:b,tag:d,props:{},children:[{type:a,value:aq}]},{type:a,value:ar}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:v,props:{id:Z},children:[{type:b,tag:f,props:{href:"#%E6%95%B0%E6%8D%AE%E5%88%B0%E5%9B%BE%E5%BD%A2%E7%9A%84%E6%98%A0%E5%B0%84%EF%BC%88-seriesencode-%EF%BC%89",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:_}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"了解了维度的概念后,我们就可以使用 "},{type:b,tag:f,props:{href:al,rel:[g,h,i],target:j},children:[{type:a,value:D}]},{type:a,value:" 来做映射。总体是这样的感觉:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:"var option = {\n dataset: {\n source: [\n ['score', 'amount', 'product'],\n [89.3, 58212, 'Matcha Latte'],\n [57.1, 78254, 'Milk Tea'],\n [74.4, 41032, 'Cheese Cocoa'],\n [50.1, 12755, 'Cheese Brownie'],\n [89.7, 20145, 'Matcha Cocoa'],\n [68.1, 79146, 'Tea'],\n [19.6, 91852, 'Orange Juice'],\n [10.6, 101852, 'Lemon Juice'],\n [32.7, 20112, 'Walnut Brownie']\n ]\n },\n xAxis: {},\n yAxis: { type: 'category' },\n series: [\n {\n type: 'bar',\n encode: {\n \u002F\u002F 将 \"amount\" 列映射到 X 轴。\n x: 'amount',\n \u002F\u002F 将 \"product\" 列映射到 Y 轴。\n y: 'product'\n }\n }\n ]\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:b,tag:d,props:{},children:[{type:a,value:D}]},{type:a,value:" 声明的基本结构如下。其中冒号左边是坐标系、标签等特定名称,如 "},{type:b,tag:d,props:{},children:[{type:a,value:"'x'"}]},{type:a,value:at},{type:b,tag:d,props:{},children:[{type:a,value:"'y'"}]},{type:a,value:at},{type:b,tag:d,props:{},children:[{type:a,value:"'tooltip'"}]},{type:a,value:" 等,冒号右边是数据中的维度名(string 格式)或者维度的序号(number 格式,从 0 开始计数),可以指定一个或多个维度(使用数组)。通常情况下,下面各种信息不需要所有的都写,按需写即可。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"下面是 "},{type:b,tag:d,props:{},children:[{type:a,value:D}]},{type:a,value:" 支持的属性:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"\u002F\u002F 在任何坐标系和系列中,都支持:\nencode: {\n \u002F\u002F 使用 “名为 product 的维度” 和 “名为 score 的维度” 的值在 tooltip 中显示\n tooltip: ['product', 'score']\n \u002F\u002F 使用 “维度 1” 和 “维度 3” 的维度名连起来作为系列名。(有时候名字比较长,这可以避免在 series.name 重复输入这些名字)\n seriesName: [1, 3],\n \u002F\u002F 表示使用 “维度2” 中的值作为 id。这在使用 setOption 动态更新数据时有用处,可以使新老数据用 id 对应起来,从而能够产生合适的数据更新动画。\n itemId: 2,\n \u002F\u002F 指定数据项的名称使用 “维度3” 在饼图等图表中有用,可以使这个名字显示在图例(legend)中。\n itemName: 3\n}\n\n\u002F\u002F 直角坐标系(grid\u002Fcartesian)特有的属性:\nencode: {\n \u002F\u002F 把 “维度1”、“维度5”、“名为 score 的维度” 映射到 X 轴:\n x: [1, 5, 'score'],\n \u002F\u002F 把“维度0”映射到 Y 轴。\n y: 0\n}\n\n\u002F\u002F 单轴(singleAxis)特有的属性:\nencode: {\n single: 3\n}\n\n\u002F\u002F 极坐标系(polar)特有的属性:\nencode: {\n radius: 3,\n angle: 2\n}\n\n\u002F\u002F 地理坐标系(geo)特有的属性:\nencode: {\n lng: 3,\n lat: 2\n}\n\n\u002F\u002F 对于一些没有坐标系的图表,例如饼图、漏斗图等,可以是:\nencode: {\n value: 3\n}\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"这是个更丰富的 "},{type:b,tag:d,props:{},children:[{type:a,value:D}]},{type:a,value:" 的 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Fexamples\u002Fzh\u002Feditor.html?c=dataset-encode1&edit=1&reset=1",rel:[g,h,i],target:j},children:[{type:a,value:U}]},{type:a,value:" 。"}]},{type:a,value:c},{type:b,tag:v,props:{id:$},children:[{type:b,tag:f,props:{href:"#%E9%BB%98%E8%AE%A4%E7%9A%84-seriesencode",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:aa}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"值得一提的是,当 "},{type:b,tag:d,props:{},children:[{type:a,value:D}]},{type:a,value:" 并没有指定时,ECharts 针对最常见直角坐标系中的图表(折线图、柱状图、散点图、K 线图等)、饼图、漏斗图,会采用一些默认的映射规则。默认的映射规则比较简单,大体是:"}]},{type:a,value:c},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"在坐标系中(如直角坐标系、极坐标系等)\n"},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"如果有类目轴(axis.type 为 'category'),则将第一列(行)映射到这个轴上,后续每一列(行)对应一个系列。"}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"如果没有类目轴,假如坐标系有两个轴(例如直角坐标系的 X Y 轴),则每两列对应一个系列,这两列分别映射到这两个轴上。"}]},{type:a,value:c}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"如果没有坐标系(如饼图)\n"},{type:b,tag:C,props:{},children:[{type:a,value:c},{type:b,tag:k,props:{},children:[{type:a,value:"取第一列(行)为名字,第二列(行)为数值(如果只有一列,则取第一列为数值)。"}]},{type:a,value:c}]},{type:a,value:c}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"默认的规则不能满足要求时,就可以自己来配置 "},{type:b,tag:d,props:{},children:[{type:a,value:"encode"}]},{type:a,value:",也并不复杂。这是一个 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Fexamples\u002Fzh\u002Feditor.html?c=dataset-default&edit=1&reset=1",rel:[g,h,i],target:j},children:[{type:a,value:"例子"}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:v,props:{id:ab},children:[{type:b,tag:f,props:{href:"#%E5%87%A0%E4%B8%AA%E5%B8%B8%E8%A7%81%E7%9A%84-seriesencode-%E8%AE%BE%E7%BD%AE%E6%96%B9%E5%BC%8F%E4%B8%BE%E4%BE%8B",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:ac}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:如何把第三列设置为 X 轴,第五列设置为 Y 轴?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:H}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"option = {\n series: {\n \u002F\u002F 注意维度序号(dimensionIndex)从 0 开始计数,第三列是 dimensions[2]。\n encode: { x: 2, y: 4 }\n \u002F\u002F ...\n }\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:如何把第三行设置为 X 轴,第五行设置为 Y 轴?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:H}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"option = {\n series: {\n encode: { x: 2, y: 4 },\n seriesLayoutBy: 'row'\n \u002F\u002F ...\n }\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:如何把第二列设置为标签?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"答:\n关于标签的显示 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##series.label.formatter",rel:[g,h,i],target:j},children:[{type:a,value:"label.formatter"}]},{type:a,value:",现在支持引用特定维度的值,例如:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"series: {\n label: {\n \u002F\u002F `'{@score}'` 表示 “名为 score” 的维度里的值。\n \u002F\u002F `'{@[4]}'` 表示引用序号为 4 的维度里的值。\n formatter: 'aaa{@product}bbb{@score}ccc{@[4]}ddd';\n }\n}\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:如何让第 2 列和第 3 列显示在提示框(tooltip)中?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:H}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"option = {\n series: {\n encode: {\n tooltip: [1, 2]\n \u002F\u002F ...\n }\n \u002F\u002F ...\n }\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:数据里没有维度名,那么怎么给出维度名?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:H}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"var option = {\n dataset: {\n dimensions: ['score', 'amount'],\n source: [\n [89.3, 3371],\n [92.1, 8123],\n [94.4, 1954],\n [85.4, 829]\n ]\n }\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:如何把第三列映射为气泡图的点的大小?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:H}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:"var option = {\n dataset: {\n source: [\n [12, 323, 11.2],\n [23, 167, 8.3],\n [81, 284, 12],\n [91, 413, 4.1],\n [13, 287, 13.5]\n ]\n },\n visualMap: {\n show: false,\n dimension: 2, \u002F\u002F 指向第三列(列序号从 0 开始记,所以设置为 2)。\n min: 2, \u002F\u002F 需要给出数值范围,最小数值。\n max: 15, \u002F\u002F 需要给出数值范围,最大数值。\n inRange: {\n \u002F\u002F 气泡尺寸:5 像素到 60 像素。\n symbolSize: [5, 60]\n }\n },\n xAxis: {},\n yAxis: {},\n series: {\n type: 'scatter'\n }\n};\n"}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"问:encode 里指定了映射,但是不管用?"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"答:可以查查有没有拼错,比如,维度名是:"},{type:b,tag:d,props:{},children:[{type:a,value:"'Life Expectancy'"}]},{type:a,value:",encode 中拼成了 "},{type:b,tag:d,props:{},children:[{type:a,value:"'Life Expectency'"}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:v,props:{id:L},children:[{type:b,tag:f,props:{href:"#%E8%A7%86%E8%A7%89%E9%80%9A%E9%81%93%EF%BC%88%E9%A2%9C%E8%89%B2%E3%80%81%E5%B0%BA%E5%AF%B8%E7%AD%89%EF%BC%89%E7%9A%84%E6%98%A0%E5%B0%84",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:L}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"我们可以使用 "},{type:b,tag:f,props:{href:R,rel:[g,h,i],target:j},children:[{type:a,value:S}]},{type:a,value:" 组件进行视觉通道的映射。详见 "},{type:b,tag:f,props:{href:R,rel:[g,h,i],target:j},children:[{type:a,value:S}]},{type:a,value:" 文档的介绍。这是一个 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Fexamples\u002Fzh\u002Feditor.html?c=dataset-encode0&edit=1&reset=1",rel:[g,h,i],target:j},children:[{type:a,value:U}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:v,props:{id:M},children:[{type:b,tag:f,props:{href:"#%E6%95%B0%E6%8D%AE%E7%9A%84%E5%90%84%E7%A7%8D%E6%A0%BC%E5%BC%8F",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:M}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"多数常见图表中,数据适于用二维表的形式描述。广为使用的数据表格软件(如 MS Excel、Numbers)或者关系数据数据库都是二维表。他们的数据可以导出成 JSON 格式,输入到 "},{type:b,tag:d,props:{},children:[{type:a,value:P}]},{type:a,value:" 中,在不少情况下可以免去一些数据处理的步骤。"}]},{type:a,value:c},{type:b,tag:"blockquote",props:{},children:[{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"假如数据导出成 csv 文件,那么可以使用一些 csv 工具如 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fgithub.com\u002Fd3\u002Fd3-dsv",rel:[g,h,i],target:j},children:[{type:a,value:"dsv"}]},{type:a,value:am},{type:b,tag:f,props:{href:"https:\u002F\u002Fgithub.com\u002Fmholt\u002FPapaParse",rel:[g,h,i],target:j},children:[{type:a,value:"PapaParse"}]},{type:a,value:" 将 csv 转成 JSON。"}]},{type:a,value:c}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"在 JavaScript 常用的数据传输格式中,二维数组可以比较直观的存储二维表。前面的示例都是使用二维数组表示。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"除了二维数组以外,dataset 也支持例如下面 key-value 方式的数据格式,这类格式也非常常见。但是这类格式中,目前并不支持 "},{type:b,tag:f,props:{href:ak,rel:[g,h,i],target:j},children:[{type:a,value:T}]},{type:a,value:" 参数。"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"dataset: [\n {\n \u002F\u002F 按行的 key-value 形式(对象数组),这是个比较常见的格式。\n source: [\n { product: 'Matcha Latte', count: 823, score: 95.8 },\n { product: 'Milk Tea', count: 235, score: 81.4 },\n { product: 'Cheese Cocoa', count: 1042, score: 91.2 },\n { product: 'Walnut Brownie', count: 988, score: 76.9 }\n ]\n },\n {\n \u002F\u002F 按列的 key-value 形式。\n source: {\n product: ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],\n count: [823, 235, 1042, 988],\n score: [95.8, 81.4, 91.2, 76.9]\n }\n }\n];\n"}]}]},{type:a,value:c},{type:b,tag:v,props:{id:ad},children:[{type:b,tag:f,props:{href:"#%E5%A4%9A%E4%B8%AA-dataset-%E4%BB%A5%E5%8F%8A%E5%A6%82%E4%BD%95%E5%BC%95%E7%94%A8%E4%BB%96%E4%BB%AC",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:ae}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"可以同时定义多个 dataset。系列可以通过 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##series.datasetIndex",rel:[g,h,i],target:j},children:[{type:a,value:"series.datasetIndex"}]},{type:a,value:" 来指定引用哪个 dataset。例如:"}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:y,props:{lang:o,"line-highlights":l,"file-name":l},children:[{type:a,value:"var option = {\n dataset: [\n {\n \u002F\u002F 序号为 0 的 dataset。\n source: []\n },\n {\n \u002F\u002F 序号为 1 的 dataset。\n source: []\n },\n {\n \u002F\u002F 序号为 2 的 dataset。\n source: []\n }\n ],\n series: [\n {\n \u002F\u002F 使用序号为 2 的 dataset。\n datasetIndex: 2\n },\n {\n \u002F\u002F 使用序号为 1 的 dataset。\n datasetIndex: 1\n }\n ]\n};\n"}]}]},{type:a,value:c},{type:b,tag:v,props:{id:af},children:[{type:b,tag:f,props:{href:"#echarts-3-%E7%9A%84%E6%95%B0%E6%8D%AE%E8%AE%BE%E7%BD%AE%E6%96%B9%E5%BC%8F%EF%BC%88seriesdata%EF%BC%89%E4%BB%8D%E6%AD%A3%E5%B8%B8%E4%BD%BF%E7%94%A8",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:ag}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"ECharts 4 之前一直以来的数据声明方式仍然被正常支持,如果系列已经声明了 "},{type:b,tag:f,props:{href:G,rel:[g,h,i],target:j},children:[{type:a,value:F}]},{type:a,value:", 那么就会使用 "},{type:b,tag:f,props:{href:G,rel:[g,h,i],target:j},children:[{type:a,value:F}]},{type:a,value:" 而非 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:m,props:{className:[n]},children:[{type:b,tag:A,props:{lang:o,layout:B},children:[{type:a,value:aj}]}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"其实,"},{type:b,tag:f,props:{href:G,rel:[g,h,i],target:j},children:[{type:a,value:F}]},{type:a,value:" 也是种会一直存在的重要设置方式。一些特殊的非 table 格式的图表,如 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##series-treemap",rel:[g,h,i],target:j},children:[{type:a,value:"treemap"}]},{type:a,value:w},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##series-graph",rel:[g,h,i],target:j},children:[{type:a,value:"graph"}]},{type:a,value:w},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Foption.html##series-lines",rel:[g,h,i],target:j},children:[{type:a,value:"lines"}]},{type:a,value:" 等,现在仍不支持在 dataset 中设置,仍然需要使用 "},{type:b,tag:f,props:{href:G,rel:[g,h,i],target:j},children:[{type:a,value:F}]},{type:a,value:"。另外,对于巨大数据量的渲染(如百万以上的数据量),需要使用 "},{type:b,tag:f,props:{href:"api.html#echartsInstance.appendData"},children:[{type:a,value:"appendData"}]},{type:a,value:" 进行增量加载,这种情况不支持使用 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:E}]},{type:a,value:c},{type:b,tag:v,props:{id:N},children:[{type:b,tag:f,props:{href:"#%E5%85%B6%E4%BB%96",ariaHidden:p,tabIndex:q},children:[{type:b,tag:r,props:{className:[s,t]},children:[]}]},{type:a,value:N}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"目前并非所有图表都支持 dataset。支持 dataset 的图表有:\n"},{type:b,tag:d,props:{},children:[{type:a,value:"line"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"bar"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"pie"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"scatter"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"effectScatter"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"parallel"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"candlestick"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"map"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"funnel"}]},{type:a,value:w},{type:b,tag:d,props:{},children:[{type:a,value:"custom"}]},{type:a,value:"。\n后续会有更多的图表进行支持。"}]},{type:a,value:c},{type:b,tag:e,props:{},children:[{type:a,value:"最后,给出这个 "},{type:b,tag:f,props:{href:"https:\u002F\u002Fecharts.apache.org\u002Fexamples\u002Fzh\u002Feditor.html?c=dataset-link&edit=1&reset=1",rel:[g,h,i],target:j},children:[{type:a,value:U}]},{type:a,value:",多个图表共享一个 "},{type:b,tag:d,props:{},children:[{type:a,value:x}]},{type:a,value:",并带有联动交互。"}]}]},dir:"\u002Fzh\u002Fconcepts",path:"\u002Fzh\u002Fconcepts\u002Fdataset",extension:".md",createdAt:au,updatedAt:au},postPath:"zh\u002Fconcepts\u002Fdataset"}],fetch:{},mutations:[]}}("text","element","\n","code","p","a","nofollow","noopener","noreferrer","_blank","li","","div","nuxt-content-highlight","js","true",-1,"span","icon","icon-link",2,"h2","、","dataset","md-code-block","数据集","md-live","tb","ul","series.encode","。","series.data","https:\u002F\u002Fecharts.apache.org\u002Foption.html##series.data","答:","在系列中设置数据","在数据集中设置数据","数据到图形的映射","视觉通道(颜色、尺寸等)的映射","数据的各种格式","其他","(","dataset.source","'time'","https:\u002F\u002Fecharts.apache.org\u002Foption.html##visualMap","visualMap","seriesLayoutBy","示例","把数据集(-dataset-)的行或列映射为系列(series)","把数据集( dataset )的行或列映射为系列(series)","维度(-dimension-)","维度( dimension )","数据到图形的映射(-seriesencode-)","数据到图形的映射( series.encode )","默认的-seriesencode","默认的 series.encode","几个常见的-seriesencode-设置方式举例","几个常见的 series.encode 设置方式举例","多个-dataset-以及如何引用他们","多个 dataset 以及如何引用他们","echarts-3-的数据设置方式(seriesdata)仍正常使用","ECharts 3 的数据设置方式(series.data)仍正常使用","系列","series","option = {\n xAxis: {\n type: 'category',\n data: ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie']\n },\n yAxis: {},\n series: [\n {\n type: 'bar',\n name: '2015',\n data: [89.3, 92.1, 94.4, 85.4]\n },\n {\n type: 'bar',\n name: '2016',\n data: [95.8, 89.4, 91.2, 76.9]\n },\n {\n type: 'bar',\n name: '2017',\n data: [97.7, 83.1, 92.5, 78.1]\n }\n ]\n};\n","https:\u002F\u002Fecharts.apache.org\u002Foption.html##series.seriesLayoutBy","https:\u002F\u002Fecharts.apache.org\u002Foption.html##series.encode"," 或者 ","'float'",": 如果设置成 ",",在存储时候会使用 ","TypedArray",",对性能优化有好处。","'int'",", ","2021-08-02T05:33:02.867Z")));