Daniele B
09/25/2020, 10:56 PMDaniele B
09/26/2020, 12:56 AMimplementation(npm("react-charts","~2.0.0"))
I thought I configured things properly, but when I run the app I get this error in the JS console:
Uncaught ReferenceError: require is not defined
at eval (webpack-internal:///../../node_modules/react-charts/dist/react-charts.mjs:904)
at Module.../../node_modules/react-charts/dist/react-charts.mjs (webApp.js:2542)
at __webpack_require__ (webApp.js:30)
at eval (webpack-internal:///./kotlin-dce-dev/CovidApp-webApp.js:1463)
at Object../kotlin-dce-dev/CovidApp-webApp.js (webApp.js:3419)
at __webpack_require__ (webApp.js:30)
at Object.0 (webApp.js:3651)
at __webpack_require__ (webApp.js:30)
at webApp.js:94
at webApp.js:97
Daniele B
09/26/2020, 12:56 AM@file:JsModule("react-charts")
@file:JsNonModule
import components.Axis
import components.DataSet
import react.RClass
import react.RProps
external interface ReactChartProps: RProps {
var data: List<DataSet>
var axes: List<Axis>
}
@JsName("default")
external val Chart: RClass<ReactChartProps>
I defined the classes:
class DataSet (val label: String, val data: List<DataPoint>)
class DataPoint(val primary: Float, val secondary: Float)
class Axis (val primary: Boolean, val type: String, val position: String)
and this is how I wrapped it into my component:
div {
Chart {
attrs {
data = listOf(
DataSet(
"Series 1", data = listOf(
DataPoint(1f, 5f),
DataPoint(3f, 7f),
DataPoint(4f, 3f),
)
),
DataSet(
"Series 2", data = listOf(
DataPoint(3f, 3f),
DataPoint(6f, 7f),
DataPoint(7f, 1f),
)
),
DataSet(
"Series 3", data = listOf(
DataPoint(8f, 9f),
DataPoint(1f, 5f),
DataPoint(4f, 7f),
)
)
)
axes = listOf(
Axis(true, "linear", "bottom"),
Axis(false, "linear", "left"),
)
}
}
}
altavir
09/27/2020, 12:19 PMDaniele B
09/27/2020, 1:00 PMaltavir
09/27/2020, 1:03 PMDaniele B
09/27/2020, 2:56 PM