我已將註釋與數據點對齊;我想垂直對齊註釋。圖表註釋:我如何對齊沿着數據軸的註釋
我讀過這個,但不知道如何將圖表寬度與數據點關聯。 https://msdn.microsoft.com/en-us/library/dd456731.aspx
這:MS Charting Annotations refuse to align to mouse position
我添加了圖表的圖象到目前爲止,例如,
'create new chart
chart1 = New DataVisualization.Charting.Chart
'add chart areas
chart1.ChartAreas.Add("NewChartArea")
chart1.ChartAreas("NewChartArea").Area3DStyle.Enable3D = False
chart1.ChartAreas("NewChartArea").AxisX.MajorGrid.Enabled = False 'turn chart background grid on and off
chart1.ChartAreas("NewChartArea").AxisY.MajorGrid.Enabled = False 'turn chart background grid on and off
chart1.ChartAreas("NewChartArea").AxisX.Title = "Activities of daily living" '----> title on the bottom for the x axis
'[template] chart1.ChartAreas("NewChartArea").AxisX.LabelStyle.Angle = 45
'[template] Chart1.Series(SeriesZeroChartName).Label = " my own label" ' -----> adds a label at the top of each bar
For c As Integer = 2 To Me.DataGridViewResultsAdls.ColumnCount - 1
Dim NextSeriesChartName As String
NextSeriesChartName = DataGridViewResultsAdls.Columns(c).Name
chart1.Series.Add(NextSeriesChartName)
chart1.Series(NextSeriesChartName).ChartType = DataVisualization.Charting.SeriesChartType.Bar 'CHART CHANGER ****** change this value to change chart type
chart1.Series(NextSeriesChartName).Points.Clear()
chart1.Series(NextSeriesChartName).IsValueShownAsLabel = True '----> puts little labels ontop of each bar
chart1.Series(NextSeriesChartName).SmartLabelStyle.Enabled = True
' fill each subsequent series with points
For Count As Integer = 0 To DataGridViewResultsAdls.Rows.Count - 2
Dim NextColumnName As String
NextColumnName = DataGridViewResultsAdls.Columns(c).Name
' define X values
Dim XLabelMyCustom As String
XLabelMyCustom = DataGridViewResultsAdls.Item(0, Count).Value
'define Y values
Dim YLabelMyCustom As String
YLabelMyCustom = DataGridViewResultsAdls.Item(NextColumnName, Count).Value
' add the point to the chart
chart1.Series(NextSeriesChartName).Points.AddXY(XLabelMyCustom, YLabelMyCustom)
' create custom labels for the x axis
chart1.ChartAreas("NewChartArea").AxisX.CustomLabels.Add(Count + 0.5, Count + 0.4 + 0.5, "Q2", 0, DataVisualization.Charting.LabelMarkStyle.None)
chart1.ChartAreas("NewChartArea").AxisX.CustomLabels.Add(Count + 0.5 + 0.5, Count + 0.9 + 0.5, "Q1", 0, DataVisualization.Charting.LabelMarkStyle.None)
chart1.ChartAreas("NewChartArea").AxisX.CustomLabels.Add(Count + 0.5, Count + 1, "Q3", 2, DataVisualization.Charting.LabelMarkStyle.LineSideMark)
'Create a variable MyDataPoint to hold the current datapoint
Dim MyDataPoint As DataPoint
MyDataPoint = chart1.Series(NextSeriesChartName).Points(Count)
'Create a new text annotation
Dim MyTextAnnotation As TextAnnotation
MyTextAnnotation = New TextAnnotation
MyTextAnnotation.Text = "some notation"
'[template] MyTextAnnotation.X = <---- sets coordinates on screen for x
'[template ]MyTextAnnotation.Y = <---- sets coordinates on screen for y
'[template] MyTextAnnotation.AnchorDataPoint = MyDataPoint 'sets the point where the notation will be
'[template] chart1.Annotations.Add(MyTextAnnotation) ' adds the notation to the chart
' only add annotations to the chart once per series
If c = 2 Then
MyTextAnnotation.AxisY = chart1.ChartAreas("NewChartArea").AxisY
' [template] chart1.Series(NextSeriesChartName).Points.Item(Count).ToString <--- output points to a string {x,y}
MyTextAnnotation.AnchorDataPoint = MyDataPoint 'sets the point where the notation will be
chart1.Annotations.Add(MyTextAnnotation) ' adds the notation to the chart
MyTextAnnotation.AnchorOffsetX = -10
End If
Next
Next
'Add chart to control and set dock to fill
Me.PanelChartAdls.Controls.Add(chart1)
chart1.Dock = DockStyle.Fill
End If
你可以在你的截圖中繪製你想要的位置嗎? (Nice [Red Circles](http://meta.stackexchange.com/questions/19478/the-many-memes-of-meta),btw ..) - 你可能需要一些[Offset](https:// msdn .microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.annotation.anchoroffsety%28v = vs.110%29.aspx) – TaW
:)我做了,我想要註釋的位置是在黃色突出顯示:) 我嘗試使用偏移集,但我不確定如何準確計算它,因爲數據點使用圖表高度和寬度的%代表 –
此圖表上的x軸也是垂直的,因爲它是一個條形圖,所以繪圖點的X軸與圖表的高度有關 - 我認爲 –