# How to export XY Chart data to CSV

**URL:** <https://forum.inductiveautomation.com/t/how-to-export-xy-chart-data-to-csv/82925>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [December 9, 2023, 8:46am UTC](https://forum.inductiveautomation.com/t/how-to-export-xy-chart-data-to-csv/82925 "2023-12-09T08:46:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 9, 2023, 8:46am UTC](https://forum.inductiveautomation.com/t/how-to-export-xy-chart-data-to-csv/82925/1 "2023-12-09T08:46:23Z")

</div>

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

 ![Weixin Image_20231209164521](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/3/3315164e9cd9885611e29efd0373bef14b984a7a.jpeg)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 9, 2023, 10:38am UTC](https://forum.inductiveautomation.com/t/how-to-export-xy-chart-data-to-csv/82925/2 "2023-12-09T10:38:23Z")

</div>

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:

```auto
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!
