MasterPane 是 GraphPane 的集合,繼承自 PaneBase。透過 PaneList 管理多個圖表窗格,支援統一標題、圖例、背景、水印等。
MasterPane myMaster = base.MasterPane;
myMaster.PaneList.Clear(); // 移除預設單一 GraphPane
myMaster.Title.Text = "ZedGraph MasterPane Example";
myMaster.IsShowTitle = true;
myMaster.PaneFill = new Fill(Color.White, Color.MediumSlateBlue, 45.0F);
myMaster.MarginAll = 10;
myMaster.Legend.IsVisible = true;
myMaster.Legend.Position = LegendPos.TopCenter;
迴圈建立多個 GraphPane 時,使用 ColorSymbolRotator 依序取得不同顏色/符號,避免手動指定:
ColorSymbolRotator rotator = new ColorSymbolRotator();
for (int j = 0; j < 5; j++)
{
GraphPane myPane = new GraphPane(new Rectangle(10,10,10,10), "Case #" + (j+1), "Time, Days", "Rate, m/s");
// ...
LineItem myCurve = myPane.AddCurve("Type " + j, list, rotator.NextColor, rotator.NextSymbol);
myMaster.Add(myPane);
}
ZOrder 決定 GraphItem (文字、圖片、箭頭) 在 Z 軸 (前後疊加) 的順序。枚舉值由後至前:
| 枚舉值 | 描述 |
|---|---|
G_BehindAll | 最底層,連標題都在它之上 |
F_BehindAxisFill | 座標軸背景填充之下 |
E_BehindAxis | 座標軸物件之下 |
D_BehindCurves | 曲線物件之下 |
C_BehindAxisBorder | 座標軸邊框之下 |
B_BehindLegend | 圖例之下 |
A_InFront | 最上層 (同層級以 GraphItemList 順序決定) |
TextItem text = new TextItem("DRAFT", 0.5F, 0.5F);
text.Location.CoordinateFrame = CoordType.PaneFraction;
text.FontSpec.Angle = 30.0F;
text.FontSpec.FontColor = Color.FromArgb(70, 255, 100, 100); // 半透明紅
text.FontSpec.Size = 100;
text.ZOrder = ZOrder.A_InFront; // 置於最上層
myMaster.GraphItemList.Add(text);
若改為 ZOrder.G_BehindAll,浮水印將隱藏在所有圖表之後。
Graphics g = this.ZedGraphControl.CreateGraphics();
myMaster.AutoPaneLayout(g, PaneLayout.ExplicitRow32); // 3 欄 2 列? 依枚舉定義
myMaster.AxisChange(g);
g.Dispose();
AutoPaneLayout 依指定模式自動排列子窗格大小與位置。