如何在react项目中使用G2Plot?
hello, 如题,请问如何在react项目中使用g2plot?
我要想问这个问题。。
G2Plot的react封装版本会以Ant Design Chart的方式呈现,敬请期待~
同问?
@xiaodu527 @xgj1988 @kaoding G2Plot 项目本身是不感知用户使用 React 还是 Vue 技术栈的,在 React 环境中封装一层 G2Plot 包装,应该难不倒大家。
欢迎大家开源各种 G2Plot 的 react 周边项目,可以参考 echarts-for-react,当然也敬请期待 在 Ant Design 体系下的官方呈现 ^_^
最简单的方式:
import React, { useRef, useEffect } from 'react';
import { Bar } from '@antv/g2plot';
const App = () => {
const data = [
{ year: '1951 年', sales: 38 },
{ year: '1952 年', sales: 52 },
{ year: '1956 年', sales: 61 },
{ year: '1957 年', sales: 145 },
{ year: '1958 年', sales: 48 },
];
const container = useRef(null);
useEffect(() => {
if (!container.current) {
return;
}
const bar = new Bar(container.current, {
data,
xField: 'sales',
yField: 'year',
colorField: 'year',
});
bar.render();
}, []);
return (
<div>
<div ref={container} />
</div>
);
};
@hustcc 难是不难,关键是我npm 装不上。yarn 也不行。 。项目重新删了。重新 npm install 和 yarn 都不行
@hustcc 难是不难,关键是我npm 装不上。yarn 也不行。 。项目重新删了。重新 npm install 和 yarn 都不行
有报什么错误码?来来点具体的信息~
#325 @hustcc 看看这个
没有index.js,暂时只能这样import { Ring } from '@antv/g2plot/esm'

@zlab 谢谢。
和bizcharts有什么区别?
chart.tooltip({
useHtml: true,
htmlContent: function(title, items) {
return '<div><ul><li>.....</li></ul></div>';
},
});
htmlContent不支持ReactNode,太恶心了,回到了拼接html的时代
itemTpl: '<li data-index={index}>' +
'<span style="background-color:{color};width:8px;height:8px;border-radius:50%;display:inline-block;margin-right:8px;"></span>' +
'{name}<span class="g2-tooltip-value">{value}</span>' +
'</li>';
看的头疼
请问下如何刷新图表数据呢,暂时没有找到刷新数据的接口呢
最简单的方式:
import React, { useRef, useEffect } from 'react'; import { Bar } from '@antv/g2plot'; const App = () => { const data = [ { year: '1951 年', sales: 38 }, { year: '1952 年', sales: 52 }, { year: '1956 年', sales: 61 }, { year: '1957 年', sales: 145 }, { year: '1958 年', sales: 48 }, ]; const container = useRef(null); useEffect(() => { if (!container.current) { return; } const bar = new Bar(container.current, { data, xField: 'sales', yField: 'year', colorField: 'year', }); bar.render(); }, []); return ( <div> <div ref={container} /> </div> ); };
@afc163 请问一下
if (!container.current) {
return;
}
这段代码是否是多余的(因为我删除了一下试了试好像也能用,这个useEffect 第二个参数为空数组不是只会执行一次吗?) 再请问一下useEffect第一次执行是否对应class组件生命周期中的componentDidMount?
请问下如何刷新图表数据呢,暂时没有找到刷新数据的接口呢
chart.updateConfig({ data: newData });
请问下如何刷新图表数据呢,暂时没有找到刷新数据的接口呢
chart.updateConfig({ data: newData });
好的,我试下,谢谢
请问下如何刷新图表数据呢,暂时没有找到刷新数据的接口呢
chart.updateConfig({ data: newData });好的,我试下,谢谢

当成js就可以在vue,react,或者其他语言环境中使用

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Ant Design Charts 已经发布了:https://charts.ant.design/