当前位置:网站首页>Bizchart+slider to realize grouping histogram
Bizchart+slider to realize grouping histogram
2022-07-04 21:52:00 【Understanding the initial state】
Use bizchart Achieve grouping histogram , With slider selection . The renderings are as follows :
Environmental Science
be based on bizchart3.x
npm install [email protected]
npm install [email protected]
Chart-Slider Component encapsulation
Chart and Slider yes 2 A component , For ease of use , We are encapsulated together , Return with a function .
import DataSet from '@antv/data-set';
import {
Axis, Chart, Geom, Legend, Tooltip } from "bizcharts";
import Slider from "bizcharts-plugin-slider";
import React, {
Component } from 'react';
function getGroupChartWithSliderComponent(data) {
const ds = new DataSet({
state: {
start: data[0] ? data[0].timestamp : '',
end: data[0] ? data[data.length - 1].timestamp : '$'
}
});
const dv = ds.createView('origin').source(data);
dv.transform({
type: 'filter',
callback(item) {
const r = item.timestamp;
return r >= ds.state.start && r <= ds.state.end;
}
});
class GroupChartWithSlider extends React.Component {
handleTimeSliderChange(e) {
const {
startValue, endValue } = e;
ds.setState('start', startValue);
ds.setState('end', endValue);
}
render() {
const chartScale = {
'timestamp': {
alias: ' Time '
},
'count': {
alias: ' frequency '
}
};
return (
<div>
<Chart height={
200} data={
dv} forceFit padding='auto' scale={
chartScale}>
<Legend position="top-center" />
<Axis name="timestamp" />
<Axis name="count" />
<Tooltip />
<Geom
type="interval"
position="timestamp*count"
color={
["tag"]}
// color={["tag", ["#f5222d", "#ec6740", "#ffa39e"]]}
adjust={
[
{
type: "dodge",
marginRatio: 1 / 32
}]}
style={
{
stroke: "#fff",
lineWidth: 1
}}
/>
</Chart>
<Slider data={
data} padding={
10} xAxis="timestamp" yAxis="count"
scales={
{
// Do not display text
timestamp: {
formatter: () => ''
}
}}
onChange={
this.handleTimeSliderChange.bind(this)} />
</div>
);
}
}
return GroupChartWithSlider;
}
Use
To generate a grouping histogram , Just the same one X There are multiple values for the axis Y value , below X The axis is timestamp
, Y The axis is count
.
class MyApp extends Component {
state = {
// Aggregate group histogram data
groupErrorData: [/* { "timestamp": '2022-6-22T11:43', "count": 15, "tag": " egg ", }, { "timestamp": '2022-6-22T11:43', "count": 3, "tag": " Banana ", }, { "timestamp": '2022-6-22T11:43', "count": 19, "tag": " pumpkin ", }, { "timestamp": '2022-6-22T11:43', "count": 5, "tag": " Southwest flower ", }, { "timestamp": '2022-6-22T11:45', "count": 6, "tag": " Wax gourd ", }, { "timestamp": '2022-6-22T11:45', "count": 20, "tag": " celery ", }], }; render() { const GroupChartWithSlider = getGroupChartWithSliderComponent(this.state.groupErrorData); return ( <div> <GroupChartWithSlider /> </div > ); } } export default MyApp;
Slider effect
Slider You can drag , Show the trend of the data .
边栏推荐
- new IntersectionObserver 使用笔记
- Jerry's ad series MIDI function description [chapter]
- 解读创客教育中的各类智能化组织发展
- Minidom module writes and parses XML
- [public class preview]: basis and practice of video quality evaluation
- Master the use of auto analyze in data warehouse
- Le module minidom écrit et analyse XML
- el-tree结合el-table,树形添加修改操作
- TCP协议三次握手过程
- 巅峰不止,继续奋斗!城链科技数字峰会于重庆隆重举行
猜你喜欢
[optimtool.unconstrained] unconstrained optimization toolbox
【LeetCode】17、电话号码的字母组合
gtest从一无所知到熟练使用(3)什么是test suite和test case
el-tree结合el-table,树形添加修改操作
[weekly translation go] how to code in go series articles are online!!
开源之夏专访|Apache IoTDB社区 新晋Committer谢其骏
TCP三次握手,四次挥手,你真的了解吗?
Bookmark
Daily question -leetcode1200- minimum absolute difference - array - sort
【微信小程序】协同工作与发布
随机推荐
gtest从一无所知到熟练使用(3)什么是test suite和test case
Lambdaquerywrapper usage
Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
什么是商业智能(BI),就看这篇文章足够了
[early knowledge of activities] list of recent activities of livevideostack
输入的查询SQL语句,是如何执行的?
How to use concurrentlinkedqueue as a cache queue
解析互联网时代的创客教育技术
redis RDB AOF
Jerry's ad series MIDI function description [chapter]
Redis03 - network configuration and heartbeat mechanism of redis
How is the entered query SQL statement executed?
MP3是如何诞生的?
How to implement Devops with automatic tools
Open3D 曲面法向量计算
2021 CCPC Harbin B. magical subsequence (thinking question)
Three or two things about the actual combat of OMS system
Case sharing | integrated construction of data operation and maintenance in the financial industry
OMS系统实战的三两事
Application practice | Shuhai supply chain construction of data center based on Apache Doris