Message Boards Message Boards

GROUPS:

Simple DateListPlot not displaying anything

Posted 13 days ago
229 Views
|
6 Replies
|
1 Total Likes
|

For a website I administer, I'm using Google Analytics API to pull the information I'm interested in, and want to do a little processing in WL. This includes want to do a simple plot of some data.

google = ServiceConnect["GoogleAnalytics"]
sessionsperdate = google["ReportData", {"ProfileID" -> xxxxxxx, 
   "Dimensions" -> "Date", 
   "Metrics" -> "Sessions", 
   "StartDate" -> "October 1, 2020", 
   "EndDate" -> "December 31, 2020",
   MaxItems -> 1000, "StartIndex" -> 1, 
   "SamplingLevel" -> "HigherPrecision"
   }];

This code returns a two column dataset, the first is Date (as a DateObject), the second is number of Sessions (an Integer, with values ranging from 1 to 100). Just for grins I want to see a plot of the sessions across all 92 days. So, I enter

DateListPlot[sessionsperdate]

What I get, for what I was expecting to be a no brainer, no frills plot, was an empty plot, with the x-axis ranging from 23:59:59 to 00:00:01 instead of dates of each day in the list, and the y-axis ranging from -1.0 to 1.0 instead of integers between 1 and 100.

I've tried several unsuccessful machinations, such as

sessionsperdate // Normal // Values

to get a list of pairs, which is then fed into DateListPlot.

Clearly I'm not understanding even the most basic of the WL. What do I need to do get this to work?

6 Replies
Posted 13 days ago

Hi Lawrence,

Could you please edit your post and add a few lines from the output of

sessionsperdate // Normal // Values

Sorry. I haven't figured out how to post the outputs. A simple copy and paste of the output cells is not rendered readable, and an attempt to paste a screen-shot doesn't render the image either. I'm at a loss on how the output cells can be posted.

Posted 12 days ago

Take a look at the "Post Editor" section here.

I've uploaded an NB will the code and output

Posted 12 days ago

Hi Lawrence,

If you look at

sessionsperdate // Normal // Values // InputForm

you will notice that the value associated with each date is a String. That explains the empty plot. One way to convert to numeric

(sessionsperdate // Normal // Values) /. {d_, v_} :> {d, ToExpression@v} // DateListPlot

enter image description here

Thank you very much. I'm maybe finally starting to see how I might debug my code. Piping into InputForm gives me some hope I might get the hang of things more readily.

It's finally occurring to me that I need to focus on the primitives of WL, being that WL is written in WL. That will require me to put much more effort on reading other's code.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract