简体   繁体   English

将Recharts.js库导入jsx react文件

[英]import Recharts.js library to jsx react file

I am looking to use Recharts as a graph system for my React app. 我希望将Recharts用作我的React应用程序的图形系统。

To install I have gone to the installation guide and entered the following command in the terminal 要安装,我已经转到安装指南并在终端中输入以下命令

$ npm install recharts

My jsx file then looks like the code below: import React from "react"; 我的jsx文件如下所示:从“ react”导入React; import ReactDOM from "react-dom"; 从“ react-dom”导入ReactDOM; import ReCharts from "recharts"; 从“图表”导入图表;

var App = React.createClass({
  render: function() {
    var data = [{ name: 'a', value: 12 }];
    return (
     <LineChart width={400} height={400} data={data}>
      <Line type="monotone" dataKey="uv" stroke="#8884d8" />
    </LineChart>
    );
  }
});

ReactDOM.render(<App/>, document.getElementById('app'));

It is not working as I am not importing recharges correctly. 我无法正确导入充值,因此无法正常工作。 Can anyone advise and explain how this should be imported and any advice on how I soul know if I am exporting another library without any explicit guidance in its documentation. 任何人都可以提供建议和解释如何导入该库,以及在我没有导出文档的任何明确指导的情况下,是否可以导出其他库的任何建议。

You need import LineChart and Line components from Recharts , because this library does not have default exports Recharts index 您需要从Recharts导入LineChartLine组件,因为该库没有默认的导出Recharts index

import { LineChart, Line } from 'recharts';

Update 更新资料

also you need change dataKey , from 'uv' to 'value' because in data you use value as key for chart values 您还需要将dataKey'uv'更改为'value'因为在data您将value用作图表值的键

Example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM