[英]Customize label in scatter graph in echarts by baidu
Referring this example to create scatter graph using echarts library: Basic Scattergraph 引用此示例以使用echarts库创建散点图: 基本散点图
My code for this is as follows: 我的代码如下:
option ={
xAxis : [
{
type : 'value',
scale:true
}
],
yAxis : [
{
type : 'value',
scale:true
}
],
series : [
{
symbolSize: 40,
itemStyle: {
normal: {
color: 'lightblue',
borderWidth: 4,
label : {
show: true,
position: 'inside',
formatter: function(v)
{
if (v==[161.2, 51.6])
return 'a'
else
return v
}
}
}
},
type:'scatter',
data: [
[161.2, 51.6],[167.5, 59.0],[157.0, 63.0],[155.8, 53.6],
[170.0, 59.0], [166.0, 69.8], [176.2, 66.8]
],
}
]
};
In the formatter
function inside series
I am trying to match my variable 'v' with a coordinate point from data. 在
series
内部的formatter
函数中,我试图将变量“ v”与数据中的坐标点进行匹配。 But that condition is not satisfied. 但是不满足该条件。 Where am I going wrong?
我要去哪里错了? I only see
[object Object]
in all the bubbles. 我只在所有气泡中看到
[object Object]
。 Please help. 请帮忙。
If you are using the Echarts2.x version, code is as follow: 如果您使用的是Echarts2.x版本,则代码如下:
option ={
xAxis : [
{
type : 'value',
scale:true
}
],
yAxis : [
{
type : 'value',
scale:true
}
],
series : [
{
symbolSize: 40,
itemStyle: {
normal: {
color: 'lightblue',
borderWidth: 4,
label : {
show: true,
position: 'inside',
formatter: function(data){
var v = data.value;
if (v[0]==161.2 && v[1]==51.6)
return 'a'
else
return v
}
}
}
},
type:'scatter',
data: [
[161.2, 51.6],[167.5, 59.0],[157.0, 63.0],[155.8, 53.6],
[170.0, 59.0], [166.0, 69.8], [176.2, 66.8]
],
}
]
};
the parameter of formatter
function is an object which is a point object on the scatter, Its structure is as follow: formatter
函数的参数是一个散点上的点对象,其结构如下:
$vars:Array[3]
color:"lightblue"
componentSubType:"scatter"
componentType:"series"
data:Array[2]
dataIndex:0
dataType:undefined
name:""
seriesIndex:0
seriesName:"-"
seriesType:"scatter"
status:"normal"
value:Array[2]
So the parameter isn't the array you wanted. 因此,该参数不是您想要的数组。 The
itemStyle
attribute is used to set the graphic style, The label
attribute is used to set the text label on the graph, which can be used to explain some data information of the graph. itemStyle
属性用于设置图形样式, label
属性用于设置图形上的文本标签,该标签可用于解释图形的某些数据信息。 Such as value, name, etc. In Echarts3.x in order to make the structure of entire configuration more flat and reasonable, label
was taken out with itemStyle
at the same level. 例如值,名称等。在Echarts3.x中,为了使整个配置的结构更加平坦合理,在同一级别上使用
itemStyle
删除了label
。 like itemStyle
have two states of normal
and emphasis
. 像
itemStyle
一样有normal
和emphasis
两种状态。 if you are using Echarts3.x version, code is like as follow: 如果您使用的是Echarts3.x版本,则代码如下:
option ={
xAxis : [
{
type : 'value',
scale:true
}
],
yAxis : [
{
type : 'value',
scale:true
}
],
series : [
{
symbolSize: 40,
itemStyle: {
normal: {
color: 'lightblue',
borderWidth: 4,
}
},
label : {
normal: {
show: true,
position: 'inside',
formatter: function(data){
var v = data.value;
if (v[0]==161.2 && v[1]==51.6)
return 'a'
else
return v
}
}
},
type:'scatter',
data: [
[161.2, 51.6],[167.5, 59.0],[157.0, 63.0],[155.8, 53.6],
[170.0, 59.0], [166.0, 69.8], [176.2, 66.8]
],
}
]
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.