偏偏這次是寫winForm只好拿mschart出來刻了。
有幾個重點的備註一下。
在做chart的時候有發現,控制項跟裡面的區域沒有塞滿。
後來才發現是auto的關係,現在強制指定變成95跟94,這是百分比。
要讓X軸從0開始,要設定最小 minimum=0,不然都是從1開始
dataChart.Series("Series1").Points.Clear()
dataChart.ChartAreas.Clear()
dataChart.ChartAreas.Add("ChartArea1")
Dim arrWT As Decimal() = CommonHelp.GetTypeStd(txtStd.Text)
Dim intWT_std = arrWT(0), intWT_T = arrWT(1)
Dim ChtLSL = intWT_std - intWT_T, ChtTGT = intWT_std, ChtUSL = intWT_std + intWT_T
Dim chartMin = chartRange(intWT_T)(0), chartMax = chartRange(intWT_T)(1)
'設定MainCht
With dataChart
.Series("Series1").MarkerStyle = MarkerStyle.Circle
.ChartAreas(0).AxisX.MajorGrid.Enabled = False
.ChartAreas(0).AxisY.MajorGrid.Enabled = False
.ChartAreas(0).AxisX.MajorTickMark.Enabled = False
.ChartAreas(0).AxisY.MajorTickMark.Enabled = False
.ChartAreas(0).AxisX.LabelStyle.ForeColor = Color.Black
.ChartAreas(0).InnerPlotPosition.Auto = True
.Legends.Clear()
'最大、最小
.ChartAreas(0).AxisY.Minimum = ChtLSL - 20
.ChartAreas(0).AxisY.Maximum = ChtUSL + 20
'把圖表駔標的左右兩邊空白去除
.ChartAreas(0).AxisX.IsMarginVisible = True
.ChartAreas(0).AxisY.IsMarginVisible = True
'X軸最大的資料點總數
.ChartAreas(0).AxisX.Maximum = 100
'X軸從0開始
.ChartAreas(0).AxisX.Minimum = 0
.ChartAreas(0).AxisX.Interval = 10
'塞滿mschart
.ChartAreas(0).Position.Width = 95
.ChartAreas(0).Position.Height = 90
''Y軸標籤
'first row are dummy labels to suppress axis numberics
'.ChartAreas(0).AxisY.CustomLabels.Add(30, 40, "", 0, LabelMarkStyle.LineSideMark)
.ChartAreas(0).AxisY.CustomLabels.Add(ChtLSL, ChtLSL + 1, "LSL(" & ChtLSL.ToString & ")") 'LSL
.ChartAreas(0).AxisY.CustomLabels.Add(ChtTGT, ChtTGT + 1, "TGT(" & ChtTGT.ToString & ")") 'TGT
.ChartAreas(0).AxisY.CustomLabels.Add(ChtUSL, ChtUSL + 1, "USL(" & ChtUSL.ToString & ")") 'USL
.ChartAreas(0).AxisY.LabelAutoFitStyle = LabelAutoFitStyles.None
'Set series chart type
.Series("Series1").ChartType = SeriesChartType.Point
''加橫線
For LineRow As Integer = 1 To 3
Dim sl1 As StripLine = New StripLine
sl1.BackColor = Color.Black
sl1.StripWidth = 0.25
Select Case LineRow
Case 1
sl1.IntervalOffset = ChtLSL
Case 2
sl1.IntervalOffset = ChtTGT
Case 3
sl1.IntervalOffset = ChtUSL
End Select
.ChartAreas(0).AxisY.StripLines.Add(sl1)
Next
End With
0 意見:
張貼留言