Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
senatorx
Level III

Validate Graph output is not blank before saving

Hey,

I am creating graphs with multiple "Where" conditions that can result in no output, depending on the contents of the data file.

Where(:Column 1 == "string1" & :Column 2 == "string2" & :Column 3 == "string3")

If I then try to save a graph that is blank, the script crashes:

GraphName <<  /*###*/save picture( SaveString, png ) /*###*/;

How can I validate that the Graph contains data prior to attempting to save it?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
pmroz
Super User

Re: Validate Graph output is not blank before saving

I would use something like:

dt << clear row states;

selected_rows = dt << get rows where(:Column 1 == "string1" &

                                     :Column 2 == "string2" &

                                     :Column 3 == "string3");

if (nrows(selected_rows) > 0,

    dt << select rows(selected_rows) << invert row selection

       << exclude << clear select;

   

    .

    .

//    Create your graph here

    .

    .

);

View solution in original post

3 REPLIES 3
Highlighted
ms
Super User ms
Super User

Re: Validate Graph output is not blank before saving

Do you mean that the graph does not exist or that you have a graph but no data points (i.e. only missing values)?

Anyway, I would use a conditional statement that that is proactive, i.e. all "where" conditions that has too few data are ignored and never graphed. That's seems simpler and more efficient than to identify blank graphs in retrospect.

senatorx
Level III

Re: Validate Graph output is not blank before saving

I am doing this:

New Window("chart name",

CC = Control Chart(

  Chart Options...

      );

);

So a new window gets created but some windows have no charts because there are no matching data points for all the where conditions.

Yeah, I think validating the data up-front before graphing is the way to go.

Thanks.

Highlighted
pmroz
Super User

Re: Validate Graph output is not blank before saving

I would use something like:

dt << clear row states;

selected_rows = dt << get rows where(:Column 1 == "string1" &

                                     :Column 2 == "string2" &

                                     :Column 3 == "string3");

if (nrows(selected_rows) > 0,

    dt << select rows(selected_rows) << invert row selection

       << exclude << clear select;

   

    .

    .

//    Create your graph here

    .

    .

);

View solution in original post

Article Labels

    There are no labels assigned to this post.