Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combinColumns合并列后,通过values设置别名导致color失效 #45

Closed
qqianding opened this issue Dec 1, 2016 · 1 comment
Closed

Comments

@qqianding
Copy link

var frame = new Frame(data.timelineData);
frame = Frame.combinColumns(frame, ['fb', 'rq', 'tcp', 'dns', 'pgrd', 'dmrd', 'psdm'], 'value', 'type', ['date']);
var chart = new G2.Chart({
id: 'J_Chart',
forceFit: true,
height: 400
});
chart.source(frame, {
date: {
alias: '时间',
tickCount: 20
},
value: {
alias: '加载时长'
},
type: {
type: 'cat',
values: ['白屏时长','请求页面时长','TCP连接时长','DNS查找时长','页面加载完成时长','Dom树加载完成时长','Dom树解析时长']
}
});
chart.legend({
title: null,
position: 'bottom',
dy: 10
});
chart.line().position('date*value').color('type', function(value) {
console.log(value);
if(value === '白屏时长') {
return 'red'
}else {
return 'blue';
}
});
chart.render();

color方法里打印出来的全是白屏时长,是哪里设置不对么?

@dxq613
Copy link
Member

dxq613 commented Dec 2, 2016

type列定义的 values改成 formatter 函数,values 的目的有两个:

  • 一个是调整分类值的顺序,这时候values的值要跟数据值一致
  • 如果你这个字段中的数值是 0,1,2,...,n时,values会按照字段索引做个映射,转换成对应的文本

你的情况其实是要将每个文本改变成中文,所以应该使用formatter函数

var map = {fb: '白屏时长', rq: '请求页面时长',...}
type: {
   formatter: function(val){
     return map[val];
   }
}

@dxq613 dxq613 closed this as completed Dec 6, 2016
simaQ pushed a commit that referenced this issue Nov 22, 2017
个体动画以及自定义动画接口

Closed #34 #45 

See merge request !78
simaQ pushed a commit that referenced this issue Nov 22, 2017
个体动画以及自定义动画接口

Closed #34 #45 

See merge request !78
simaQ pushed a commit that referenced this issue Nov 22, 2017
个体动画以及自定义动画接口

Closed #34 #45 

See merge request !78
simaQ pushed a commit that referenced this issue Nov 22, 2017
个体动画以及自定义动画接口

Closed #34 #45 

See merge request !78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants