javascript - Zingchart last element keeps changing color and not matching with legend -


my zingchart's last element's color not match legend, , keeps on changing unlike others. ideas? else works good. though i'm parsing data through mysql database, how javascript looks like.

my code:

 <script>     var mydata = ["12","15","7","20","2","22","10","7","7","10","8","15","9"];     var mydata = mydata.map(parsefloat);     var mylabels = ["general verbal insults","general beatings\/pushing","terrorizing\/threatening remarks","false gossip inflation (rumors)","discrimination","rough fighting","sexual utterance\/assaults","general exclusion","theft","racist utterance\/assaults","personal property damage","internet related (cyber)","other\/unspecified"];      window.onload=function(){         var colorcharacters = "acdef0123456789";         var globalstylesarray = [];          var myconfig = {             type: "bar",              legend:{},             title: {             "text":"showing results for: canada",             "color":"green"              },             subtitle: {             "text":"total bullying incidents in country: 144",             "color":"blue"             },              series : [{"values":[ mydata[0] ],"text":"general verbal insults",},{"values":[ mydata[1] ],"text":"general beatings/pushing",},{"values":[ mydata[2] ],"text":"terrorizing/threatening remarks",},{"values":[ mydata[3] ],"text":"false gossip inflation (rumors)",},{"values":[ mydata[4] ],"text":"discrimination",},{"values":[ mydata[5] ],"text":"rough fighting",},{"values":[ mydata[6] ],"text":"sexual utterance/assaults",},{"values":[ mydata[7] ],"text":"general exclusion",},{"values":[ mydata[8] ],"text":"theft",},{"values":[ mydata[9] ],"text":"racist utterance/assaults",},{"values":[ mydata[10] ],"text":"personal property damage",},{"values":[ mydata[11] ],"text":"internet related (cyber)",},{"values":[ mydata[12] ],"text":"other/unspecified",}]         };         zingchart.render({              id : 'mychart',              data : myconfig,              width:"100%",             height:500,          });         zingchart.gload = function(p) {           console.log(p);           var graphid = p.id;           var graphdata = {};           graphdata = zingchart.exec(graphid, 'getdata');           graphdata = graphdata.graphset[0] ? graphdata.graphset[0] : graphdata;           console.log(graphdata);           createcolors(graphdata.series[0].values.length);           zingchart.exec(graphid, 'modifyplot', {             data: {               styles: globalstylesarray             }           });         }         function createcolors(serieslength) {           console.log('-------createcolor serieslength: ', serieslength);           globalstylesarray = [];           (var = 0; < serieslength; i++) {             var colorstring = '#';             (var j = 0; j < 6; j++) {               colorstring += colorcharacters.charat(math.floor(math.random() * (colorcharacters.length - 4)));             }             globalstylesarray.push(colorstring);           }            console.log('-----globalstylesarray-------', globalstylesarray);         }      };     </script> 

referring comment on op:

i want color different, since dont know how many elements in mydata - generated through php & mysql

if want of colors different, remove zingchart.gload function , createcolors function. zingchart create different colors each series dynamically.

if want specify each of colors ahead of time since not know how many series data produce, need apply theme chart configuration: http://www.zingchart.com/docs/design-and-styling/javascript-chart-themes/


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -