|
Scatter chart |
Posted by Claude Kane on Dec-05-2013 22:56 |
|
I have a XYChart that I wish to change the color of the symbol based on a third data set. I have an array with the Hex code for the color desired for each symbol. I am thinking of addextrafield, but not sure how to implement that and get the symbol to change color.
Therefore I have 3 arrays, xData, Ydata, ColorData
Suggestions? |
Re: Scatter chart |
Posted by Peter Kwan on Dec-06-2013 00:24 |
|
Hi Claude,
If you have only a few symbols (eg. 500 symbols), you may consider to simply use one symbol per layer. In this way, each symbol can have a different color, shape, etc.. For example:
for (int i = 0; i < xData.Length; ++i)
c.addScatterLayer(new double[] { xData[i] }, new double[] { yData[i] }, "", Chart.CircleSymbol, 9, ColorData[i], ColorData[i]);
If you have a large number of symbols (eg. 50000 symbols), it is better to divide the symbols into groups based on colors, and then use one scatter layer per group. In C#, it is like:
//separate the points into groups based on color
Dictionary< int, List<int> > groups = new Dictionary< int, List<int> >();
for (int i = 0; i < ColorData.Length; ++i) {
if (!groups.ContainsKey(ColorData[i]))
groups.Add(ColorData[i], new List<int>()); // add a new group
groups[ColorData[i]].Add(i);
}
//plot each group as a scatter layer
foreach (var pair in groups) {
double[] groupXData= new double[pair.Value.Count];
double[] groupYData= new double[groupXData.Length];
foreach(int j = 0; j < groupXData.Length; ++i) {
groupXData[i] = xData[pair.Value[i]];
groupYData[i] = yData[pair.Value[i]];
}
c.addScatterLayer(groupXData, groupYData, "", Chart.CircleSymbol, 9, pair.Key, pair.Key);
}
Hope this can help.
Regards
Peter Kwan |
|