首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

ZedGraph 教學(九):MasterSampleDemo 多窗格與 ZOrder 詳細解析(二)

     編輯:關於C語言

MasterPane:多圖表容器

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;

ColorSymbolRotator:自動分配顏色與符號

迴圈建立多個 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:繪圖層級控制

ZOrder 決定 GraphItem (文字、圖片、箭頭) 在 Z 軸 (前後疊加) 的順序。枚舉值由後至前:

枚舉值描述
G_BehindAll最底層,連標題都在它之上
F_BehindAxisFill座標軸背景填充之下
E_BehindAxis座標軸物件之下
D_BehindCurves曲線物件之下
C_BehindAxisBorder座標軸邊框之下
B_BehindLegend圖例之下
A_InFront最上層 (同層級以 GraphItemList 順序決定)

實戰:DRAFT 浮水印

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 依指定模式自動排列子窗格大小與位置。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved