I trying to make custom tooltip for apexcharts like in example: https://apexcharts.com/docs/options/tooltip/#
JavaScript
x
8
1
tooltip: {
2
custom: function({series, seriesIndex, dataPointIndex, w}) {
3
return '<div class="arrow_box">' +
4
'<span>' + series[seriesIndex][dataPointIndex] + '</span>' +
5
'</div>'
6
}
7
}
8
and it’s works, but when I set in return some vue component nothing shows.
JavaScript
1
6
1
tooltip: {
2
custom: function({series, seriesIndex, dataPointIndex, w}) {
3
return '<MyComponent/>'
4
}
5
}
6
JavaScript
1
8
1
<template>
2
<div>Just simple component</div>
3
</template>
4
5
<script>
6
export default { name: "MyComponent" }
7
</script>
8
Why is this happening and how to fix it?
Advertisement
Answer
To make Vue render the component correctly, you’ll have to tell it to in the custom tooltip function:
JavaScript
1
14
14
1
tooltip: {
2
custom: ({series, seriesIndex, dataPointIndex, w}) => {
3
// create component constructor
4
var TooltipComponent = Vue.extend({
5
template: '<my-component/>'
6
});
7
// create an instance of tooltip and mount it
8
var tooltip = new TooltipComponent();
9
tooltip.$mount();
10
// Return the html
11
return tooltip.$el.outerHTML;
12
}
13
}
14
If you need data or other reactivity it becomes a bit more complicated, see https://v2.vuejs.org/v2/api/#Vue-extend for more information.