微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为Google时间线图表中的每个柱线着色?

如何解决如何为Google时间线图表中的每个柱线着色?

在这里阅读了其他一些答案,并相应地添加role属性,但是它不起作用。

<Chart
  width={'500px'}
  height={'300px'}
  chartType="Timeline"
  loader={<div>Loading Chart</div>}
  data={[
    [
      { type: 'string',id: 'President' },{ type: 'date',id: 'Start' },id: 'End' },{type: 'string',role: 'style'}
    ],['Washington',new Date(1789,3,30),new Date(1797,2,4),'gold'],['Adams',new Date(1801,'color: #ccc'],['Jefferson',new Date(1809,]}
  options={{
    showRowNumber: true,}}
  rootProps={{ 'data-testid': '1' }}
/>

引用:https://react-google-charts.com/timeline-chart

解决方法

在时间轴图表上,样式角色仅在用作第三列时起作用。

因此,您还需要为条形标签添加第二列。
但是如果需要,您可以为该列使用null值...

<Chart
  width={'500px'}
  height={'300px'}
  chartType="Timeline"
  loader={<div>Loading Chart</div>}
  data={[
    [
      { type: 'string',id: 'President' },{ type: 'string',id: 'Bar' },// <-- add bar label here...
      { type: 'string',role: 'style' },// <-- add style role here...
      { type: 'date',id: 'Start' },{ type: 'date',id: 'End' }
    ],['Washington',null,'gold',new Date(1789,3,30),new Date(1797,2,4)],['Adams','#ccc',4),new Date(1801,['Jefferson',new Date(1809,]}
  options={{
    showRowNumber: true,}}
  rootProps={{ 'data-testid': '1' }}
/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。