Reactjs react ChartList中的onDraw事件
在另一个论坛中,我发现了这段代码,它对我很有用:Reactjs react ChartList中的onDraw事件,reactjs,events,chartist.js,Reactjs,Events,Chartist.js,在另一个论坛中,我发现了这段代码,它对我很有用: var chart = new Chartist.Bar('.ct-chart', { labels: ['Test', 'Long test', 'Very long test'], series: [[1, 5, 3]] }); // Uncomment this line to test rendering without foreign objects //chart.supportsForeignObject = false;
var chart = new Chartist.Bar('.ct-chart', {
labels: ['Test', 'Long test', 'Very long test'],
series: [[1, 5, 3]]
});
// Uncomment this line to test rendering without foreign objects
//chart.supportsForeignObject = false;
chart.on('draw', function(event) {
// If the draw event is for labels on the x-axis
if(event.type === 'label' && event.axis.units.pos === 'x') {
// If foreign object is NOT supported, we need to fallback to text-anchor and event.width / 2 offset.
if(!chart.supportsForeignObject) {
event.element.attr({
x: event.x + event.width / 2,
'text-anchor': 'middle'
});
}
}
});
用它解决的特殊问题并不重要。我的问题是,在使用react ChartList时,我没有使用new ChartList.Bar
来声明新的ChartList组件:
<ChartistGraph
data={graphData}
options={graphOptions}
type={type}
/>
因此,我无法像示例中那样对onDraw事件做出反应。
是否可以将函数绑定到onDraw事件?我试过这样的方法:
<ChartistGraph
onDraw={e => onDrawHandler(e)}
data={graphData}
options={graphOptions}
type={type}
/>
onDrawHandler(e)}
数据={graphData}
选项={graphOptions}
类型={type}
/>
这不起作用。使用
侦听器道具:
<ChartistGraph
listener={{
draw: e => onDrawHandler(e)
}}
data={graphData}
options={graphOptions}
type={type}
/>
onDrawHandler(e)
}}
数据={graphData}
选项={graphOptions}
类型={type}
/>
请参阅:有人能告诉我如何在reactjs中的窗口调整和onclick事件中阻止图表一次又一次地重新绘制吗?