1

I want to plot a graph where in the X axis should appear the name of some production lines, and in the Y axis the total time the lines were stopped (E.G: 110:43:00h) but i'm having some problems. Here's my code:

Dim cmd As New MySqlCommand
Chart2.Series.Add("Stops")
Try
    ConnectDatabase()
    With cmd
        .Connection = conn
        .CommandText = "SELECT X as lines, time_format(SEC_TO_TIME(SUM(abs(TIME_TO_SEC(timediff(Y, Z))))),'%H:%i:%s') AS SUM FROM M, N WHERE a = b GROUP BY P"
    End With
    Dim objReader As MySqlDataReader = cmd.ExecuteReader
    While objReader.Read
        Chart2.Series("Stops").Points.AddXY(objReader("lines").ToString, objReader("SUM").ToString)
    End While
Catch ex As Exception
    If ex.InnerException IsNot Nothing Then
        MsgBox(ex.InnerException)
    End If
End Try
DisconnectDatabase()

The MySQL query is correct, and i can see the X axis correctly, but in the Y axis nothing appears, and it doesn't plot anything. Can you please help? What am i doing wrong?

There's a print of how SUM looks like: enter image description here

Thanks.

UPDATE: Problem solved. In the select query i just select the data in Hours.

vallete7
  • 113
  • 1
  • 11
  • Would it be possible to see the structure of the query result? I'm just wondering if because SUM is a keyword if that is throwing up an issue. A quick test would be to change that to something other than SUM and fix the series argument to reflect the change. – Charles May Feb 01 '16 at 14:30
  • I made a test and changed the axis, i mean, i putted SUM in the X axis and the lines in the Y axis. The SUM appears and the name lines no. So the problem need to be in the Y axis but i'm not figuring out why... – vallete7 Feb 01 '16 at 14:37
  • so a typical SUM result would be something like '110:43:00h'? Because it's looking for a numerical value. If that represents 110 hours and 43 minutes you may need to get that into a number that represents it 110.72 which is 110.72 hours or 110 hours and 43/60 hours. – Charles May Feb 01 '16 at 14:47
  • Check the image i put in the question. – vallete7 Feb 01 '16 at 14:50
  • OK, so what does a typical sum look like? (The value you're passing into the y axis) because that looks like you're trying to pass a non-numeric value to the y-axis. – Charles May Feb 01 '16 at 14:56
  • Didn't get your point. Why can i show SUM in the X axis and not in the Y axis? – vallete7 Feb 01 '16 at 14:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102260/discussion-between-charles-may-and-vallete7). – Charles May Feb 01 '16 at 14:59
  • Click on the link in the last comment to continue this in the chat room. – Charles May Feb 01 '16 at 15:15

1 Answers1

0

Make your y-values numeric instead of strings.

Change

Chart2.Series("Stops").Points.AddXY(objReader("lines").ToString, objReader("SUM").ToString)

to

Chart2.Series("Stops").Points.AddXY(objReader("lines").ToString, Double.Parse(objReader("SUM").ToString))
djv
  • 15,168
  • 7
  • 48
  • 72
  • Check out this solution http://stackoverflow.com/questions/6624066/how-to-set-values-in-x-axis-mschart-using-c-sharp – djv Feb 02 '16 at 15:50