-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs: 新增「热力图」文档 #6950
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
docs: 新增「热力图」文档 #6950
Conversation
Pull Request Test Coverage Report for Build 15323906186Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
site/docs/charts/heatmap.zh.md
Outdated
|
||
例 3: **适合展示用户交互行为热区** | ||
|
||
下面这个例子展示了用户在界面上的鼠标移动轨迹热力图,用于分析用户的关注热区。(此示例仅作展示说明,实际运行需要用户交互) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eomnational 这里的data有问题,playground转换api调用为spec是通过返回内部运行时的配置得来的,这地方的data应该是已经交互过的,正确的代码如下:
import { Chart } from '@antv/g2';
import { throttle } from 'lodash';
const data = {};
const chart = new Chart({
container: 'container',
width: 640,
height: 480,
padding: 0,
});
chart.data([]);
chart.options({
type: "view",
style: { viewFill: "#4e79a7" },
axis: false,
children: [
{
type: "heatmap",
data: [],
encode: { x: "x", y: "y", color: "v" },
scale: {
x: { domain: [0, 640] },
y: { domain: [0, 480], range: [0, 1] },
},
style: { opacity: 0 },
animate: false,
tooltip: false,
},
],
});
chart.render();
chart.on(
'plot:pointermove',
throttle((e) => {
const { x, y } = e;
const kx = Math.floor(x - (x % 8));
const ky = Math.floor(y - (y % 8));
if (!data[kx]) data[kx] = {};
if (!data[kx][ky]) data[kx][ky] = 0;
data[kx][ky] += 1;
const d = transform(data);
chart.changeData(d);
}),
);
function transform(dataMap) {
const arr = [];
Object.keys(dataMap).forEach((x) => {
Object.keys(dataMap[x]).forEach((y) => {
arr.push({ x, y, v: dataMap[x][y] });
});
});
return arr;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这个代码试过了,还是没用。不知道为啥
感谢您的贡献 🎉 |
@interstellarmt 已修改 |
Uh oh!
There was an error while loading. Please reload this page.