初学者:使用谷歌图表设置React Gantt图表

时间:2017-04-03 10:33:17

标签: javascript reactjs charts gantt-chart

目标:在反应中显示甘特图。目前使用谷歌图表与github的反应包装。我还是React和JS的新手,我正在努力学习!

问题:可能误解了一些关键的东西,我还没有意识到!我找不到文档/示例来帮助我克服这个困境。我90%肯定我的语法错了但几个小时后我仍然认为我没有走上正轨。

我正在使用的资源

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

^ 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;

1 个答案:

答案 0 :(得分:0)

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'],
],