-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SparklineBarFormatter to customise bar sparklines #216
Comments
Hello @amp36, Please check out here to see if this helps. https://www.ag-grid.com/react-data-grid/sparklines-data/#formatting-sparkline-data This isnt really something that we can add to the grid, but would have to be something that ag-grid handles itself. |
It seems like I should be able to pass a formatter function into
However, the error I get in the console is that |
Ok, yes, I see the issue now. We will need to add this functionality in our next release. Probably going to try to work with more Enterprise features. |
Hi @amp36 You can make the whole Note that you can also use components such as SparlinkeBarFormatter example: import dash_ag_grid as dag
from dash import Dash, html
app = Dash(__name__)
rowData = [
{
"symbol": "A",
"name": "Agilent Technologies Inc. Common Stock",
"change": [0.9, 0.8],
"volume": "$971,760",
},
{
"symbol": "AAL",
"name": "American Airlines Group Inc. Common Stock",
"change": [0.2, 0.3],
"volume": "$20,309,670",
},
{
"symbol": "AAP",
"name": "Advance Auto Parts Inc Advance Auto Parts Inc W/I",
"change": [0.4, 0.1],
"volume": "$699,427",
},
{
"symbol": "AAPL",
"name": "Apple Inc. Common Stock",
"change": [0.5, 0.7],
"volume": "$57,807,909",
},
]
columnDefs = [
{"field": "symbol", "maxWidth": 120},
{"field": "name", "minWidth": 250},
{
"field": "change",
"cellRenderer": "agSparklineCellRenderer",
"cellRendererParams": {"function": "sparklineBarCellRendererParams"},
},
{
"field": "volume",
"type": "numericColumn",
"maxWidth": 140,
},
]
defaultColDef = {
"flex": 1,
"minWidth": 100,
"resizable": True,
}
app.layout = html.Div(
[
dag.AgGrid(
enableEnterpriseModules=True,
rowData=rowData,
defaultColDef=defaultColDef,
columnDefs=columnDefs,
columnSize="sizeToFit",
dashGridOptions={"rowHeight": 50},
),
],
style={"margin": 20},
)
if __name__ == "__main__":
app.run(debug=True)
"""
Add the following to the dashAgGridFunctions.js file in /assets
var dagfuncs = (window.dashAgGridFunctions = window.dashAgGridFunctions || {});
function sparklineBarFormatter(params) {
const { yValue } = params;
return {
fill: yValue <= .20 ? '#4fa2d9' : yValue < .60 ? '#277cb5' : '#195176',
};
}
dagfuncs.sparklineBarCellRendererParams = {
sparklineOptions: {
type: 'bar',
// fill: '#5470c6',
stroke: '#91cc75',
highlightStyle: {
fill: '#fac858',
},
valueAxisDomain: [0, 1],
paddingOuter: 0,
padding: {
top: 0,
bottom: 0,
},
axis: {
strokeWidth: 0,
},
formatter: sparklineBarFormatter
},
}
""" |
We already have a valueFormatter, it would be nice to be able to customise sparklines using a formatter in
sparklineOptions
https://www.ag-grid.com/javascript-data-grid/sparklines-bar-customisation/#barsparklineoptions
The text was updated successfully, but these errors were encountered: