Pages - Menu

2019年11月28日 星期四

[MsChart]參數設定

前言

弄MsChart的時候,搞了太多的參數,
不寫一下又怕到時忘記



正文

1.設定ChartArea區域的範圍


chart.ChartAreas[0].Position = new ElementPosition(2, 5, 83, 90);

表示從座標(2,5)開始畫 寬度 83 高度90的圖

2.不顯示XY軸格線


chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

3.設定Series顏色


chart.Series[0].Color = Color.Orange;

如果想要更炫一點,可使用調色版,多種顏色混搭

chart.Series[0].Palette = ChartColorPalette.BrightPastel;

4.顯示座標的數值標籤


chart.Series[0].IsValueShownAsLabel = false;

5.不顯示XY軸的標籤


chart.ChartAreas[0].AxisX.CustomLabels.Add(new CustomLabel());
chart.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel());

6.資料繫結

通常…直接指定 datasource跟datatable 就好。
但如果碰到很奇怪的問題,兩個關連後,產生圖表,X軸整個走鍾。
可以改用DataBindXY(x,y)的方式

List<int> x = new List<int>();
List<int> y = new List<int>();
foreach (DataRow row in dtContouring.Rows)
{
    DateTime dtime = (DateTime)row[0];
    int Contouring = Convert.ToInt16(row[1]);
    int angle = Convert.ToInt16(row[2]);
    int location = 0;
    if (angle >= 0 && angle < 90)
        location = angle;
    else if (angle >= 90 && angle < 180)
        location = -(90 - (180 - angle));
    else if (angle >= 180 && angle < 270)
        location = -(270 - angle);
    else if (angle >= 270 && angle < 360)
        location = 90 - (360 - angle);
    x.Add(Contouring);
    y.Add(location);
    labels.Add(angle);
}
chartTE.Series[0].Points.DataBindXY(x,y);
chartTE.DataBind();


ref.英文顏色比對網站-WPF & C# - Color Name Table (컬러 / RGB / 색상)

沒有留言:

張貼留言