dabeng / OrgChart

It's a simple and direct organization chart plugin. Anytime you want a tree-like chart, you can turn to OrgChart.
MIT License
2.88k stars 771 forks source link

Dynamically load datasources for many charts? #147

Open norbertsch17 opened 7 years ago

norbertsch17 commented 7 years ago

Hi folks, Is there a way to add datasources dynamically (no ajax reload), maybe based on some div-attributes? I have numerous charts, all sharing the same settings and createNode() function. Only difference is the datasource (and export filename). Currently I have to repeat the full $(...).orgchart(){} js for all of these charts again and again.

Instead I'd like to do something like <div class="chart-container" data-chartsource-info="foo"></div> <div class="chart-container" data-chartsource-info="bar"></div> etc. Then start all charts at once with $('.chart-container').orgchart({ [...] where the data-attribute is a function returning the actual chart data. Something like: 'data': function($the-original-chart-dom-object) { // do something, like reading the // data-chartsource-info attribute to prepare the dataset return mydataobject; }

I could think of alternative ways to do this, maybe call a setDatasource()-method after instanciating the charts by $('.chart-container') without a data-source set, but above seems more handy to me.

Any hints on this?

Cheers, Norbert Thanks or this little marvel!

dabeng commented 7 years ago

Hi @norbertsch17 , I wonder what's your concrete demands? Why do you need to display multiple orgcharts within one page ? From my point of view, it's truly not common use case.