It appears as though the chart.js module isn't bei...
# javascript
n
It appears as though the chart.js module isn't being installed via npm (
npm("chart.js")
). How do I get chart.js installed as a library? Is there a separate Gradle task that needs to be executed?
Forgot to wrap the npm function call inside the implementation function call.
👍 1
g
did you suceed in making chart.js work? I've tried using react-chart-js-2 but couldn't figure out how to set the props
n
Had no luck so far. End up with this error message appearing:
Uncaught TypeError: Cannot create property 'data' on string 'rgb(255, 99, 132)'
Managed to get Chart.js working through trail and error. Basically this means using Dukat to convert the TypeScript definition of the library where the end result is full of compile time errors. As a result the Kotlin definitions were created from scratch to cover a small surface API area, where some techniques were used from the failed Dukat translation to make Chart.js work on the Kotlin JS side.
Below are the definitions:
Copy code
import org.w3c.dom.HTMLCanvasElement

external class Chart<D : Number>(context: HTMLCanvasElement, options: ChartConfiguration<D>)

external interface ChartConfiguration<D: Number> {
    val type: String
    var data: ChartData<D>
}

external interface ChartData<T : Number> {
    var labels: Array<String>
    var datasets: Array<ChartDataSet<T>>
}

external interface ChartDataSet<T : Number> {
    val label: String
    val backgroundColor: String
    val borderColor: String
    val data: Array<T>
}
🎉 2
Below is a example that uses Chart.js: