Comments (14)
使用什么版本的 F2?
from wx-f2.
@simaQ 您好,我是直接在https://github.com/antvis/wx-f2.git clone下去的最新
from wx-f2.
那请你贴下源码吧
from wx-f2.
好的 稍等
from wx-f2.
创建 chart 的时候需要声明 width 和 height,看这个报错应该是没有声明或者宽高没有读取到
from wx-f2.
我看了下报错位置 是在这个位置报错的,我就怕是 生命周期的问题 document没有
getStyle: function getStyle(el, property) {
return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
},
from wx-f2.
恩,我知道,我在图表组件里面是查找到 canvas 组件之后,才读取 width 和 height 的,https://github.com/antvis/wx-f2/blob/master/f2-canvas/f2-canvas.js#L89,
所以你看下是不是你写代码的时候漏了声明 width 和 height, https://github.com/antvis/wx-f2/blob/master/pages/charts/column/index.js#L16。
如果你担心生命周期的问题,你自己处理下就行了。或者声明 lazyLoad: true, 参考这个例子,延迟加载:
https://github.com/antvis/wx-f2/blob/master/pages/charts/k/index.js#L14
https://github.com/antvis/wx-f2/blob/master/pages/charts/k/index.js#L26
https://github.com/antvis/wx-f2/blob/master/pages/charts/k/index.js#L27
from wx-f2.
组件代码(路径我做了一点调整):
import F2 from '../../../f2-canvas/lib/f2';
let chart = null;
function initChart(canvas, width, height) { // 使用 F2 绘制图表
// const data = [
// { year: '1956', sales: [34,42] },
// { year: '1957', sales: 43 },
// { year: '1958', sales: 48 },
// { year: '1959', sales: 54 },
// { year: '1960', sales: 75 },
// { year: '1962', sales: 170 },
// ];
const data = [{
name: 'London',
月份: 'Jan.',
月均降雨量: 18.9
}, {
name: 'London',
月份: 'Feb.',
月均降雨量: 28.8
}, {
name: 'London',
月份: 'Mar.',
月均降雨量: 39.3
}, {
name: 'Berlin',
月份: 'Jan.',
月均降雨量: 99.7
}, {
name: 'Berlin',
月份: 'Feb.',
月均降雨量: 52.6
}, {
name: 'Berlin',
月份: 'Mar.',
月均降雨量: 35.5
}];
chart = new F2.Chart({
el: canvas,
width,
height
});
chart.source(data);
// chart.source(data, {
// value: {
// tickCount: 5
// }
// });
chart.tooltip({
showItemMarker: false,
onShow(ev) {
const { items } = ev;
items[0].name = null;
items[0].name = items[0].title;
items[0].value = '¥ ' + items[0].value;
}
});
//chart.interval().position('year*sales');
chart.interval().position('月份*月均降雨量').color('name').adjust({
type: 'dodge',
marginRatio: 0.05 // 设置分组间柱子的间距
});
chart.render();
return chart;
}
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
items: [1, 2, 3, 4, 5],
opts: {
onInit: initChart
}
},
/**
* 组件的方法列表
*/
methods: {
}
})
组件json
{
"component": true,
"usingComponents": {
"ff-canvas": "/../../../f2-canvas/f2-canvas"
}
}
组件wxml
<view class="container">
<block wx:key='id' wx:for='0'>
<ff-canvas class='aa' height='220px' width='123px' canvas-id="column" opts="{{ opts }}"></ff-canvas>
<view class='split'>测试一下</view>
</block>
</view>
引用json (位置做了调整)
{
"usingComponents": {
"x-column": "/components/charts/x-column/index"
}
}
**引用wxml **
<view class="item">
<x-column></x-column>
</view>
from wx-f2.
你是自己又封装了一个组件了吧?那这样吧,你调试下是不是组件 init 的时候 width 和 height 没有拿到,关键代码在这里:
https://github.com/antvis/wx-f2/blob/master/f2-canvas/f2-canvas.js#L93
这个报错原因就是因为 width 和 height 为空导致的。微信小程序的组件生命周期我也不是特别熟...
from wx-f2.
是的 我是在上面又封装了一层 ;我跟踪了下 在以下代码处的输出宽高都是有的...
query.select('.f2-canvas').boundingClientRect(res => {
console.log(canvas);
console.log(res);
if (typeof callback === 'function') {
this.chart = callback(canvas, res.width, res.height);
} else if (this.data.opts && this.data.opts.onInit) {
this.chart = this.data.opts.onInit(canvas, res.width, res.height);
}
}).exec();
},
bottom
:
493
dataset
:
{}
height
:
0
id
:
""
left
:
31
right
:
383
top
:
493
width
:
352
from wx-f2.
height 是 0 哦。。。
那你试着给 canvas 组件加下样式看下,参考:https://github.com/antvis/wx-f2/blob/master/app.wxss#L16
from wx-f2.
哈哈 老眼昏花 。。 不过给了还是不行...
谢谢你帮我回答这么多,我自己再看一下,万分感谢!
ps:如果你有时间你在上面也封装一个 看看能不能重现吧 。。哈哈
from wx-f2.
我试了一下,是可以的呢,基于你贴出代码的基础上,添加了 x-column.wxss 文件
- 基于 ff-canvas 自定义组件:https://github.com/antvis/wx-f2/tree/custom-components/pages/charts/x-column
- 使用:https://github.com/antvis/wx-f2/tree/custom-components/pages/charts/test
from wx-f2.
@simaQ 感谢感谢!只要在container样式中加一个position: absolute; 就好了 ,你去掉的话就报错...
from wx-f2.
Related Issues (20)
- 导入工具提示: app.json 未找到
- taro微信小程序引入f2后,报错了 HOT 4
- 跪求大佬支持remax!!!! HOT 1
- 请问可以提供一个小demo吗 HOT 2
- edit HOT 1
- IOS下不显示 折线图平移图表
- 小程序交互的demo
- 【iOS】横屏-位置识别有问题 点击对应的柱状图-柱子并不会显示对应的tooltip
- 按照官方demo在小程序中雷达图不展示 HOT 1
- 微信小程序上可以画点的时候可以替换为图片吗,我看包里面方法没有提供image和icon类型的key HOT 2
- 异步请求后,渲染到图表上 HOT 1
- 小程序版怎么手动加载呢?
- Hello, how can I solve the problem of chart.pieLabel is not a function when the pie chart reports an error? 你好,请问饼图报错 chart.pieLabel is not a function 怎么解决呢? HOT 8
- tooltip 在ios和android真机小程序上表现不一样 HOT 1
- dont support performanceObserver tepy = paint
- 请统一到 https://github.com/antvis/F2/issues 提交问题和反馈,谢谢
- 在小程序中无法使用 HOT 4
- 折线图部分虚线是不是做不了啊,没有view()实例
- wx-f2 文档链接失效 HOT 1
- taro 微信小程序使用antv f2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wx-f2.