Native Grist charts do a few extra data transformations that may be good to port here. See these functions in particular:
sortByXValues
trimNonNumericData
consolidateValues
Note that since custom charts are much more flexible, these may create undesirable tradeoffs.