反应图不会呈现 PIE 图表的图例

React-chart does not render the legend for PIE chart

本文关键字:PIE      更新时间:2023-09-26

我正在使用react-chart在我们的应用程序中呈现饼图。我们想显示饼图的图例,但找不到有关如何执行此操作的任何选项,也没有关于github存储库的帮助。

请帮忙。

发现问题并发布解决方案。

问题 - 问题出在 npm 上可用的反应图版本中。那里可用的最新版本是0.6.0github存储库有0.7.3。问题在这里反应图。0.6.0中的代码段如下

classData[name] = function() {
   return this.state.chart[type].apply(this.state.chart, arguments);
};

请参阅我在获得最新版本后用于显示图例的代码。

Component File

componentDidUpdate(){
   var pieChartLegend = this.refs.pieChart && this.refs.pieChart.generateLegend();
   if(this.state.chartLegend !== pieChartLegend){this.setState({chartLegend:pieChartLegend});}
}
render(){
   return(
    <div>
    <PieChart ref="pieChart" data={data} style={{height:'60%',width:'100%'}}
    options={
        {
            tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value + ' %' %>",
            legendTemplate:"<ul class='"<%=name.toLowerCase()%>-legend'" style='"list-style-type: none'"><% for (var i=0; i<segments.length; i++){%><li style='"text-align: left;'"><span style='"color:<%=segments[i].fillColor%>'"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
        }
    } />
    <div style={{position:'absolute',top:'100px',left:'370px'}} dangerouslySetInnerHTML={{__html: this.state.chartLegend}} />
    </div>
    )
}
相关文章:
  • 没有找到相关文章