CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: MS Chart Help

  1. #1
    Join Date
    Nov 2007
    Posts
    5

    MS Chart Help

    I am working with MSChart. I took the example code off of Patric Johansson tutorial about MSChart and trying to make mine do the same thing. Here is a piece of his code:

    -------------------------------------------------------------
    axMSChart.ChartData = new Object[5, 4] {
    {null, "Computer A","ComputerB", "Computer C"},
    {"10:00 AM", 123131, 242142, 254353},
    {"10:01 AM", 113121, 171345, 205432},
    {"10:02 AM", 126323, 281876, 269743},
    {"10:03 AM", 199833, 242122, 283445}};

    --------------------------------------------------------------

    What I want to do is get my arrays in the above format.
    My results from the array will be (these are examples)

    12-Jul-2007, 10:00 am, HGB, 10.5
    12-Jul-2007, 10:00 am, HCT, 31.0
    12-Jul-2007, 11:00 am, HGB, 12.0
    12-Jul-2007, 11:00 am, HCT, 36.0
    13-Jul-2007, 12:00 am, HGB, 12.5
    13-Jul-2007, 12:00 am, HCT, 37.0
    15-Aug-2007, 11:15 am, HGB, 14.0
    15-Aug-2007, 11:15 am, HCT, 42.1

    ...and so on. They can have different dates, times and results.

    I want it to look like:

    {null, "HGB","HCT"},
    {12-Jul-2007, "10:00 AM", "10.5", "31.0"},
    {12-Jul-2007, "11:00 AM", "12.0", "36.0"},
    {13-Jul-2007, "12:00 AM", "12.5", "37.0"},
    {15-Jul-2007, "11:15 AM", "14.0", "42.1"}};

    What I am trying to achieve is a 3d bar chart with the date and time on the X-Axis, the result on the Y-Axis and the tests, HGB and HCT on the Z-Axis. I can't get it to work. What happens now is:

    Each test (hgb and hct) show up on a separate column with the date/time on the X-axis and the result shows up on the Y-Axis. I can't get a Z-Axis with the two tests on it.


    My piece of code is below..
    ======================================

    try
    {
    SqlCommand cmd = new SqlCommand(
    "Select Count(*) " +
    "From LabDB " +
    "Where l.name in ('HGB', 'HCT') ",conn);

    int arraySize = Convert.ToInt32(cmd.ExecuteScalar());

    cmd.CommandText = "Select l.date as resultDate, " +
    l.time as resultTime, " +
    itemname = case " +
    "when l.name = 'HGB' " +
    "then 'Hemoglobin' " +

    "when l.name = 'HCT' " +
    "then 'Hematocrit' " +
    "end, " +
    "l.value as result " +
    "From LabDB " +
    "Where l.name in ('HGB', 'HCT') ",conn);
    "Order by l.resultDate desc, itemname ";

    SqlDataReader dr = cmd.ExecuteReader();

    string [,] ptInfo = new string [arraySize, 4];
    int i = 0;

    if ( null != dr )
    {
    while (dr.Read() & i < arraySize)
    {
    ptInfo[i, 0] = dr["itemname"].ToString();
    ptInfo[i, 1] = dr["resultDate"].ToString();
    ptInfo[i, 2] = dr["resultTime"].ToString();
    ptInfo[i, 3] = dr["result"].ToString();

    axMSChart1.ChartData = ptInfo;
    i += 1;
    }
    dr.Close();
    }
    }
    =================================================
    Can anyone help?

    Thanks,
    Tony
    Last edited by eusanpe; November 11th, 2007 at 06:05 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: MS Chart Help

    Did you copy that right? Don't you want WHERE instead of WHEN?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2007
    Posts
    5

    Re: MS Chart Help

    Thank you for the reply...

    Yes I did copy it right. That is what I have in my Select statement. Should it be 'where' instead of 'when'.


    Tony

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

Featured