【发布时间】:2017-09-19 20:58:48
【问题描述】:
我是 React、Highcharts 和 UI 开发的新手。 我想从一组数据中呈现多个图表。目前,该页面仅显示最后一个图表 - 来自数组中的最后一个数据。
function chartToRender(seriesArr){
//console.log(JSON.stringify(application));
var Chart = React.createClass({
// When the DOM is ready, create the chart.
componentDidMount: function() {
// Extend Highcharts with modules
if (this.props.modules) {
this.props.modules.forEach(function(module) {
module(Highcharts);
});
}
// Set container which the chart should render to.
this.chart = new Highcharts[this.props.type || "Chart"](
this.props.container,
this.props.options
);
},
//Destroy chart before unmount.
componentWillUnmount: function() {
this.chart.destroy();
},
//Create the div which the chart will be rendered to.
render: function() {
return React.createElement('div', {
id: this.props.container
});
}
}), element2;
return seriesArr.map(application =>
element2 = React.createElement(Chart, {
container: 'stockChart',
type: 'stockChart',
options: {
rangeSelector: {
selected: 0
},
title: {
text: application.app_name + ' application Free Memory'
},
tooltip: {
style: {
width: '200px'
},
valueDecimals: 4,
shared: true
},
xAxis:{
type:'datetime',
//categories : timeSeries,
dateTimeLabelFormats : {
millisecond: '%Y-%m-%dT%H:%M:%S.%L'
}
},
yAxis: {
title: {
text: 'Free Memory'
}
},
series: application.series
}
})
)
}
目前我是通过类上的render函数调用这个函数
render() {
var seriesArr = getSeriesArr(this.props)
return(
<div>
<div className="row">
<ul>
{chartToRender(seriesArr)}
</ul>
</div>
</div>
)
}
如何在一个页面的下方显示所有图表? “seriesArr”变量具有渲染图表所需的所有数据。
【问题讨论】:
-
看起来您错过了一些代码 - 任何地方都没有
chartToRender()函数。可能是Chart组件末尾的问题? -
您好,邓肯,感谢您抽出宝贵时间。我已经编辑了问题以显示我使用的功能。该函数只是定义了 Chart 类并使用它来创建要渲染的元素
-
Stil 看起来有点奇怪 -
}), element2;后面的createClass()行是什么意思。那是交付吗? -
Duncan,我只是声明了 2 个变量 - Chart 和 element2。
标签: javascript reactjs highcharts