当前位置:网站首页>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 .
边栏推荐
- Jerry's ad series MIDI function description [chapter]
- Jerry's ad series MIDI function description [chapter]
- 哈希表(Hash Tabel)
- [early knowledge of activities] list of recent activities of livevideostack
- Super detailed tutorial, an introduction to istio Architecture Principle and practical application
- redis03——Redis的网络配置与心跳机制
- Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
- EhLib 数据库记录的下拉选择
- 2021 CCPC Harbin B. magical subsequence (thinking question)
- Bookmark
猜你喜欢
VS2019 C# release下断点调试
Maya lamp modeling
Methods of improving machine vision system
TCP协议三次握手过程
Shutter textfield example
El tree combined with El table, tree adding and modifying operations
QT—双缓冲绘图
Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
SolidWorks工程图添加材料明细表的操作
做BI开发,为什么一定要熟悉行业和企业业务?
随机推荐
Redis has three methods for checking big keys, which are necessary for optimization
如何借助自动化工具落地DevOps
Shutter textfield example
MongoDB聚合操作总结
[leetcode] 17. Letter combination of telephone number
How much is the minimum stock account opening commission? Is it safe to open an account online
ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
Jerry added the process of turning off the touch module before turning it off [chapter]
Redis03 - network configuration and heartbeat mechanism of redis
2021 CCPC Harbin I. power and zero (binary + thinking)
vim 从嫌弃到依赖(23)——最后的闲扯
Numpy vstack and column_ stack
Flutter WebView示例
[early knowledge of activities] list of recent activities of livevideostack
开户哪家券商比较好?网上开户安全吗
At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held
QT - plot other problems
Redis 排查大 key 的3种方法,优化必备
一文掌握数仓中auto analyze的使用
Solve the problem of data disorder caused by slow asynchronous interface