highcharts / highcharts-vue

Other
686 stars 150 forks source link

Added: HighchartsVue.use for easy registration of features #137

Closed richardeschloss closed 1 year ago

richardeschloss commented 4 years ago

This PR suggests a much simpler implementation for registering additional Highcharts features, such as exporting, mapChart, and stockChart.

Prior to this PR, the developer had to register the feature like this:

import Highcharts from 'highcharts'
import stockInit from 'highcharts/modules/stock'
stockInit(Highcharts)

However, this doesn't always work, since it sometimes throws an error "TypeError: Cannot read property 'parts/Globals.js' of undefined" as described here...that problem required a (typeof Highcharts === 'object') check, but there's an even simpler way for both you guys and people that use the wrapper. Simply define a "use" property (method) on the wrapper, and let that method handle everything. This results in extremely simple code that's easy to maintain (and less docs to update):


import Vue from 'vue'
import HighchartsVue from 'highcharts-vue' // So, people were already doing this... 
import { mapData } from 'js/worldmap'

// Just tell HighchartsVue what features to use:
HighchartsVue.use('exporting')
HighchartsVue.use('stockChart')
HighchartsVue.use('mapChart', { mapName: 'myMapName', mapData })

Easy!

--- 

Also: the linter required some updating just so I could get the linter to pass 
nicqchen commented 4 years ago

hi richard, do you know how to enable stock tools or indicators ?

richardeschloss commented 4 years ago

Hi @nicqchen , I think these two links will help: