您无法直接修改图例的顺序,但您可以对模型内的系列进行排序,因此您将看到图例按字母顺序排序:
有两种方法可以进行排序:
选项 1,简单冒泡排序:
Series temp;
int length = plotModel.Series.Count;
for (i = 0; i < length; i++)
{
for (int j = i + 1; j < length; j++)
{
if (string.Compare(plotModel.Series[i].Title, plotModel.Series[j].Title) > 0) //true if second string goes before first string in alphabetical order
{
temp = plotModel.Series[i];
plotModel.Series[i] = plotModel.Series[j];
plotModel.Series[j] = temp;
}
}
}
Run Code Online (Sandbox Code Playgroud)
选项 2,辅助列表:
List<Series> sortedList = new List<Series>(plotModel.Series);
sortedList.Sort((x, y) => string.Compare(x.Title, y.Title));
plotModel.Series.Clear();
foreach(Series s in sortedList)
plotModel.Series.Add(s);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
825 次 |
| 最近记录: |