Hey everyone, I am looking for a way to get agSparklineCellRenderer
rendered in an aggregated AG Grid. I have tried a few things, but to no avail. Also, I couldn’t find an example of what I’m after on either the AG Grid or Dash websites.
In brief, I have a dataset like this:
rowData = [
{ columnA: 'A', columnB: 'B', sparklineValues: 2 },
{ columnA: 'A', columnB: 'B', sparklineValues: 3 },
{ columnA: 'A', columnB: 'C', sparklineValues: 3 },
{ columnA: 'A', columnB: 'C', sparklineValues: 4 },
]
I am grouping the Column A
and Column B
columns and would like to see the sparkline chart rendered in the cells of the sparklineValues
column.
columnDefs = [
{"headerName": "Column A", "field": "columnA", "rowGroup": True, "hide": True},
{"headerName": "Column B", "field": "columnB", "rowGroup": True, "hide": True},
{
"headerName": "Sparkline",
"field": "sparklineValues",
"cellRenderer": "agSparklineCellRenderer",
"cellRendererParams": {"function": "sparklineCellRenderer(params)" },
"aggFunc": "sum",
"valueGetter": {"function": "[params.data['sparklineValues']]"} #As I need to return a list for the sparkline component
},
]
ag-grid.js
dagfuncs.sparklineCellRenderer = (params) => {
return {
"sparklineOptions": {
"type": "bar",
"stroke": "#91cc75",
"highlightStyle": {
"fill": "#fac858",
},
"valueAxisDomain": [-30, 30],
"paddingOuter": 0,
"padding": {
"top": 0,
"bottom": 0,
},
"label": {
"enabled": true,
"fontWeight": "normal",
"fontSize": 14,
"placement": "insideEnd",
},
formatter: (params) => {
const { yValue, highlighted } = params;
if (highlighted) {
return;
}
return {
fill: yValue < 0 ? "#F9CACA" : "#C8ECD7",
};
}
},
}
}
I would really appreciate any input that can help me with this or anything related.
Cheers,
Adriana Cavalcanti