Add labels to ZED graph

  • Robi55

    I'm using this code::
    Imports ZedGraph
    Public Class Form1

    Private Sub CreateGraph(ByVal zg1 As ZedGraphControl)
        Dim myPane1 As GraphPane = zg1.GraphPane
        myPane1.Title.Text = "Title A"
        myPane1.XAxis.Title.Text = "xtext"
        myPane1.YAxis.Title.Text = "ytext"
        Dim labels As String() = {"label1", "label2", "label3", "label4", "label5"}
        Dim y As Double() = {100, 75, 11, 22, 3}
        ' Dim y As Double() = {100, 115, 75, 22, 98, 40}
        Dim y2 As Double() = {90, 100, 95, 35, 80, 35}
        Dim y3 As Double() = {80, 110, 65, 15, 54, 67}
        Dim y4 As Double() = {100, 100, 90, 40, 105, 75}
        ' Generate a red bar with "Curve 1" in the legend
        Dim myBar As BarItem = myPane1.AddBar("mytext", Nothing, y, Color.Transparent)
        myBar.Bar.Fill = New Fill(Color.Red, Color.Yellow, Color.Red)
        ' ' Draw the X tics between the labels instead of at the labels
        myPane1.XAxis.MajorTic.IsBetweenLabels = True
        '' Set the XAxis labels
        myPane1.XAxis.Scale.TextLabels = labels
        ' ' Set the XAxis to Text type
        myPane1.XAxis.Type = AxisType.Text
        '' Fill the Axis and Pane backgrounds
        myPane1.Chart.Fill = New Fill(Color.White, Color.FromArgb(255, 255, 166), 90.0F)
        myPane1.Fill = New Fill(Color.FromArgb(250, 250, 255))
        '' Tell ZedGraph to refigure the
        '' axes since the data have changed
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    End Sub
    Private Sub SetSize()
        zg1.Location = New Point(10, 10)
        zg1.Size = New Size(1200, 350)
    End Sub

    End Class

    Above each bar a bar's Y-value should be marked with labels (as shown in the figure).
    How to do this? How do I choose the font size and color of these labels?
    Thanks in advance.

    alternate text

  • Robi55

    I found in meantime next:
    ' Create TextObj's to provide labels for each bar
    BarItem.CreateBarLabels(myPane1, False, "f0")
    but, these label are always shown as integers. That's something I want to avoid.
    I get a Y-values by code and they are decimals rounded to 2 decimals and it would be nice if the bar label shows the decimal number as is instead of rounded integer.
    Is that possible?

    Last edit: Robi55 2013-10-06
  • Robi55

    I found this solution:
    BarItem.CreateBarLabels(myPane1, False, "f2")