I think what you're looking for is this
There is quite a bit of code around using the SharePoint API but the numbers it reports are from SharePoint Search so are slightly different (reference).
I haven't been able to find a code example for you I'm afraid.
I've just found the following which talks about the GraphApi analytics for specific list item (file) giving the actorCount, actionCount
This lead me to
for the basic analytics and then
the following which gives these values for a specific interval
I think with this and the PostMan tool getting a GraphApi token for authentication, should give you (and me now) enough to get analytics for specific files.