一.echarts的折线图的使用demo如下,linecharts为实例化的封装组件,line为实际应用的组件

cnpm install echarts
import React from 'react';
import './lineCharts.less';
let echarts = require('echarts'); /**
* 组件参数配置
*
* @param {string} id
* id = 每个图标的标识
* @param {array} color
* color = 多组数据的颜色区分,第一组数据为第一种颜色
* @param { } legendShow
* legendShow 是否显示默认标注,右上角颜色对应块
* @param {string} legendTextStyle
* legendTextStyle = 折线图标注的文字颜色
* @param { } noPercent
* noPercent 折线图不是以百分比来显示
* @param { array } xAxis
* xAxis": ["翡翠城西南区", "盛世嘉园","西溪北苑"],
* @param { array } yAxis
* "yAxis": [
{
"data": [100,200,300],
"name": "水费",
"stack": "1",
"type": "line",
},
{
"data": [100,200,300],
"name": "物业管理费",
"stack": "1",
"type": "line",
},
{
"data": [100,200,300],
"name": "燃气费",
"stack": "1",
"type": "line",
}
]
*
*/ let colors = ['#f27573', '#69757a', '#ffd553', '#51b8ae', '#ff8d69', '#a48b82', '#dde779', '#7d89cd', '#cacaca', '#51d1e1', '#f06695', '#fff179', '#8ca8f9', '#c9b185', '#9e5c81']; class lineCharts extends React.Component {
constructor(props) {
super(props);
this.state = {};
} componentDidMount() {
let { id, xAxis, yAxis } = this.props;
let myChart = echarts.init(document.getElementById(id));
myChart.setOption({
color: this.props.color ? this.props.color : colors,
title: {
left: "center",
},
legend: {
orient: 'vertical',
left: 'right',
show: this.props.legendShow ? true : false,
textStyle: {
color: this.props.legendTextStyle ? this.props.legendTextStyle : '#000',
fontSize: 12
}
},
tooltip: {
trigger: 'axis',
formatter: this.props.noPercent ? '' : '{b0}<br />{a0}: {c0}%<br />{a1}: {c1}%'
},
grid: {
left: '20%',
right: '20%',
bottom: '3%',
top:'30%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: xAxis,
"axisLabel": {
interval: this.props.intervalNum ? this.props.intervalNum : 0,
rotate: 7
},
axisLine: {
lineStyle: {
color: this.props.lineColor ? this.props.lineColor : '#000',
}
},
},
yAxis: {
type: 'value',
minInterval: 1,
boundaryGap: [0, 0.1],
axisLabel: {
formatter: this.props.noPercent ? '{value}' : '{value} %',
},
axisLine: {
lineStyle: {
color: this.props.lineColor ? this.props.lineColor : '#000',
}
},
precision: 0,
// min: 1,
max: this.props.maxSize && this.props.maxSize <= 10 ? 10 : null,
},
series: yAxis
})
} render() {
return (
<div id={this.props.id} className="charts"> </div>
);
} } export default lineCharts;
import React, { Component } from 'react'
import { Button } from 'antd';
import LineCharts from "./lineCharts";
import './lineCharts.less'; class Line extends Component { render() {
const data = {
"xAxis": ["翡翠城西南区", "盛世嘉园","西溪北苑"],
"yAxis": [
{
"data": [100,200,300],
"name": "水费",
"stack": "1",
"type": "line",
"areaStyle": {}
},
{
"data": [100,200,300],
"name": "物业管理费",
"stack": "2",
"type": "line",
"areaStyle":{}
},
{
"data": [100,200,300],
"name": "燃气费",
"stack": "3",
"type": "line",
"areaStyle":{}
}
]
}
return (
<div className="root">
<Button className="big">这是一个按钮</Button>
<LineCharts id="lineCharts-1" color={['#f38747', '#f7dc3e', '#6ed66d']} legendShow legendTextStyle="#5d71a2" noPercent maxSize={100} lineColor="#5d71a2" xAxis={data.xAxis} yAxis={data.yAxis} />
</div>
);
}
} export default Line

二.g2的使用以如下柱状图为例

cnpm install @antv/g2
import React from 'react';
import G2 from '@antv/g2'; class g2 extends React.Component {
constructor(props) {
super(props);
this.state = {
data :[
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 }
]
};
} componentDidMount() {
const chart = new G2.Chart({
container: 'c1', // 指定图表容器 ID
width: 600, // 指定图表宽度
height: 300 // 指定图表高度
});
chart.source(this.state.data);
chart.interval().position('genre*sold').color('genre');
chart.render();
}
render() {
return (
<div id="c1" className="charts"> </div>
);
} } export default g2;

三:bizcharts:基于g2的封装版本,去除实例化图表的步骤,更多的关注于各字段的控制,以下两个demo分别为折线图,扇形图

cnpm install bizcharts;
cnpm install @antv/data-set;//扇形图时要安装改依赖
import React from 'react';
import ReactDOM from 'react-dom';
import { Chart, Geom, Axis, Tooltip, Legend, Coord } from 'bizcharts'; class bizcharts extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{ genre: 'Sports', sold: 275, income: 2300 },
{ genre: 'Strategy', sold: 115, income: 667 },
{ genre: 'Action', sold: 120, income: 982 },
{ genre: 'Shooter', sold: 350, income: 5271 },
{ genre: 'Other', sold: 150, income: 3710 }
],
};
} render() {
return (
<div>
<Chart width={600} height={200} padding={[60,'auto','auto',160]} data={this.state.data} >
<Axis name="genre" />
<Legend position="bottom"/>
<Tooltip />
<Geom type="line" position="genre*sold" size={2} />
<Geom type='point' position="genre*sold" size={4} shape={'circle'} style={{ stroke: '#fff', lineWidth: 1 }} />
</Chart>
</div>
);
} } export default bizcharts;
import React from 'react';
import ReactDOM from 'react-dom';
import { Chart, Geom, Axis, Tooltip, Legend, Coord, Label } from 'bizcharts';
import DataSet from '@antv/data-set';//cnpm install @antv/data-set
const { DataView } = DataSet;
const dv = new DataView(); class bizcharts extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{ item: '事例一', count: 40 },
{ item: '事例二', count: 21 },
{ item: '事例三', count: 17 },
{ item: '事例四', count: 13 },
{ item: '事例五', count: 9 }
],
};
} render() {
dv.source(this.state.data).transform({
type: 'percent',
field: 'count',
dimension: 'item',
as: 'percent',
});
const cols = {
percent: {
formatter: val => {
val = (val * 100) + '%';
return val;
}
}
}
return (
<div>
<Chart height={window.innerHeight} data={dv} scale={cols} padding={[80, 100, 80, 80]} forceFit>
<Coord type='theta' radius={0.75} />
<Axis name="percent" />
<Legend position='right' offsetY={-window.innerHeight / 2 + 120} offsetX={-100} />
<Tooltip
showTitle={false}
itemTpl='<li><span style="" class="g2-tooltip-marker"></span>{name}: {value}</li>'
/>
<Geom
type="intervalStack"
position="percent"
color='item'
tooltip={['item*percent', (item, percent) => {
percent = percent * 100 + '%';
return {
name: item,
value: percent
};
}]}
style={{ lineWidth: 1, stroke: '#fff' }}
>
<Label content='percent' formatter={(val, item) => {
return item.point.item + ': ' + val;
}} />
</Geom>
</Chart>
</div>
);
} } export default bizcharts;

react+echarts/g2/bizcharts可视化图表的更多相关文章

  1. 三大图表库:ECharts 、 BizCharts 和 G2,该如何选择?

    最近阿里正式开源的BizCharts图表库基于React技术栈,各个图表项皆采用了组件的形式,贴近React的使用特点.同时BizCharts基于G2进行封装,Bizcharts也继承了G2相关特性. ...

  2. Webstorm+Webpack+echarts构建个性化定制的数据可视化图表&&两个echarts详细教程(柱状图,南丁格尔图)

    Webstorm+Webpack+echarts   ECharts 特性介绍 ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(I ...

  3. JFreeChart与AJAX+JSON+ECharts两种处理方式生成热词统计可视化图表

    本篇的思想:对HDFS获取的数据进行两种不同的可视化图表处理方式.第一种JFreeChar可视化处理生成图片文件查看.第二种AJAX+JSON+ECharts实现可视化图表,并呈现于浏览器上.   对 ...

  4. G2( bizCharts ) React 绘制混合图例

    G2( bizCharts ) React 绘制混合图例, // data-set 可以按需引入,除此之外不要引入别的包 import React from 'react'; import { Cha ...

  5. vue可视化图表 基于Echarts封装好的v-charts简介

    **vue可视化图表 基于Echarts封装好的v-charts** 近期公司又一个新的需求,要做一个订单和销售额统计的项目,需要用到可视化图表来更直观的展示数据.首先我想到的是Echarts,众所周 ...

  6. 数据可视化图表ECharts

    介绍: ECharts是一个基于ZRender(轻量级Canvas类库)的纯javascript图表库,提供可交互.个性化的数据可视化图表. ECharts提供了折线图.柱状图.散点图.饼图.K线图, ...

  7. ECharts-基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表

    ECharts http://ecomfe.github.com/echarts 基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表.创新的拖拽重计算 ...

  8. echarts.js--前端可视化数据图形

    ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上, 兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等 ...

  9. ECharts JS应用:图表页面实现

    因为要统计数据进行图表展示,所以就简单学习了 ECharts JS 的应用.它是一个纯Javascript图库,它依赖于一个轻量级的Canvas库 ZRender,并提供直观.生动.交互式和高度可定制 ...

随机推荐

  1. [Angular] Two things about OnChanges Lifecycle hook

    1. ngOnChanges is called before ngOnInit but after constructor() 2. ngOnChanges is called because of ...

  2. ListView改变字体

    ListView中没有改变字体的属性和方法,所以需要用其他的方式.这里使用ArrayAdapter.   首先,创建一个TextView组件,用来作为Adapter的列表项组件.   在layout文 ...

  3. java写的小脚本,用来受mDNS消息

    太ugly了,但是可以工作,抓了包下来,用前面DNS message structure做了下比较. 代码如下: import java.net.DatagramPacket; import java ...

  4. 03-hibernate注解-关系映射级别注解-一对一

    实体之间的映射关系 一对一:一个公民对应一个身份证号码 一对多(多对一):一个人可以有多个银行账号 多对多:一个学生有多个老师,一个老师有多个学生. 一对一单向外键关联 @OneToOne(casca ...

  5. MySQL外键的设置及作用

    原文地址:http://www.php100.com/html/webkaifa/database/Mysql/2010/0830/5342.html 外键的作用: 保持数据一致性,完整性,主要目的是 ...

  6. 【Shiro】Apache Shiro架构之权限认证(Authorization)

    Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shir ...

  7. Image.Save出错 GDI 一般错误

    一般是路径问题 需要转化为绝对路径 \转换为/ if (HttpContext.Current!=null) outPath = HttpContext.Current.Server.MapPath( ...

  8. C# 异或校验算法

    C# 的异或校验算法 直接上代码 public partial class FormCRC : Form { public FormCRC() { InitializeComponent(); } p ...

  9. Spring学习笔记(四)-- Spring事务全面分析

    通过本系列的文章对Spring的介绍,我们对Spring的使用和两个核心功能IOC.AOP已经有了初步的了解,结合我个人工作的情况,因为项目是金融系 统.那对事务的控制是不可缺少的.而且是很严格的控制 ...

  10. Yii Framework2.0开发教程(3)数据库mysql入门

    沿用教程(2)的代码 第一步.在本地mysql数据库中新建数据库zhyoulun 第二步.在数据库中新建表并插入若干条数据 CREATE TABLE `country` ( `code` CHAR(2 ...