Setting Highcharts piechart chartDefaults from calling jsx file in React

試著忘記壹切 提交于 2019-12-12 06:12:30

问题


I am using the following syntax to render a Highcharts PieChart.

var ContainingClass = React.createClass({
  render: function() {
    return (
        <PieChart
            title={this.props.title}
            series={this.props.series}
        />
    );
  },
});

This works well, but I need to overwrite the tooltip field in PieChart. What can I change in ContainingClass to make this happen?

Edit: Here is a sample fiddle with PieChart - http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-basic/ I know that I need to set the tooltip field and could do it in plain javascript or jquery. I don't know how to pass my desired tooltip value from ContainingClass in React.


回答1:


The correct answer is to pass a ChartOverride function as follows:

var ContainingClass = React.createClass({

  render: function() {
    return (
        <PieChart
            title={this.props.name}
            series={this.props.series}
            chartOverrides={this.chartOverrides()}
        />
    );
  },
  chartOverrides: function() {
    return {
      tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
      },
    }
  }

});


来源:https://stackoverflow.com/questions/29222442/setting-highcharts-piechart-chartdefaults-from-calling-jsx-file-in-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!