G2( bizCharts ) React 绘制混合图例
G2( bizCharts ) React 绘制混合图例,
// data-set 可以按需引入,除此之外不要引入别的包
import React from 'react';
import { Chart, Axis, Tooltip, Geom, Legend, Label } from 'bizcharts';
import DataSet from '@antv/data-set'; // 下面的代码会被作为 cdn script 注入 注释勿删
// CDN START
const data = [
{ label: '0.1', 放款应还本金: 2800, 价格: 2800, 收益: 2260, 总收益率: 2 },
{ label: '0.2', 放款应还本金: 1800, 价格: 1800, 收益: 1300, 总收益率: 3 },
{ label: '0.3', 放款应还本金: 950, 价格: 950, 收益: 900, 总收益率: 5 },
{ label: '0.4', 放款应还本金: 500, 价格: 500, 收益: -390, 总收益率: 1 },
{ label: '0.5', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
{ label: '0.6', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
{ label: '0.7', 放款应还本金: 170, 价格: 170, 收益: -100, 总收益率: 3 },
{ label: '0.8', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
{ label: '0.9', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
{ label: '1.0', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
{ label: '未评分', 放款应还本金: 170, 价格: 170, 收益: 100, 总收益率: 3 },
];
const ds = new DataSet();
const dv = ds.createView().source(data);
dv.transform({
type: 'fold',
fields: ['放款应还本金', '价格', '收益'], // 展开字段集
key: 'type', // key字段
value: 'value', // value字段
});
const scale = {
总收益率: {
type: 'linear',
min: 0,
max: 10,
},
}; let chartIns = null; const getG2Instance = chart => {
chartIns = chart;
};
console.log(getG2Instance, 'getG2Instance');
class Demo extends React.Component {
render() {
return (
<Chart
height={400}
width={500}
forceFit
data={dv}
scale={scale}
padding="auto"
onGetG2Instance={getG2Instance}
>
<Legend
custom
allowAllCanceled
items={[
{
value: '放款应还本金',
marker: { symbol: 'square', fill: '#3182bd', radius: 5 },
},
{
value: '价格',
marker: { symbol: 'square', fill: '#41a2fc', radius: 5 },
},
{
value: '收益',
marker: { symbol: 'square', fill: '#54ca76', radius: 5 },
},
{
value: '总收益率',
marker: {
symbol: 'hyphen',
stroke: '#fad248',
radius: 5,
lineWidth: 3,
},
},
]}
onClick={ev => {
const item = ev.item;
const value = item.value;
const checked = ev.checked;
const geoms = chartIns.getAllGeoms();
console.log('geoms', geoms);
for (let i = 0; i < geoms.length; i++) {
const geom = geoms[i];
if (geom.getYScale().field === value && value === '总收益率') {
if (checked) {
geom.show();
} else {
geom.hide();
}
} else if (
geom.getYScale().field === 'value' &&
value !== '总收益率'
) {
geom.getShapes().map(shape => {
if (shape._cfg.origin._origin.type == value) {
shape._cfg.visible = !shape._cfg.visible;
}
shape.get('canvas').draw();
return shape;
});
} const g_shapes = geom.get('labelContainer');
let labels = g_shapes._cfg.labelsGroup._cfg.children;
labels.map(label => {
if (checked) {
if (label._id.includes(value)) {
label._cfg.visible = true;
}
} else {
if (label._id.includes(value)) {
label._cfg.visible = false;
}
}
});
}
}}
/>
<Axis name="label" />
<Axis name="value" position={'left'} />
<Tooltip />
<Geom
type="interval"
position="label*value"
color={[
'type',
value => {
if (value === '放款应还本金') {
return '#2b6cbb';
}
if (value === '价格') {
return '#41a2fc';
}
if (value === '收益') {
return '#54ca76';
}
},
]}
adjust={[
{
type: 'dodge',
marginRatio: 1 / 32,
},
]}
>
<Label content="value" />
</Geom>
<Geom type="line" position="label*总收益率" color="#fad248" size={3}>
<Label content="label" />
</Geom>
</Chart>
);
}
} // CDN END
ReactDOM.render(<Demo />, mountNode);

G2( bizCharts ) React 绘制混合图例的更多相关文章
- G2 绘制混合图例 demo
G2 绘制混合图例 demo import G2 from '@antv/g2'; import DataSet from '@antv/data-set'; // G2 对数据源格式的要求,仅仅是 ...
- react+echarts/g2/bizcharts可视化图表
一.echarts的折线图的使用demo如下,linecharts为实例化的封装组件,line为实际应用的组件 cnpm install echarts import React from 'reac ...
- React Native 混合开发与实现
关于 微信公众号:前端呼啦圈(Love-FED) 我的博客:劳卜的博客 知乎专栏:前端呼啦圈 前言 随着 React 的盛行,其移动开发框架 React Native 也收到了广大开发者的青睐,以下简 ...
- 你不可不知的 React Native 混合用法(Android 篇)
前言 当前 React Native 虽说版本更新比较快,各种组件也提供的很全面了,但是在某些情况下,混合开发的方式才会快速缩短开发周期,原因无非就是原生平台的"底蕴"无疑更深,拥 ...
- 【Qt编程】基于QWT的曲线绘制及图例显示操作
在<QWT在QtCreator中的安装与使用>一文中,我们完成了QWT的安装,这篇文章我们讲讲基础曲线的绘制功能. 首先,我们新建一个Qt应用程序,然后一路默认即可.这时,你会发现总共有: ...
- 《React Native 精解与实战》书籍连载「Android 平台与 React Native 混合开发」
此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...
- 《React Native 精解与实战》书籍连载「iOS 平台与 React Native 混合开发」
此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...
- 【Qt编程】基于QWT的曲线绘制及图例显示操作——有样点的实现功能
在<QWT在QtCreator中的安装与使用>一文中,我们完成了QWT的安装,这篇文章我们讲讲基础曲线的绘制功能. 首先,我们新建一个Qt应用程序,然后一路默认即可.这时,你会发现总共有: ...
- React Native混合开发中必须要学会点FlexBox布局
在前面的案例中,界面的搭建都是采用CSS的布局,基于盒子模型,依赖 display属性 , position属性, float属性.但对于那些特殊布局非常不方便,比如,垂直居中. 一种全新的针对web ...
随机推荐
- Android Studio 使用本地gradle配置详解
由于国内墙的原因,我们的Gradle无法使用 但是我们可以通过去下载我们想要的Gradle版本 然后再AndoidStudio内去配置本地的版本 进而去实现了Gradle的配置 注意一: so我们按照 ...
- Bupt归队赛, gunfight
只需要关心是否开枪,上个人和当前这个人的位置关系,转移可以前缀和优化 为了不重复,始终认为第一个就是1,最后答案乘以n #include<bits/stdc++.h> using name ...
- string转数组, 数组转ist, list转数组, 数组转string
private string OrderBonds(string bonds) { string[] lists = bonds.Split(','); List<string> newL ...
- 不安全的HTTP方法(渗透实验)
1.使用 curl -v -X OPTIONS url(含目录) 获取允许访问的http method 例如:curl -v -X OPTIONS http://192.168.1.123:12123 ...
- tensorFlow(三)逻辑回归
tensorFlow 基础见前博客 逻辑回归广泛应用在各类分类,回归任务中.本实验介绍逻辑回归在 TensorFlow 上的实现 理论知识回顾 逻辑回归的主要公式罗列如下: 激活函数(activati ...
- Binary Tree Path Sum
Given a binary tree, find all paths that sum of the nodes in the path equals to a given number targe ...
- ChinaCock界面控件介绍-TCCBarcodeCreator
条码生成器,可以生成各种条码,包括二维码.这是一个不可视控件.用起来依旧简单. 属性说明: BarCodeColor:生成条码的颜色 BarcodeFormat:生成条码的类型,支持的条码类型: Bo ...
- offsetWidth与clientWidth 区别
offsetWidth //元素宽度.内边距和边框,不包括外边距 offsetHeight //元素高度.内边距和边框,不包括外边距 clientWidth //元 ...
- 给a链接跳转后的页面添加class
$(document).ready(function(){ var test = window.location.href;//获取到当前页面的href // console.log(test); / ...
- 自动化测试-10.selenium的iframe与Frame
前言 有很多小伙伴在拿163作为登录案例的时候,发现不管怎么定位都无法定位到,到底是什么鬼呢,本篇详细介绍iframe相关的切换 以http://mail.163.com/登录页面10为案例,详细介绍 ...