How to export XY Chart data to CSV

in perspective
I want to create a button to export the data in XYchart to a CSV file through a script. How can I achieve this function

I've done similar on a project by creating a popup to display the CSV data in a Text Area component. As far as I know, there is no Perspective function to copy to the clipboard so I give user instructions for keyboard shortcuts. See below.

  1. Create the popup with
  • Label with text: "Select the comma-separated data in the text area below (Ctrl-A), copy (Ctrl-C) and paste it into Excel (Ctrl-V)." (or whatever you want).
  • Text Area
  • Add a parameter to the view to accept the chart data.
  1. Add a Clipboard button to your primary view.
  2. Add a Navigation event to the button's onActionPerformed. Call the popup and pass the XY Chart's dataSources.example to the popup.
  3. Back to the popup: create a script in the popup's onStartup event to loop through the data and generated the CSV and add this to the Text Area text property.

The script will be something like:

def runAction(self, event):
	dataSource = self.getSibling("XYChart").props.dataSources.example
	data = ""
	for row in dataSource:
		data += ','.join([str(v) for k, v in row.items()]) + '\n'
	self.getSibling("TextArea").props.text = data

Tip: screengrabs from the computer are better than photos of a screen!