简体   繁体   中英

how to use one graph more than 1 time on one page morris js

how to use one graph more than 1 time on one page morris.js

for example:

  element: 'sales_statistics',

that is using ID but is it possible to use class instead

If you pass element a string, morris will assume its an id . Otherwise, you can pass morris a jQuery object, or even a DOM object. So if your classname was .sales_statistics , you could do this:

element: $('.sales_statistics'),

or

element: document.getElementsByClassName('sales_statistics'),

A great way to learn about things like that is to look at the source code. The following is a snippet from Morris's Donut constructor, and the same logic is seen in Grid and other constructors (I found it by doing a search for element in the source):

        this.options = $.extend({}, this.defaults, options);
        if (typeof options.element === 'string') {
            this.el = $(document.getElementById(options.element));
        } else {
            this.el = $(options.element);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM