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

仪表盘刻度的显示范围自定义,起点设置为自定义的最小值,有方法吗 #2306

Closed
xiao15934831580 opened this issue Apr 13, 2020 · 0 comments

Comments

@xiao15934831580
Copy link

const Shape = G2.Shape;
// 自定义Shape 部分
Shape.registerShape('point', 'pointer', {
drawShape(cfg, group) {
const center = this.parsePoint({ // 获取极坐标系下画布中心点
x: 0,
y: 0
});
// 绘制指针
group.addShape('line', {
attrs: {
x1: center.x,
y1: center.y,
x2: cfg.x,
y2: cfg.y,
stroke: cfg.color,
lineWidth: 5,
lineCap: 'round'
}
});
return group.addShape('circle', {
attrs: {
x: center.x,
y: center.y,
r: 9.75,
stroke: cfg.color,
lineWidth: 4.5,
fill: '#fff'
}
});
}
});

const data = [
{ value: 5.6 }
];
const chart = new G2.Chart({
container: 'container',
forceFit: true,
height: 500,
padding: [ 0, 0, 30, 0 ]
});
chart.source(data);

chart.coord('polar', {
startAngle: -9 / 8 * Math.PI,
endAngle: 1 / 8 * Math.PI,
radius: 0.75
});
chart.scale('value', {
min: 1,
max: 9,
tickInterval: 4,
nice: false,
range:[0,1]
});

chart.axis('1', false);
chart.axis('value', {
zIndex: 2,
line: null,
label: {
offset: -16,
textStyle: {
fontSize: 18,
textAlign: 'center',
textBaseline: 'middle'
}
},
subTickCount: 4,
subTickLine: {
length: -8,
stroke: '#fff',
strokeOpacity: 1
},
tickLine: {
length: -17,
stroke: '#fff',
strokeOpacity: 1
},
grid: null
});
chart.legend(false);
chart.point().position('value*1')
.shape('pointer')
.color('#1890FF')
.active(false);

// 绘制仪表盘背景
chart.guide().arc({
zIndex: 0,
top: false,
start: [ 1, 0.945 ],
end: [ 9, 0.945 ],
style: { // 底灰色
stroke: '#CBCBCB',
lineWidth: 18
}
});
// 绘制指标
chart.guide().arc({
zIndex: 1,
start: [1, 0.945 ],
end: [ data[0].value, 0.945 ],
style: {
stroke: '#1890FF',
lineWidth: 18
}
});
// 绘制指标数字
chart.guide().html({
position: [ '50%', '95%' ],
html: '

'
+ '

合格率

'
+ '

' + data[0].value * 10 + '%

'
+ '
'
});

chart.render();

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

1 participant