Results 1 to 4 of 4

Thread: MsChart

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2019


    I have a chart that brings in cost from different categories.
    My problem is i want to use the Y value in one column ("Revenue") and use it in a calculation in one of the other columns is.. "Field"
    I've tried putting the data into an array, but when i hover over the Field column, each one is the same?
    The temp variable is declared as a Public variable.. Public temp() as Double
                            sql = "select sum(amount)amount from ticket_info left join rpt_date_info on rpt_date_info.Date = ticket_info.Date left join customers on customers.idcustomers = ticket_info.company where pay_period = '" & payperiod & "' and Pay_Year = '" & Payyear & "'"
                        Catch es As Exception
                            ' Response.Write(" < Script > alert('Error');</script>")
                        End Try
                        dbcomm = New MySqlCommand(sql, dbconn)
                        dbread = dbcomm.ExecuteReader()
                    While dbread.Read()
                            Revenue = dbread("amount")
                        Catch ex As Exception
                        End Try
                    End While
                        'Revenue = QShop + QField + QTravel + QStandby + QSalary
                        Chart1.ChartAreas(0).AxisY2.LineColor = Drawing.Color.Transparent
                        Chart1.ChartAreas(0).AxisY2.MajorGrid.Enabled = False
                        Chart1.ChartAreas(0).AxisY2.Enabled = AxisEnabled.True
                        Chart1.Series("Revenue").YAxisType = AxisType.Secondary
                        Chart1.ChartAreas(0).AxisY2.IsStartedFromZero = Chart1.ChartAreas(0).AxisY.IsStartedFromZero
                        Chart1.Series.Item("Revenue").Points.AddXY(previous.AddDays(6), (Revenue))
                        Chart1.Series.Item("Shop").Points.AddXY(previous.AddDays(6), (QShop))
                        Chart1.Series.Item("Field").Points.AddXY(previous.AddDays(6), (QField))
                        Chart1.Series.Item("Travel").Points.AddXY(previous.AddDays(6), (QTravel))
                        Chart1.Series.Item("SalaryHrs").Points.AddXY(previous.AddDays(6), (QSalary))
                        Chart1.Series.Item("Standby").Points.AddXY(previous.AddDays(6), (QStandby))
                            temp = (Chart1.Series("Revenue").Points(y).YValues)
                        Catch ex As Exception
                        End Try
                        Chart1.Series("Shop").ToolTip = "Shop :" & Environment.NewLine & "#VALY{C0}" & Environment.NewLine & ((QShop / temp(0)) * 100)
                        Chart1.Series("Field").ToolTip = "Field :" & Environment.NewLine & "#VALY{C0}" & Environment.NewLine & ((QField / temp(0)) * 100)
                        Chart1.Series("Travel").ToolTip = "Travel :" & Environment.NewLine & "#VALY{C0}" & Environment.NewLine & ((QTravel / temp(0)) * 100)
                        Chart1.Series("SalaryHrs").ToolTip = "Salary :" & Environment.NewLine & "#VALY{C0}" & Environment.NewLine & ((QSalary / temp(0)) * 100)
                        Chart1.Series("Standby").ToolTip = "Standby :" & Environment.NewLine & "#VALY{C0}" & Environment.NewLine & ((QStandby / temp(0)) * 100)
                        Chart1.Series("Revenue").ToolTip = "#VALY{C0}"
                        Chart1.Series("Revenue").LabelForeColor = Drawing.Color.Transparent
                        Chart1.Series("Revenue").Color = System.Drawing.Color.DarkViolet
                        ' Next
                    Catch ex As Exception
                    End Try
                    If sqlresult = 1 Then Exit Sub
                    y = y + 1
    Trying to display the percentage of the Field column in relationship to the Revenue column.
    The revenue column is the purple one, and the Field column is the 1st Blue.. Problem is that once the chart is populated, all the dates have the proper $ values, but all the same percentages at each period in time.

    Name:  Screenshot (12).jpg
Views: 177
Size:  18.2 KB
    Last edited by Crog1959; Nov 8th, 2019 at 12:02 PM. Reason: add code tags

  2. #2
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Skunthorpe, North Lincolnshire, England.

    Re: MsChart

    Hi Crog1959,

    We'll need to see all your code if we're to help.

    Last edited by Poppa Mintin; Nov 15th, 2019 at 06:26 AM.
    Along with the sunshine there has to be a little rain sometime.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2019

    Re: MsChart

    Any one? do i need more data posted?

  4. #4
    Frenzied Member
    Join Date
    Jul 2011

    Re: MsChart

    I can see a Next statement, but can't see any For statement. Looks like the code you have given is part of a loop that adds points to the various Chart Series.

    If that's the case, then a lot of the code shown is in the wrong place. Only the code that affects the point data should be inside the loop; the code that affects the axes properties and the series tooltips should be outside the loop.

    As it stands the axes properties and the series tooltips are being repeatedly modified in a tight loop. It's only the values form the last iteration of the loop that will have any long lasting effect, which is why you are seeing all the same percentage values, because they are all being calculated from the final point data values.

    I'm not a Chart guru and I don't know if there are any "magic" words (like #VALY etc.) that can be used to retrieve point data from parallel series, so if it were me I'd set the tooltip for each Point, not for the series a a whole.

    The AddXY method is a function that returns the index of the point in the series' point collection. you can use that index to set the tooltip for the point itself. Something like (I'm assuming here that Revenue, QShop, etc. are numeric types, and not Strings to begin with) :
    Dim thisDataPointIndex As Integer
    'Revenue = QShop + QField + QTravel + QStandby + QSalary
    thisDataPointIndex = Chart1.Series.Item("Revenue").Points.AddXY(previous.AddDays(6), (Revenue))
    Chart1.Series.Item("Revenue").Points(thisDataPointIndex).ToolTip = Revenue.ToString
    thisDataPointIndex = Chart1.Series.Item("Shop").Points.AddXY(previous.AddDays(6), (QShop))
    Chart1.Series.Item("Shop").Points(thisDataPointIndex).ToolTip = "Shop :" & Environment.NewLine & QShop & Environment.NewLine & (QShop / Revenue).ToString("P")

Posting Permissions

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


Click Here to Expand Forum to Full Width