Page 1 of 1

[SOLVED] npPlot inquiry

PostPosted: Thu Jan 15, 2015 10:22 am
by stu
I'm trying to see if i can generate a graphic with the help of npPlot but I'm getting a weird result, maybe in my code and I can't see it...

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
npPlotCreate "Graph" "[Result]"

npPlotTitleOptions "Graph" "Calls per year" "Tahoma|11|0,0,0" "[Result]"

npPlotAddSeries "Graph" "Calls" "skBar" "[Result]"

npPlotAxisXOptions "Graph" "Year" "1" "[Result]"
npPlotAxisYOptions "Graph" "Calls" "1" "[Result]"

npPlotBeginUpdate "Graph" "[Result]"

Setvar "[YearVar]" "[Year]"
StrDel "[YearVar]" "1" "2" "[YearShort]"
Setvar "[YearCount]" "0"

While "[YearCount]" "<=" "[YearShort]"

      if "[YearCount]" "<" "10"
         Setvar "[AddedZero]" "0"
      else
          Setvar "[AddedZero]" ""
      endif

      dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #20[AddedZero][YearCount]-01-01# AND #20[AddedZero][YearCount]-12-31#"
      setvar "[Year20[AddedZero][YearCount]]" "[FIRE.tblIncidents.$RecCount]"

      npPlotAddXY "Graph" "Calls" "20[AddedZero][YearCount]" "[Year20[AddedZero][YearCount]]" "[Result]"

      Math "[YearCount]+1" "0" "[YearCount]"
     
endwhile

npPlotEndUpdate "Graph" "[Result]"

CustomWindow "Call's per year" "-1" "-1" "Graph" "ToolWindow"
Parsed in 0.009 seconds, using GeSHi 1.0.8.10


This code it's actually doing pretty much all what it's supposed to... except that the result its as follows:

Image

Any clues =)

EDIT: I realized I can put all in a single While...

Re: npPlot inquiry

PostPosted: Thu Jan 15, 2015 12:49 pm
by dec
Hello,

I think you mean the years appear in some extrange order: "2009", "20010", "20012", etc. If this correct? Really I never hear about a problem like that, then, I want to question, are you sure the numbers in which the chart are based are not "20010", "20012", etc? Since you get the data from a database, I can't test it without such database,... can you try to test (in order to replicate the problem) using some "fake" data that I can also try here?

Anyway sorry for the possible inconveniences stu.

Re: npPlot inquiry

PostPosted: Thu Jan 15, 2015 1:31 pm
by dpayer
Yes, it is a bit odd that you go from 2009 to 20010. That is a 18,001 year gap. Maybe the app can't comprehend it! :shock:

Re: npPlot inquiry

PostPosted: Thu Jan 15, 2015 1:36 pm
by dec
Hello,

dpayer wrote:Yes, it is a bit odd that you go from 2009 to 20010. That is a 18,001 year gap. Maybe the app can't comprehend it! :shock:


My idea (maybe wrong) is the data come "like that" from the database or something like that. In few words, the chart receive that value and then print out accordingly. Below we can see a sample publication, which do not take the data from any database, and, as we can see, the year gap do not happend:

Image

Re: npPlot inquiry

PostPosted: Thu Jan 15, 2015 3:54 pm
by stu
Thanks for the replies!

I Guess I'll carry on tomorrow, but I got an update... I Changed the part of the code that adds or not a zero depending if the number is less than 10 and then it generates the years ok, but then the data keeps not making sense. So IMO its purely a code related issue.

As said, I'll keep trying tomorrow and let you know.

Re: npPlot inquiry

PostPosted: Thu Jan 15, 2015 5:03 pm
by Gaev
stu:

Try this cide ...
Code: Select all
dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #20[AddedZero][YearCount]-01-01# AND #20[AddedZero][YearCount]-12-31#"
setvar "[thisYearIncedents]" "[FIRE.tblIncidents.$RecCount]"

AlertBox "20[AddedZero][YearCount]" "[thisYearIncidents]"
npPlotAddXY "Graph" "Calls" "20[AddedZero][YearCount]" "[thisYearIncidents]" "[Result]"

That will confirm if the expected values are being passed to npPlotAddXY.

Re: npPlot inquiry

PostPosted: Fri Jan 16, 2015 4:17 am
by stu
Gaev wrote:stu:

Try this cide ...
Code: Select all
dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #20[AddedZero][YearCount]-01-01# AND #20[AddedZero][YearCount]-12-31#"
setvar "[thisYearIncedents]" "[FIRE.tblIncidents.$RecCount]"

AlertBox "20[AddedZero][YearCount]" "[thisYearIncidents]"
npPlotAddXY "Graph" "Calls" "20[AddedZero][YearCount]" "[thisYearIncidents]" "[Result]"

That will confirm if the expected values are being passed to npPlotAddXY.


Oh yeah, i did test with alertboxes to check if the values being passed were ok, they were.

But take a look at this code, this works, makes all the requested years (2000 - 2015) display ok...

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
npPlotCreate "Graph" "[Result]"

npPlotTitleOptions "Graph" "Calls per year" "Tahoma|11|0,0,0" "[Result]"

npPlotAddSeries "Graph" "Calls" "skBar" "[Result]"

npPlotAxisXOptions "Graph" "Year" "1" "[Result]"
npPlotAxisYOptions "Graph" "Calls" "1" "[Result]"

npPlotBeginUpdate "Graph" "[Result]"

Setvar "[YearVar]" "[Year]"
StrDel "[YearVar]" "1" "2" "[YearShort]"
Setvar "[YearCount]" "0"

While "[YearCount]" "<=" "[YearShort]"

      if "[YearCount]" "<" "10"
         Setvar "[AddedZero]" "00"
      else
          Setvar "[AddedZero]" ""
      endif

      dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #2[AddedZero][YearCount]-01-01# AND #2[AddedZero][YearCount]-12-31#"
      setvar "[Year2[AddedZero][YearCount]]" "[FIRE.tblIncidents.$RecCount]"

      npPlotAddXY "Graph" "Calls" "2[AddedZero][YearCount]" "[Year2[AddedZero][YearCount]]" "[Result]"

      Math "[YearCount]+1" "0" "[YearCount]"

endwhile

npPlotEndUpdate "Graph" "[Result]"

CustomWindow "Call's per year" "-1" "-1" "Graph" "ToolWindow"
Parsed in 0.008 seconds, using GeSHi 1.0.8.10


(Pay no attention to the emergency line, that's part of another test)

Image

Now years show ok, but the data per year doesn't (?)

Funny thing

------------------ EDIT ------------------

Image

I got it! ok, so final code:

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
npPlotCreate "Graph" "[Result]"

npPlotTitleOptions "Graph" "Calls per year" "Tahoma|11|0,0,0" "[Result]"

npPlotAddSeries "Graph" "Calls" "skBar" "[Result]"

npPlotAxisXOptions "Graph" "Year" "1" "[Result]"
npPlotAxisYOptions "Graph" "Calls" "1" "[Result]"

npPlotBeginUpdate "Graph" "[Result]"

Setvar "[YearVar]" "[Year]"
StrDel "[YearVar]" "1" "2" "[YearShort]"
Setvar "[YearCount]" "0"

While "[YearCount]" "<=" "[YearShort]"

      if "[YearCount]" "<" "10"
         Setvar "[AddedZero]" "00"
      else
          Setvar "[AddedZero]" "0"
      endif

      dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #2[AddedZero][YearCount]-01-01# AND #2[AddedZero][YearCount]-12-31#"
      setvar "[Year2[AddedZero][YearCount]]" "[FIRE.tblIncidents.$RecCount]"

      npPlotAddXY "Graph" "Calls" "2[AddedZero][YearCount]" "[Year2[AddedZero][YearCount]]" "[Result]"

      Math "[YearCount]+1" "0" "[YearCount]"

endwhile

npPlotEndUpdate "Graph" "[Result]"

CustomWindow "Call's per year" "-1" "-1" "Graph" "ToolWindow"
Parsed in 0.008 seconds, using GeSHi 1.0.8.10


On line 19 double zero and on line 21 added a single zero.

I keep trying to add more data to the graph and see if I can get the result Im looking for. =)

Thanks for your replies!

Re: [SOLVED] npPlot inquiry

PostPosted: Fri Jan 16, 2015 6:34 am
by Gaev
stu:

I think that ... although NeoBook does a great job with nested variable syntax (like [Year2[AddedZero][YearCount]]) ... it might be getting messed up when passed to the plugin.

Since both, the database and the plugin use year values 2000, 2001 ... 2014, 2015 ... why not just do this ...
Code: Select all
Setvar "[YearVar]" "[Year]"   ... <<-- 2015
Setvar "[thisYear]" "2000"

While "[thisYear]" "<=" "[Year]"

      dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #[thisYear]-01-01# AND #[thisYear]-12-31#"
      setvar "[thisYearIncidents]" "[FIRE.tblIncidents.$RecCount]"

      npPlotAddXY "Graph" "Calls" "[thisYear]" "[thisYearIncidents]" "[Result]"

      Math "[thisYear]+1" "0" "[thisYear]"

endwhile


In other words, K.I.S.S (keep it simple, stu) :wink:

Added bonus ... easily converts to get data for years 19xx as well.

Re: [SOLVED] npPlot inquiry

PostPosted: Wed Jan 21, 2015 5:23 am
by stu
Gaev wrote:stu:

I think that ... although NeoBook does a great job with nested variable syntax (like [Year2[AddedZero][YearCount]]) ... it might be getting messed up when passed to the plugin.

Since both, the database and the plugin use year values 2000, 2001 ... 2014, 2015 ... why not just do this ...
Code: Select all
Setvar "[YearVar]" "[Year]"   ... <<-- 2015
Setvar "[thisYear]" "2000"

While "[thisYear]" "<=" "[Year]"

      dbpQuery "FIRE" "tblIncidents" "IncidentDateTime BETWEEN #[thisYear]-01-01# AND #[thisYear]-12-31#"
      setvar "[thisYearIncidents]" "[FIRE.tblIncidents.$RecCount]"

      npPlotAddXY "Graph" "Calls" "[thisYear]" "[thisYearIncidents]" "[Result]"

      Math "[thisYear]+1" "0" "[thisYear]"

endwhile


In other words, K.I.S.S (keep it simple, stu) :wink:

Added bonus ... easily converts to get data for years 19xx as well.


Sorry dude, I missed this post, thanks for this already proved it and works perfect :D