图表中的标签 - 表格中的另一个字段 [英] Label in a chart - another field from the table
问题描述
亲爱的朋友
我需要在图表的每一列中添加标签,但此标签必须是表格中其他字段的值。
图表月(X)和值(Y),但我的标签必须是字段
" Rotul" 来自同一张桌子。
谢谢
夏洛特
这是一个使用自定义注释在任何地方添加文本的示例。
在示例中有两个数组。数组 Mz 中的值绘制在图表和数组中; Mt用于标签文本。我认为您应该能够根据自己的需求进行调整。
还有其他方法可以添加或修改标签,具体取决于您确切的应用程序的其余部分。但这是最常用的方式。
'绘制自定义注释示例
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form2
Dim Mz(5 )As Integer
Dim Mt(5)As String
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
InitializeChart( )
InputData()
DrawChart()
End Sub
Private Sub InitializeChart()
Chart1.Dock = DockStyle.Fill
Me.Chart1.Series.Clear()
Me.Chart1.Series.Add(" F")
Me.Chart1.Series(0).Color = Color。 SkyBlue
Me.Chart1.Series(0).ChartType = SeriesChartType.Column
使用Chart1.ChartAreas(0)
Chart1.ChartAreas(0).AxisX.Title =" ; Y"
Chart1.ChartAreas(0).AxisX.Maximum = 7
Chart1.ChartAreas(0).AxisX.Minimum = 0.0
Chart1.ChartAreas(0).AxisY.Title =" Z" ;
Chart1.ChartAreas(0).AxisY.Minimum = 0.0
Chart1.ChartAreas(0).AxisY.Maximum = 10
以
结束Sub
Private Sub InputData()
Mz(0)= 3
Mz(1)= 3
Mz(2)= 6
Mz(3)= 8
Mz(4)= 9
Mz(5)= 7
Mt(0)=" abc0"
Mt(1)=" abc1"
Mt(2)=" abc2"
Mt(3)=" abc3"
Mt(4)=" abc4"
Mt(5)=" abc5"
结束子
私人子DrawChart()
Chart1.Series(0).IsVisibleInLegend = False
我作为整数= 1到6
'使图表点数
Chart1.Series(0).Points.AddXY(i,Mz(i - 1))
'make每个图表点的图表anno pt来自第二个数组
Dim PC As New TextAnnotation
PC
'.CalloutStyle = CalloutStyle.SimpleLine
.ForeColor = Color.Maroon
.Font = New Font(" Tahoma",10)
.AnchorDataPoint = Chart1.Series(" F")。Points(i - 1)
.X = Chart1.Series(" ; F")。Points(i - 1).XValue - 0.7
.Y = Chart1.Series(" F")。Points(i - 1).YValues(0)
.Text = Mt(i - 1).ToString
Chart1.Annotations.Add(PC)
以
结尾下一个
结束次级
结束等级
Dears Friends
I need to put labels in each column of my chart, but this label need to be the value from another field from the table.
The chart is month(X) and value(Y), but my label need to be the field "Rotul" from the same table.
Thanks
Charlotte
Here is an example which uses custom annotations to add some text where ever you want.
In the example there are two arrays. The values in array Mz are plotted in the graph and array Mt is used for the label text. I think you should be able to adapt it for your desires.
There are other ways to add or modify the labels depending on the rest of your exact application. But this is the most general way.
'draw custom annotations example Imports System.Windows.Forms.DataVisualization.Charting Public Class Form2 Dim Mz(5) As Integer Dim Mt(5) As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load InitializeChart() InputData() DrawChart() End Sub Private Sub InitializeChart() Chart1.Dock = DockStyle.Fill Me.Chart1.Series.Clear() Me.Chart1.Series.Add("F") Me.Chart1.Series(0).Color = Color.SkyBlue Me.Chart1.Series(0).ChartType = SeriesChartType.Column With Chart1.ChartAreas(0) Chart1.ChartAreas(0).AxisX.Title = "Y" Chart1.ChartAreas(0).AxisX.Maximum = 7 Chart1.ChartAreas(0).AxisX.Minimum = 0.0 Chart1.ChartAreas(0).AxisY.Title = "Z" Chart1.ChartAreas(0).AxisY.Minimum = 0.0 Chart1.ChartAreas(0).AxisY.Maximum = 10 End With End Sub Private Sub InputData() Mz(0) = 3 Mz(1) = 3 Mz(2) = 6 Mz(3) = 8 Mz(4) = 9 Mz(5) = 7 Mt(0) = "abc0" Mt(1) = "abc1" Mt(2) = "abc2" Mt(3) = "abc3" Mt(4) = "abc4" Mt(5) = "abc5" End Sub Private Sub DrawChart() Chart1.Series(0).IsVisibleInLegend = False For i As Integer = 1 To 6 'make the chart points Chart1.Series(0).Points.AddXY(i, Mz(i - 1)) 'make a chart anno pt for each chart point from the second array Dim PC As New TextAnnotation With PC ' .CalloutStyle = CalloutStyle.SimpleLine .ForeColor = Color.Maroon .Font = New Font("Tahoma", 10) .AnchorDataPoint = Chart1.Series("F").Points(i - 1) .X = Chart1.Series("F").Points(i - 1).XValue - 0.7 .Y = Chart1.Series("F").Points(i - 1).YValues(0) .Text = Mt(i - 1).ToString Chart1.Annotations.Add(PC) End With Next End Sub End Class
这篇关于图表中的标签 - 表格中的另一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!