11# Working with chart objects
22
3- This guide tours the key operations available on all of our object-oriented chart types .
3+ This guide tours the key operations available on all charts based on our object-oriented classes .
44
55## Creating a new chart
66
@@ -16,19 +16,20 @@ data = pd.DataFrame(
1616 }
1717)
1818
19- # Create a chart
19+ # Configure the chart object
2020chart = dw.BarChart(
2121 title = " Most Popular Programming Languages 2024" ,
2222 data = data,
2323 value_label_format = dw.NumberFormat.ONE_DECIMAL ,
2424)
2525
26+ # Create it by sending to Datawrapper
2627chart.create()
2728```
2829
2930## Getting an existing chart
3031
31- You can retrieve an existing chart by using ` get_chart ` with the chart ID:
32+ You can retrieve an existing chart with the ID, which is found in its URL.
3233
3334``` python
3435# Retrieve an existing chart
@@ -41,8 +42,6 @@ print(existing_chart.chart_id)
4142
4243## Updating an existing chart
4344
44- After creating or retrieving a chart, you can modify its properties and update it:
45-
4645``` python
4746# Modify the chart properties
4847chart.title = " Programming Language Popularity - Updated"
@@ -57,7 +56,7 @@ new_data = pd.DataFrame(
5756)
5857chart.data = new_data
5958
60- # Push the changes to Datawrapper (returns self for method chaining)
59+ # This will send the updates to Datawrapper
6160chart.update()
6261```
6362
@@ -66,7 +65,6 @@ chart.update()
6665Once your chart is ready, publish it to make it publicly accessible:
6766
6867``` python
69- # Publish the chart (returns self for method chaining)
7068chart.publish()
7169
7270# Chain with other operations
@@ -75,8 +73,6 @@ chart.create().publish()
7573
7674## Exporting a chart
7775
78- Export your chart as an SVG, PNG, or PDF file:
79-
8076``` python
8177# Export as PNG (default)
8278chart.export(filepath = " chart.png" )
@@ -90,14 +86,9 @@ chart.export(
9086)
9187```
9288
93- The export method supports various other options for customizing the output format and dimensions.
94-
9589## Duplicating a chart
9690
97- Create an editable copy of your chart:
98-
9991``` python
100- # Create a duplicate
10192duplicate_chart = chart.duplicate()
10293
10394# The duplicate is a new chart with a different ID
@@ -111,10 +102,7 @@ duplicate_chart.update()
111102
112103## Deleting a chart
113104
114- Remove a chart from Datawrapper:
115-
116105``` python
117- # Delete the chart
118106success = chart.delete()
119107
120108if success:
@@ -136,22 +124,17 @@ Get the HTML iframe embed code for your chart:
136124``` python
137125# Get standard iframe code
138126iframe_code = chart.get_iframe_code()
139- print (iframe_code)
140127
141128# Get responsive iframe code
142129responsive_iframe = chart.get_iframe_code(responsive = True )
143- print (responsive_iframe)
144130```
145131
146132## Getting png URL
147133
148134Get the fallback image URL for use in noscript tags:
149135
150136``` python
151- # Get the PNG URL
152137png_url = chart.get_png_url()
153- print (f " PNG fallback: { png_url} " )
154138
155- # Use in HTML noscript tags
156139html = f ' <noscript><img src=" { png_url} " alt="Chart" /></noscript> '
157140```
0 commit comments