简体   繁体   English

React + d3 具有不同数据的多个图表组件

[英]React + d3 multiple charts components with different data

在此处输入图像描述

I want to develop a 'monthly calendar' view with radial line charts for each day - displaying different data for each day.我想开发一个“月历”视图,其中包含每天的径向折线图 - 每天显示不同的数据。 Right now I only used 3 days, just to try how would it work.现在我只用了 3 天,只是为了尝试它是如何工作的。 The problem is that the graphs are getting attached to the previous svgs and they should be rendered only once in one separate svg for each of the graphs.问题是这些图附加到以前的 svg 上,它们应该只在每个图的一个单独的 svg 中渲染一次。

Here is the component that generates the graph: https://pastebin.com/hzRwNhNh And here is the Calendar component: https://pastebin.com/m6qd1z3m这是生成图表的组件: https ://pastebin.com/hzRwNhNh 这是日历组件: https ://pastebin.com/m6qd1z3m

Calendar component has now 3 charts components:日历组件现在有 3 个图表组件:

<CalendarRadial currentDay={'2017-03-03'}
          dataDayHours={dataParser.getDayHoursArr(this.props.monthData, '2017-03-03')}
          dayInsights={this.props.monthData}
          lineType={this.props.lineType}
          clockConfig={this.props.clockConfig} />
        <CalendarRadial currentDay={'2017-03-04'}
          dataDayHours={dataParser.getDayHoursArr(this.props.monthData, '2017-03-04')}
          dayInsights={this.props.monthData}
          lineType={this.props.lineType}
          clockConfig={this.props.clockConfig} />
        <CalendarRadial currentDay={'2017-03-05'}
          dataDayHours={dataParser.getDayHoursArr(this.props.monthData, '2017-03-05')}
          dayInsights={this.props.monthData}
          lineType={this.props.lineType}
          clockConfig={this.props.clockConfig} />

I assume the problem is when rendering svg.我认为问题出在渲染 svg 时。

This is how example props look like (this part should be correct):这是示例道具的样子(这部分应该是正确的): 在此处输入图像描述

The problem was that I was attaching everythin to the same class ('.radial).问题是我将所有东西附加到同一个类('.radial)。 Instead I created a new g element and appended each data to it and this helped.相反,我创建了一个新的 g 元素并将每个数据附加到它,这很有帮助。

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

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