Dojo chart generation function
A function is written to generate a chart by passing parameters. The Code is as follows:
/*** Created by LZUGIS * @ param container * @ param type * @ param data * @ constructor */function AddChart (container, type, data) {require (["dojox/charting/Chart2D", "dojox/charting/themes/PlotKit/blue", "dojox/charting/action2d/Highlight ", "dojox/charting/action2d/Tooltip", "dojox/charting/action2d/MoveSlice"], function (Chart2D, themes, Highlight, Tooltip, MoveSlice) {var chart = new dojox. charting. chart2D (container); chart. setTheme (dojox. charting. themes. plotKit. blue); // set the topic switch (type) {case "bar": {// bar chart. addPlot ("default", {type: "Columns", gap: 8 // interval between control Columns}); break;} case "pie ": {// pie chart. addPlot ("default", {type: "Pie", labelOffset: 40 // control the display position of the annotation, "+" is inside, "-" is outside}); break ;} case "line": {// linear chart. addPlot ("default", {type: "Lines", markers: true, // whether the data point displays tension: "X" // The curve is smooth, "X" is similar to "S", and "x" is closed and smooth}); break;} case "stack": {// stacked chart. addPlot ("default", {type: "StackedColumns", gap: 8}); break;} default: {break;} var xStr = ["Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; // Add axes var myLabelFunc = function (text, value, precision) {return xStr [text-1] ;}; chart. addAxis ("x", {labelFunc: myLabelFunc}); chart. addAxis ("y", {vertical: true, fixLower: "major", fixUpper: "major"}); chart. addSeries ("Series A", data); new Highlight (chart, "default", {highlight: "lightskyblue"}); new Tooltip (chart, "default "); new MoveSlice (chart, "default"); // new Legend ({chart: chart}, "legend"); chart. render ();});}The usage is simple as follows:
dojo chart test <script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script> <script src="js/dojochart.js"></script> <script type="text/javascript"> var chartData = [40000,9200,11811,12000,8662,12000,8662]; AddChart("chart","bar",chartData); </script>