Yopadd / vue-chartist

Pluging chartist for vuejs
Do What The F*ck You Want To Public License
172 stars 21 forks source link

Add tooltip plugin #32

Closed 50l3r closed 6 years ago

50l3r commented 6 years ago

Hi guys,

¿How can i add tooltip plugin to vue-chartist?

I try with:

import chartist from 'vue-chartist'
import chartist_tooltip from 'chartist-plugin-tooltips'

vue.use(chartist,{
    plugins: [
         chartist_tooltip
    ],
})
hitautodestruct commented 6 years ago

@50l3r The plugin definition goes into your options configuration per component. You would have to import it in the vue component like you did and then set it up like so:

<template>
    <chartist :data="chart_data" :options="chart_options" type="Line" />
</template>
<script>
import chartist_tooltip from 'chartist-plugin-tooltips'

export default {
  data () {
    return {
      chart_options: {
        plugins: [ chartist_tooltip() ]
      }
    }
  }
}
</script>
50l3r commented 6 years ago

I recieve this error:

    vue.esm.js?efeb:591 [Vue warn]: Error in data(): "TypeError: __WEBPACK_IMPORTED_MODULE_3_chartist_plugin_tooltips___default(...) is not a function"

    found in

    ---> <Dashboard> at src\components\Dashboard.vue
           <App> at src\components\App.vue
             <Root>
funami-dev commented 6 years ago

@50l3r that's the same with me. https://www.npmjs.com/package/chartist-plugin-tooltip works. (the package without an s at the end)

If you dont want the jquery version: https://github.com/tmmdata/chartist-plugin-tooltip/issues/152#issuecomment-395361512

or in vue components Imports

import * as ChartistTooltips from 'chartist-plugin-tooltips';

Options

plugins: [this.$chartist.plugins.tooltip()]
50l3r commented 6 years ago

Works well but tooltip positioned in top left:

tooltip

50l3r commented 6 years ago

Fixed with some css

.chartist-tooltip{ position: absolute; background: rgba(0,0,0,0.6); color: white; padding: 0px 10px; border-radius: 5px; }

matteoraf commented 4 years ago

@50l3r that's the same with me. https://www.npmjs.com/package/chartist-plugin-tooltip works. (the package without an s at the end)

If you dont want the jquery version: tmmdata/chartist-plugin-tooltip#152 (comment)

or in vue components Imports

import * as ChartistTooltips from 'chartist-plugin-tooltips';

Options

plugins: [this.$chartist.plugins.tooltip()]

This way the linter complains about ChartistTooltips never being used. Any workaround besides disabling linting for that line?

matteoraf commented 4 years ago

Ok, I got it working by putting

import Vue from 'vue'
import 'chartist/dist/chartist.min.css'
import 'chartist-plugin-tooltips-updated/dist/chartist-plugin-tooltip.min'

Vue.use(require('vue-chartist'))

in a plugin file and then imported it in my main.js