How can I call functions from a custom plugin?

You don’t, alert is a javascript function that runs in the browser. PHP runs on the server, the two are different languages that run in different places.

Instead, consider using script tags:

return '<script>window.alert("Connected to the database successfully.")</script>';`

console.log("") may be a more appropriate method than alert("") for debugging

I would also note, that shortcodes embed content, and should represent something. Your plugin appears to create graphs, therefore I would assume your shortcode should be something such as [vivek_graph]. Inside that shortcode you can connect to the database, rather than requiring a connect to db shortcode happen before every use