Anyone had any success with using chart.js date ad...
# kvision
c
Anyone had any success with using chart.js date adapters with KVision? I naively tried to add an (NPM) dependency to an adapter in the build, but no cigar 😞
r
I've just tried that with KVision 9.0.0 and it seems to work. Dependencies
Copy code
implementation(npm("luxon", "*"))
        implementation(npm("chartjs-adapter-luxon", "*"))
Import modules:
Copy code
@JsModule("luxon")
external object LuxonModule

@JsModule("chartjs-adapter-luxon")
external object LuxonAdapterModule
Initialize:
Copy code
useModule(LuxonModule)
        useModule(LuxonAdapterModule)
I'm not sure how to use time axis, but the project builds and works without errors.
c
I'll try to add the import and intialization steps, I had no idea what's expected so I tried with just the dependencies. However, the error doesn't appear until runtime: "This method is not implemented: Check that a complete date adapter is provided." Basically, I just add:
Copy code
scales = mapOf("x" to ChartScales(type = ScalesType.TIME))
to my ChartOptions.
(and make sure that my X axis data are strings or something that isn't unix timestamps)
r
Yes. I had this runtime error. Adding and initializing imports fixed it.
c
OK sounds very promising 🙂 I'm trying it just now...
Probably a really stupid question, but what would be the context of the @JsModule() / useModule() stuff? I'm not at all familiar with those. Is that Kotlin API?
r
@JsModule
is
kotlin.js.JsModule
- Kotln JS API
useModule()
is KVision helper function, that doesn't do anything but forces some externals not to be removed by DCE
c
I see. I think I was on the right track, but I get "Unresolved reference 'useModule'" and can't seem to find out where it's defined.
r
io.kvision.utils.useModule
c
👍
r
But you need to work with KVision 9
c
Aha, that'd be the culprit then, I guess. I'm still on 8 😕
r
You would have to use different code with KV 8. Probably
require()
function instead. But the whole modules architecture is now different because KV 9 uses ES modules.
It may not work at all with eariler version.
c
I see. I'll experiment some more - maybe the better route would be to feed it with timestamps in the first place and avoid the need for the adapter.
FYI, I got it working with the Spacetime adapter and KVision 8.1 by simply adding:
Copy code
require("spacetime" )
require("chartjs-adapter-spacetime")
🙂 All the other adapters failed at runtime in one way or another.
👍 1