To create a new dashboard widget, use the method ComponentsProvider.add(), see the linked documentation.
To make a dashboard widget visible, you need an application that also includes dashboard functionality (either the one that contains the plugin, or another app that you create, for example, using the "Own applications" menu item).
To include dashboard functionality, subscribe the application to at least the following plugins: Device list, device detail, dashboard und key performance indicators.