首页 > 解决方案 > 当您使用 refreshCells 重新生成图表时,更改 Ag-Grid 中的字幕会做出反应

问题描述

我正在使用 Ag-Grid React,我是新手。我有一个下拉菜单,允许您通过 refreshCells 函数切换到从 AWS 调用的不同数据集到折线图中。当您从下拉列表中选择某些内容时,图表会刷新良好,但我还想更改折线图的副标题以匹配被拉取的数据(选定的下拉值)。这可能与页面初始加载后的 refreshCells 函数有关吗?

标签: ag-gridag-grid-react

解决方案


在定义您的gridOptions对象时定义processChartOptions如下所示。

每当由于基础数据的变化而重绘图表时,都会调用此方法。您可以使用 params 对象动态设置标题/副标题值。

function processChartOptions(params) {
  var options = params.options;

  console.log('chart options:', options);

  options.title.enabled = true;
  options.title.text = 'your title here';
  options.title.fontStyle = 'italic';
  options.title.fontWeight = '600';
  options.title.fontSize = 18;
  options.title.fontFamily = 'Impact, sans-serif';
  options.title.color = '#414182';

  options.subtitle.enabled = true;
  options.subtitle.text = 'your subtitle here';
  options.subtitle.fontSize = 14;
  options.subtitle.fontFamily = 'Monaco, monospace';
  options.subtitle.color = 'rgb(100, 100, 100)';

  return options;
}

这是一个演示


推荐阅读