问题
I am using the jquery pie chart/donut to display data on several pages. There is one chart for each page, which has different data.
My plan was to put the coding for each of the pie charts into an external js file that would then be referenced on each page in the page template.
However, when the script for the jqplot donut chart on the linked js file gets to a chart that doesn't have a matching ID on the page, none of the scripts for the following charts work.
This means that only the first chart listed in the script works. All other pages are not displaying their charts, as there is script above that doesn't have a matching ID on that page.
For example, chart 1 and chart 2 both have their coding in a js file, with the code for chart 1 first, code for chart 2 second. on page 1, the pie chart 1 displays as it has a ID on that page for pie chart 1. However, on page 2, there is no matching element for pie chart 1, and the script just throws an error and doesn't get to the code for pie chart 2, which is then not displayed in its matching element on page 2.
Usually when I do similar, if the code doesn't have a matching ID on the page the code is just ignored. There seems to be something in the jqplot that causes this error if the code is not matched to an element.
This seems a basic implementation to me. I'm sure many people use the pie chart on multiple pages for different data sets and put the coding for them all in a single js file, rather than in-page or referencing multiple individual js files.
Any help on this issue would be appreciated many thanks
Richard
来源:https://stackoverflow.com/questions/29811617/jqplot-error-with-multiple-pie-charts-on-external-js-file