您不能直接修改去傳說中的順序,但你可以在一系列排序的模型裏面,所以你會看到傳說按字母順序排序:
有你有2種方法來進行排序:
選項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;
}
}
}
選項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);