dcsimg
Results 1 to 8 of 8

Thread: Plotting a stacked column graph

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    41

    Plotting a stacked column graph

    Hi all,

    I am monitoring a device every hour to check whether it is on or off, and if it is on, I set a value to 1 and if it is off, I set it to 0. I want to be able to plot this as a stacked column, plotting day 1 next to day 2 and so on. I have come up with a simple function that simulates a few days of data

    Code:
    Function gettable() As DataTable
            Dim table As New DataTable
            table.Columns.Add("Day1", GetType(Integer))
            table.Columns.Add("Day2", GetType(Integer))
            table.Columns.Add("Day3", GetType(Integer))
            table.Columns.Add("Day4", GetType(Integer))
            table.Columns.Add("Day5", GetType(Integer))
            table.Columns.Add("Day6", GetType(Integer))
    
            table.Rows.Add(0, 1, 1, 1, 0, 0)
            table.Rows.Add(1, 1, 1, 1, 0, 0)
            table.Rows.Add(1, 1, 1, 1, 0, 1)
            table.Rows.Add(1, 1, 1, 1, 0, 1)
            table.Rows.Add(1, 0, 1, 0, 1, 1)
            table.Rows.Add(1, 0, 0, 0, 1, 1)
            table.Rows.Add(1, 0, 0, 0, 1, 1)
    
            Debug.WriteLine("Rows: " & CStr(table.Rows.Count))
    
    
            Return table
    
        End Function
    I can reorder this so it is orthogonal if required (i.e. swap days for hours), but from the function above, what I'd like to see in the first column is a red block at the bottom, with green to the top, in the 2nd, green up to about 1/2 and then red, and so on. I'm really struggling with this because I can't make sense of the graphing routines at all. If anyone has any idea how I could achieve this, that would be great.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Plotting a stacked column graph

    I'm really struggling with this because I can't make sense of what this graph is intended to show. What you say you'd 'like to see', unless I'm being really thick (and I have got a bad case of laryngitis, a stuffed up head, and severely aching limbs so that's entirely possible!) doesn't seem to bear any relation to the data and more specifically the kind of data that you have collected. A picture would probably paint a thousand words here!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    41

    Re: Plotting a stacked column graph

    Quote Originally Posted by dunfiddlin View Post
    I'm really struggling with this because I can't make sense of what this graph is intended to show. What you say you'd 'like to see', unless I'm being really thick (and I have got a bad case of laryngitis, a stuffed up head, and severely aching limbs so that's entirely possible!) doesn't seem to bear any relation to the data and more specifically the kind of data that you have collected. A picture would probably paint a thousand words here!
    It would take ages to draw! I'll try this, and if still no good, then I will get paint out!

    Code:
    table.Rows.Add("6", 1, 1, 1, 0, 0)
            table.Rows.Add("5", 1, 1, 1, 0, 0)
            table.Rows.Add("4", 1, 1, 1, 0, 1)
            table.Rows.Add("3", 1, 1, 1, 0, 1)
            table.Rows.Add("2", 0, 1, 0, 1, 1)
            table.Rows.Add("1", 0, 0, 0, 1, 1)
            table.Rows.Add("0", 0, 0, 0, 1, 1)
    the first column shows the hour in each day (each column after that is a day's data), and after that each column shows whether the device is on or off in that hour. If this were a stacked column, all the "0" would be red and all the "1" would be green.

    does that make sense?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Plotting a stacked column graph

    Well kinda. But then that's not really a chart at least in the conventional sense of needing a chart control. You could do this far more easily in say a Datagridview where you simply change the backcolor (or image if you want to get really fancy) of each cell according to the value. You have after all already made this a table, you might as well display it as such.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    41

    Re: Plotting a stacked column graph

    That could work I suppose. The problem is if the data gets really dense, for example if I am gathering it several times an hour for many days:

    It would become hard to see clearly without the various axes and such.

    here's an example ( I did this one with MatLab) that goes for 30 days

    Name:  sample.png
Views: 96
Size:  244.4 KB

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Plotting a stacked column graph

    if I am gathering it several times an hour for many days
    .... then you're not checking it every hour as you said in your original post and suggested in the code example. It's kinda difficult to offer the best solution if you move the goalposts.

    If what you're looking for is actually the latter then you might well be better off simply drawing this directly using GDI+. It is after all nothing but a bunch of rectangles. Having said that, as a chart it is somewhat inaccurate suggesting that the periods are continuous where actually you only know the state at specific sampling points. A bit pedantic perhaps but it rather depends on what this chart is actually to be used for.

    It would become hard to see clearly without the various axes and such.
    You have both row and column headers available in a DGV. More than adequate replacements for the axes.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2013
    Posts
    41

    Re: Plotting a stacked column graph

    I figured out a way to do what I want with the graph in the end, but it means pre-interpreting all the data, so now I have On-7 off-3 and so on for each day and then plot 'on' for each day as a series, then 'off' for each day. I do however have gaps between the columns like above. Is there a way to get rid of those? I may want to change the number of days displayed though.

    thanks!

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Plotting a stacked column graph

    Personally I'd rather gnaw my own arms off than use the chart control in most situations so truth is I don't know. I'd advise against it though even if it is possible because it will be come a very busy graphic if colours are running into each other (red and green's already a bold choice!).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

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