aggrid:没有可供绘制的数据



我有一个关于ag网格企业版(使用v23.0.0(的新手问题。当我创建一个简单的网格,然后执行以下用户操作时:

  1. 右键单击数字单元格
  2. 选择图表范围、列、分组(实际上,所有图表选项都不起作用…(

我得到No data available to be charted.

这在演示(https://www.ag-grid.com/example.php(中运行良好,但在我的应用程序中不起作用。我需要做什么才能使数据显示在图表中?

我正在使用Flask web应用程序框架来托管我的Python代码。这是我的HTML/JavaScript代码:

agpoc.html:

<!DOCTYPE html>
<html lang="en">
<head>
<script src="{{url_for('static', filename='ag-grid-enterprise.js')}}"></script>
<script src="{{url_for('static', filename='agpoc.js')}}"></script>
</head>
<body>
<div id="salesGrid" style="height: 200px; width:500px;" class="ag-theme-balham"></div>
</body>
</html>

agpoc.js:

document.addEventListener('DOMContentLoaded', function() {
var gridDiv = document.querySelector('#salesGrid');
new agGrid.Grid(gridDiv, gridOptions);
});
var columnDefs = [
{headerName: "brand", field: "brand"},
{headerName: "sales", field: "sales", type: "numericColumn"}
];
var rowData = [
{"brand": "Brand X", "sales": "270.12"},
{"brand": "Brand Y", "sales": "400.89"}
];
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData,
enableCharts: true,
enableRangeSelection: true,
};

我已经调试过了,似乎ag-grid-enterprise.js中的以下代码:

ChartDataModel.prototype.getSelectedValueColState()

返回一个空列表。我不明白example.js在做什么,我没有做这种行为。

有人有什么线索吗?

谢谢

所以这可能有点令人困惑。在您的特定示例中,因为您的salesstrings,而不是numbers

默认情况下,您必须确保每一行都有一个可用的数值。例如,具有undefinednull将导致no data available issue

为了解决这个问题,您需要在感兴趣的特定列的colDef上定义一个chartDataType

这里有一个例子,我用age作为null预写一行,但由于将chartDataType定义为series,它仍然有效

https://plnkr.co/edit/nyzxLY5tntyURkK3

编辑*这看起来像是一个即将修复的错误:

If chartDataType in the column definition is not provided, AG Grid infers whether the data is numeric (for plotting as a series values), or not (for plotting as category values) based on the first row in the column. If the first row in this column doesn't contain a numeric value, it's treated as a category value which cannot be charted, as described here:
https://www.ag-grid.com/javascript-data-grid/integrated-charts-range-chart/#inferred-by-the-grid
This is why please set chartDataType='series' on columns you want to chart in order to avoid cases where there's a null/undefined value in the first row, which infers the column as a category column and prevents it from charting.

答案现在仍然适用。

最新更新