0

I have an issue with the Legend on a StackedColumn chart. I have set the following dataSeries and legend elements.

enter image description here

In the code, I have the following for loop to assign all the labels to the values so that they appear in the legend.

v = compositeData.dataSeries;
y = compositeData.legend;
for (i = 0; i < v.length; i++) {
    dataSeries = v[i];
    r += '  ynchart.addSeries("'+y[i]+'", ['+dataSeries+']);'+@NewLine();
}

When I run the code, I end up with

enter image description here

showing the legend except the order of the labels is not in the order I expected. Element [3] is first, followed by [0], 1 and 2. The color of the elements in the legend are in the correct order but somehow the label is not. I have no code in the script anywhere else that sorts anything. Why is the order of the legend label reordering itself and how do I fix it?

4

1 回答 1

0

When you specify a parameter in a custom control as "multi-instance" you hand over a java.util.List. The List doesn't guarantee you any delivery sequence and that seems what is happening here. So you are probably better of handing over ONE parameter which you then split(). Of course that leans itself to the potential issue that your label and values get out of sync. So you might want to hand over a complete JSON with all included as parameter. Something like:

{ "values" : { "worldwide" : [10,20,30],
               "NA" : [2,10,20],
               "Europe" : [4,5,4],
               "Japan" : [4,5,6]
             }
}

You could consider a function that you hand the names of your fields that returns that string for you.

于 2012-11-01T17:01:28.790 回答