dcsimg
Results 1 to 5 of 5

Thread: Chart not showing series name

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    83

    Chart not showing series name

    Dear all,
    I have a chart with 4 series bounded to it.
    The names of the series are got from a specific string column of the datatable which is bound to the chart through a selection in a databox. Here below the code that is loading data to the chart for the first series (the other three are the same):

    Code:
    Private Sub Cmb1_SelectedValueChanged(sender As Object, e As EventArgs) Handles Cmb1.SelectedValueChanged
    
            ConfrontoDataTable1.Columns("Nome_Cognome").Expression = "Nome + ' ' + Cognome"
    
            If IsNothing(Cmb1.SelectedValue) Then
                Me.Label17.Text = "-"
                Me.Label16.Text = "-"
                Me.Label15.Text = "-"
                Me.Label14.Text = "-"
                Me.Label13.Text = "-"
                Me.Label12.Text = "-"
    
            Else
                Me.Label17.Text = CDec(CType(Cmb1.SelectedItem, DataRowView)("Media_1"))
                Me.Label16.Text = CStr(CType(Cmb1.SelectedItem, DataRowView)("Media_2"))
                Me.Label15.Text = CStr(CType(Cmb1.SelectedItem, DataRowView)("Media_3"))
                Me.Label14.Text = CStr(CType(Cmb1.SelectedItem, DataRowView)("Media_4"))
                Me.Label13.Text = CStr(CType(Cmb1.SelectedItem, DataRowView)("Media_5"))
                Me.Label12.Text = CStr(CType(Cmb1.SelectedItem, DataRowView)("Media_6"))
    
                Dim selectedRow1() As DataRow = ConfrontoDataTable1.Select(String.Format("Codice_pers= '{0}'", Me.Cmb1.SelectedValue))
                For Each dr As DataRow In selectedRow1
                    Me.Chrt1.Series("Series1").Points.AddXY(dr("Nome_Cognome"), dr("Media_1"))
    The problem here is that for the first series the chart shows on X axis the name of the series (so the corresponding selected value of the column Nome_Cognome, while this is not happening for the other 3 series.

    I'm not sure whether I'm doing something wrong with the code and/or I'm missing any kind of specific configuration in the chart series and/or I should add something to the code.

    Anybody who has any suggestion or has experienced anything similar in the past?

    Thanks,
    A.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Chart not showing series name

    I dont see any code that puts the series name on the chart? What is the series name on the cart a label? A title? Where in your code is the label or title added to the chart? Am I missing it?

    If you use a legend then the series name should appear for each in the legend.

    You say the first series shows the name properly but the other series do not. Where is the code for showing the name in the first series?

    Show an image of the result you get with your code now (and the code) and the result you want to get.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    83

    Re: Chart not showing series name

    Dear tommytwotrain,
    you cannot see any code that puts the series name on the chart exactly because I didn't write any code.
    I've just configured the chart area/series on the Property window of the chart and my surprise is that for the first series I can see the label on the X axis while for the others nothing. I was wondering whether possibly I could have missed any setting in the labels definitions for the other series...

    In any case, please find here below a printscreen of the chart which is showing in the middle the "Me.Cmb1.SelectedValue". On the right you can see also the column of the second series, but you can see that the "Me.Cmb2.SelectedValue" is not shown.

    Name:  Result.png
Views: 33
Size:  4.8 KB

    Please do let me know whether you need any other check from my side.

    Thanks,
    A.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Chart not showing series name

    Quote Originally Posted by AndreB82 View Post
    Dear tommytwotrain,
    you cannot see any code that puts the series name on the chart exactly because I didn't write any code.
    I've just configured the chart area/series on the Property window of the chart and my surprise is that for the first series I can see the label on the X axis while for the others nothing. I was wondering whether possibly I could have missed any setting in the labels definitions for the other series...

    In any case, please find here below a printscreen of the chart which is showing in the middle the "Me.Cmb1.SelectedValue". On the right you can see also the column of the second series, but you can see that the "Me.Cmb2.SelectedValue" is not shown.
    A.
    It is not clear exactly what you mean? You need to use the exact words and images to describe exactly what you mean.

    "for the first series I can see the label on the X axis while for the others nothing"

    What does that mean? Which "label are you talking about? The control you have in your code? The label over the series item? The x axis grid value label? Show the label in the image if required.

    The first thing you should do is learn what the "things" are and what they do.

    This samples program shows how most things work. It is a c# project you run in visual studio (just like a vb project). It has the best set of docs for the chart. Get it and run it.

    https://code.msdn.microsoft.com/Samp...s-for-b01e9c61

    This is from the above samples:

    Name:  a.png
Views: 31
Size:  55.3 KB

    The way the chart and things like this work is you have to make sure a thing is turned on (some are on by default). Then put a value in the thing ie a series can be named when it is declared so in the examp;le for series index 0 the name is "series one" etc:

    Then the names are shown in the ledgend thats what it does.

    https://docs.microsoft.com/en-us/dot...tframework-4.8

    If you dont want a series name shown in the legend you can turn it off as for series index 2 named "Series Two" in the example. See how 2 is not in the legend upper right?

    So you have to work through those those things one at a time to learn how they work.

    Here is an example that does what you want? See how the various labels are made and etc??

    Name:  a1.png
Views: 30
Size:  20.9 KB

    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form3
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'setup the chart area graphics
            With Chart1.ChartAreas(0)
                .AxisX.Title = "X axis"
                .AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold)
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Interval = 2
    
                .AxisY.Title = "Y axis"
    
                .BackColor = Color.FloralWhite  'AntiqueWhite 'LightSkyBlue
                .BackSecondaryColor = Color.White
                .BackGradientStyle = GradientStyle.HorizontalCenter
                .BorderColor = Color.Blue
                .BorderDashStyle = ChartDashStyle.Solid
                .BorderWidth = 1
                .ShadowOffset = 2
            End With
    
            'make titel
            Chart1.Titles.Add("Title 1")
            Chart1.Titles(0).Text = "Chart Title"
    
            'make the series
            Chart1.Series.Clear()
            Chart1.Series.Add("Series Zero")
            Chart1.Series.Add("Series One")
            Chart1.Series.Add("Series Two")
    
            With Chart1.Series(0)
                'define the series styles
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
                .BorderWidth = 1
                .Color = Color.Red
                .BorderDashStyle = ChartDashStyle.Dash
                .MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
                .MarkerSize = 4
                .Font = New Font("Arial", 9, FontStyle.Bold)
                .IsValueShownAsLabel = True                  'add point value labels to top of column
                .LabelFormat = "f0"                          'show label as one decimal place ie  XXX.X 
                .LabelForeColor = Color.Green             'point label color
            End With
    
            Chart1.Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(1).Color = Color.Blue
            Chart1.Series(2).ChartType = DataVisualization.Charting.SeriesChartType.Line
            Chart1.Series(2).Color = Color.Purple
            Chart1.Series(2).IsVisibleInLegend = False  'dont show this one in legend
    
            'add the data series
            For x = 1 To 9
                Chart1.Series(0).Points.AddXY(x, x - 1)
                Chart1.Series(1).Points.AddXY(x, 2 * x)
                Chart1.Series(2).Points.AddXY(x, 3 * x)
            Next
    
        End Sub
    End Class

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2018
    Posts
    83

    Re: Chart not showing series name

    Dear tommytwotrain,
    first of all thanks for the explanation and for the material. I'm going to check it all right now.
    In the meanwhile, as I see the picture and I realized I didn't make myself clear enough, let me explain comparing my picture to yours.
    In the chart you posted I can see labels like: "John", "Mary", "Jeff", "Bob". They are exactly what I would like to show in my chart. The issue I'm having is that actually my chart, even if it should show "Andrea Semenza" and "Elio Zalli", it's only showing "Andrea Semenza" under both the series displayed (the value for Andrea Semenza is 2,57, while the value for Elio Zalli is 2,71 - the bar is shown in the chart, but not the name...).

    Hope to have been clear this time. Thanks for your support.

    Thanks,
    A.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width