繁体   English   中英

如何向chartjs中的插件添加第二个功能?

[英]How do I add a second function to a plugin in chartjs?

我有这个。

  type: 'line',
  data: data,
  options: options,
  plugins: [{
    id: "responsiveGradient",

    afterLayout: function(downChart) {
      console.log(downChart);
      let scales = downChart.scales;
      let color = downChart.ctx.createLinearGradient(0, scales["x-axis-0"].top, 0, 0);

      //let chartColors = getChartColors(status);
      color.addColorStop(0, "rgba(0, 181, 63, 0.01)");
      color.addColorStop(1, "rgba(0, 181, 63, 0.6)");

      downChart.data.datasets[0].backgroundColor = color;
    },
  }]
});

我需要在“afterLayout”键之后添加第二个函数。

更多信息在这里: https : //www.chartjs.org/docs/latest/developers/plugins.html

定义并调用要在调用 afterLayout 处理程序时运行的两个函数:

function func1(downChart) {
    console.log(downChart);
    let scales = downChart.scales;
    let color = downChart.ctx.createLinearGradient(0, scales["x-axis-0"].top, 0, 0);

    //let chartColors = getChartColors(status);
    color.addColorStop(0, "rgba(0, 181, 63, 0.01)");
    color.addColorStop(1, "rgba(0, 181, 63, 0.6)");

    downChart.data.datasets[0].backgroundColor = color;
};

function func2(downChart) {
    ....
};

然后在匿名函数中,你可以调用上面的两个。

type: 'line',
data: data,
options: options,
plugins: [{
    id: "responsiveGradient",

    afterLayout: function(downChart) {
        func1(downChart);
        func2(downChart);
      },
    }]
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM