this.dChart.Diagram.Series.Clear();//清空圖的內容 var groups = result.GroupBy(itm => itm["flag"]);//將result根據flag屬性分組 result是要顯示為散點圖的數據內容 foreach (var group ...
this.dChart.Diagram.Series.Clear();//清空圖的內容
var groups = result.GroupBy(itm => itm["flag"]);//將result根據flag屬性分組 result是要顯示為散點圖的數據內容
foreach (var group in groups)
{
var t = group.First();
PointSeries2D series = new PointSeries2D() //新建散點圖組
{
Name = t["flag"].ToString(),
Brush = new SolidColorBrush(Colors.Blue),//顏色
DisplayName = t["flagname"].ToString(),//顯示內容
AnimationAutoStartMode = AnimationAutoStartMode.PlayOnce,
MarkerSize = 8 /*顯示點的大小*/,
MarkerModel = new RingMarker2DModel(),
CrosshairEnabled = true,
CrosshairLabelVisibility = true,
CrosshairLabelPattern = "{S}\n時間:{A}\n水位:{V}m",//滑鼠滑過顯示的內容
};
int flag = Convert.ToInt32(group.Key);//group.Key就是上邊根據分組的屬性
switch (flag)//自定義顏色
{
case 0: series.Brush = new SolidColorBrush(Colors.Blue); break;
case 1: series.Brush = new SolidColorBrush(Colors.Green); break;
case 2: series.Brush = new SolidColorBrush(Colors.Yellow); break;
case 3: series.Brush = new SolidColorBrush(Colors.Red); break;
default: break;
}
var source = group.ToList();
foreach (var s in source)//將數據內容賦值到點上
{
if (s["a"] == null || string.IsNullOrEmpty(s["a"].ToString()))//判斷空值
continue;
double z = Convert.ToDouble(s["a"]);
DateTime tm = Convert.ToDateTime(s["tm"]);
series.Points.Add(new SeriesPoint(tm, z));//將點加入
}
dChart.Diagram.Series.Add(series);//將散點組賦值給圖的數據源
}