2020-05-07 15:59:06 +02:00
|
|
|
<script>
|
2020-05-18 12:01:09 +02:00
|
|
|
import { onMount } from "svelte"
|
|
|
|
import FusionCharts from "fusioncharts"
|
|
|
|
import Charts from "fusioncharts/fusioncharts.charts"
|
|
|
|
import FusionTheme from "fusioncharts/themes/fusioncharts.theme.fusion"
|
|
|
|
import SvelteFC, { fcRoot } from "svelte-fusioncharts"
|
2020-05-07 23:15:09 +02:00
|
|
|
|
2020-05-18 12:01:09 +02:00
|
|
|
fcRoot(FusionCharts, Charts, FusionTheme)
|
2020-05-07 15:59:06 +02:00
|
|
|
|
|
|
|
export let _bb
|
|
|
|
export let _instanceId
|
|
|
|
export let model
|
2020-05-07 23:15:09 +02:00
|
|
|
export let type = "column2d"
|
2020-05-07 15:59:06 +02:00
|
|
|
|
2020-05-07 23:15:09 +02:00
|
|
|
let store = _bb.store
|
|
|
|
|
|
|
|
$: chartConfigs = {
|
|
|
|
type,
|
2020-05-18 12:01:09 +02:00
|
|
|
width: "600",
|
|
|
|
height: "400",
|
|
|
|
dataFormat: "json",
|
2020-05-07 23:15:09 +02:00
|
|
|
dataSource: {
|
2020-05-18 12:01:09 +02:00
|
|
|
data: $store[model._id] || [],
|
|
|
|
},
|
2020-05-07 23:15:09 +02:00
|
|
|
}
|
2020-05-07 15:59:06 +02:00
|
|
|
|
|
|
|
async function fetchData() {
|
2020-05-07 23:15:09 +02:00
|
|
|
const FETCH_RECORDS_URL = `/api/${_instanceId}/all_${model._id}/records`
|
2020-05-07 15:59:06 +02:00
|
|
|
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
|
|
|
if (response.status === 200) {
|
|
|
|
const json = await response.json()
|
2020-05-07 23:15:09 +02:00
|
|
|
store.update(state => {
|
2020-05-18 12:01:09 +02:00
|
|
|
state[model._id] = json
|
2020-05-07 23:15:09 +02:00
|
|
|
return state
|
|
|
|
})
|
2020-05-07 15:59:06 +02:00
|
|
|
} else {
|
|
|
|
throw new Error("Failed to fetch records.", response)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
await fetchData()
|
|
|
|
})
|
2020-05-07 23:15:09 +02:00
|
|
|
</script>
|
2020-05-07 15:59:06 +02:00
|
|
|
|
2020-05-07 23:15:09 +02:00
|
|
|
<div id="container">
|
|
|
|
<SvelteFC {...chartConfigs} />
|
2020-05-18 12:01:09 +02:00
|
|
|
</div>
|