gpt4 book ai didi

javascript - 初学者 : Setting up React Gantt chart using google charts

转载 作者:行者123 更新时间:2023-11-28 04:48:10 28 4
gpt4 key购买 nike

目标:在React中显示甘特图。目前正在使用 Google Charts 和来自 github 的 React 包装器。我对 React 和 JS 还很陌生,我正在努力学习!

问题:可能误解了一些我尚未意识到的关键问题!我找不到帮助我克服这个困难的文档/示例。我 90% 确信我的语法是错误的,但几个小时后我仍然认为我没有走在正确的轨道上。

我正在使用的资源:

React google charts Gant example尝试使用 Prop 窗口作为指导

^ The github readme from the above, specifically using the rows/columns setup

This older SO question.

当前停留在渲染上的代码:

import { Chart } from 'react-google-charts';
import React from 'react';

class ExampleChart extends React.Component {
constructor(props) {
super(props);
this.state = {

rows: [
['Research','Find sources','2015-01-01T08:00:00.000Z','2015-01-05T08:00:00.000Z',null,100,null],
['Write','Write paper',null,'2015-01-09T08:00:00.000Z',259200000,25,'Research,Outline'],
['Cite','Create bibliography',null,'2015-01-07T08:00:00.000Z',86400000,20,'Research'],
['Complete','Hand in paper',null,'2015-01-10T08:00:00.000Z',86400000,0,'Cite,Write'],
['Outline','Outline paper',null,'2015-01-06T08:00:00.000Z',86400000,100,'Research'],
],

columns: [
{
id:'Task ID',
type:'string',
},
{
id:'Task Name',
type:'string',
},
{
id:'Start Date',
type:'date',
},
{
id:'End Date',
type:'date',
},
{
id:'Duration',
type:'number',
},
{
id:'Percent Complete',
type:'number',
},
{
id:'Dependencies',
type:'string',
},
],
};
}


render() {
return (
<Chart
graph_id="ganttchart"
chartType = "Gantt"
columns={this.state.columns}
rows={this.state.rows}
chartPackages={['gantt']}
width="100%" height="9999px">
</Chart>
);
}
}
export default ExampleChart;

最佳答案

react-google-charts 似乎需要 Date 对象。我没有在源代码中明确验证这一点,但是当我将 rows 更改为:

时,一切都呈现正常
rows: [
['Research','Find sources',new Date(2015,1,1,8,0,0), new Date(2015,1,5,8,0,0),null,100,null],
['Write','Write paper',null,new Date(2015,1,9,12,0,0),259200000,25,'Research,Outline'],
['Cite','Create bibliography',null,new Date(2015,1,7,8,0,0),86400000,20,'Research'],
['Complete','Hand in paper',null,new Date(2015,1,10,8,0,0),86400000,0,'Cite,Write'],
['Outline','Outline paper',null,new Date(2015,1,6,8,0,0),86400000,100,'Research'],
],

关于javascript - 初学者 : Setting up React Gantt chart using google charts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43182311/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com