【问题标题】:High chart how to process config if get config from DB and it contianed a function?高图表如果从数据库获取配置并包含函数,如何处理配置?
【发布时间】:2021-04-19 08:51:15
【问题描述】:

假设我从服务器端获得了图表配置:

  let chartConfig = {
    chart: {
      type: "bar"
    },
    tooltip: {
      formatter: `function () {
        return  this.point.name + ':' +this.y;
    }`
    },
  };

所以格式化程序函数需要是一个字符串,以便可以将其保存为 JSON 字符串。 它不能作为字符串工作。

我将 react 与 highchart-react-officail 库一起使用。

我试过这个:

    useEffect(() => {
        chartConfig.tooltip.formatter = tooltipsFormat;
    }, [])

    const tooltipsFormat = () => {
        return this.key + '<br/>' 
    }

将函数重新分配给格式化程序,但很明显,这里的“this”与配置中的不一样。

我应该怎么做才能让它工作?

【问题讨论】:

    标签: highcharts react-highcharts


    【解决方案1】:

    更新:

     useEffect(() => {
            chartConfig.tooltip.formatter = function(){
               return this.key + '<br/>' 
    
        }, [])
    

    将解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-11
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      相关资源
      最近更新 更多