Message Boards Message Boards

Simple DateListPlot not displaying anything

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?

POSTED BY: Lawrence Winkler
6 Replies
Posted 3 years 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

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Lawrence,

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

sessionsperdate // Normal // Values
POSTED BY: Rohit Namjoshi

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 BY: Lawrence Winkler
Posted 3 years ago

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

POSTED BY: Rohit Namjoshi

I've uploaded an NB will the code and output

POSTED BY: Lawrence Winkler

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.

POSTED BY: Lawrence Winkler
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