前端analysis | 3w & 1h

《微信小程序》-F2图表组件实践遇到的那些卡壳

2020-02-27

效果图

卡壳一-自定义颜色,必定tooltip显示重复


1
2
3
4
5
6
7
8
9
chart.tooltip({
showCrosshairs: true,
showTitle: false,
showItemMarker: false,
snap: true,
crosshairsType: 'xy',
});
chart.area().position('date*weight').color('#0ac7d9').shape('smooth').adjust('stack');
chart.line().position('date*weight').color('#0ac7d9').shape('smooth').adjust('stack');

解决方案

1
2
3
4
5
6
7
8
9
10
chart.tooltip({
showCrosshairs: true,
showTitle: false,
showItemMarker: false,
snap: true,
crosshairsType: 'xy',
onShow: function onShow(ev) { //添加如下
return (ev.items = ev.items.splice(1));
},
});

卡壳二-字符串线性展示不支持


解决方案

  • 定义类型,让库自己解决 – 错的离谱,行不通
    1
    2
    3
    4
    5
    6
    // 参数
    [{
    date: "2/27"
    height: "170"
    weight: "70"
    }]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    chart.source(chartData, {
    date: {
    range: [0, 1],
    type: 'timeCat',
    mask: 'MM-DD'
    },
    weight: {
    type:'linear', //添加
    min:0,
    max: 120,
    tickCount: 5,
    alias: '体重(kg)'
    }
    });
  • 把数据转换为数值类型 – 只能自己每次转换为数值,理论上行的通,就是繁琐
使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏