reactjs - 反应图表“堆叠:真”不起作用
问题描述
我使用react-charts
, 在 ReactJS 中创建了一个带有多个条形的图表。
这是我的组件:
import React, { Component } from "react";
import { Chart } from "react-charts";
import axios from "axios";
const qs = require("qs");
class Volume extends Component {
state = {
load_vol_chart: true,
volume_chart_data: []
};
componentDidMount() {
this.getVolumeChartData();
}
getVolumeChartData() {
var name = this.props.name;
axios
.post(
`http://api.mydomain.in/details/`,
qs.stringify({ type: name })
)
.then(res => {
if (res.data.result === 1) {
this.setState({
volume_chart_data: [
{
label: "Label1",
data: res.data.data2.map(vol => ({
x: vol.created_at,
y: (vol.volume * vol.percentage) / 100
}))
},
{
label: "Label2",
data: res.data.data2.map(vol => ({
x: vol.created_at,
y: vol.volume
}))
}
],
load_vol_chart: false
});
}
});
}
render() {
return (
<div className="inner-content" style={{ marginTop: "12px" }}>
<h3>
<i className="fa fa-caret-right" /> {" "}
{this.props.symbol}: Volume
</h3>
{this.state.load_vol_chart ? null : (
<div
style={{
width: "100%",
height: "400px",
marginTop: "35px",
marginBottom: "10px"
}}
>
<Chart
data={this.state.volume_chart_data}
series={{ type: "bar" }}
axes={[
{ primary: true, type: "ordinal", position: "left" },
{ position: "bottom", type: "linear" }
]}
primaryCursor
secondaryCursor
tooltip
/>
</div>
)}
</div>
);
}
}
export default Volume;
我想要的是:
Label1
条形图是用一些公式计算的。在图表工具提示中,我想显示一个附加值,例如:vol.percent
。我也可以在条上显示这个百分比作为标签吗?我希望这些图表堆叠起来。我试过
stacked:true
了,它不起作用。
我怎样才能实现这些?
提前致谢。
解决方案
推荐阅读
- flutter - 如何获取购物篮中所有商品的总价
- azure-data-explorer - 使用 kusto 查询语言每天或每月关闭多个虚拟机多长时间
- python - SQLAlchemy - 将动态表名传递给查询函数?
- visual-studio - 使用 Visual Studio 2019 进行调试时,dockerized lagacy NET 框架项目的命令行参数
- php - 如何将离子视频捕获移动到 php 中的 file_put_contents()
- mongodb - Mongodb shell find 过滤提取嵌入文本数据
- linux - 加密凭证
- python - 当数据每秒都添加到列表中时,如何在matplotlib上实时绘制简单的折线图?
- c# - Instagram explore/tags API 不返回 JSON 数据
- javascript - 将 JPG 文件与 Photoshop 图层进行比较