Skip to content

Commit f204a76

Browse files
authored
refactor: update documentation for various chart examples with improved clarity and structure
1 parent 1530587 commit f204a76

5 files changed

Lines changed: 48 additions & 370 deletions

File tree

docs/user-guide/charts/column-charts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ url = "https://raw.githubusercontent.com/chekos/datawrapper/main/tests/samples/c
1313
df = pd.read_csv(url)
1414

1515
chart = dw.ColumnChart(
16-
# Chart title with HTML line break
16+
# Chart headline
1717
title="U.S. unemployment rate",
18+
# Introductory text
19+
intro="January 2016-September 2020",
1820
# Data source attribution
1921
source_name="U.S. Bureau of Labor Statistics",
2022
source_url="https://www.bls.gov/",
21-
# Introductory text
22-
intro="January 2016-September 2020",
2323
# Data from pandas DataFrame
2424
data=df,
25-
# Format Y-axis grid labels with one decimal place and a percentage sign
25+
# Format labels with one decimal place and a percentage sign
2626
y_grid_format=dw.NumberFormat.PERCENT_UP_TO_ONE_DECIMAL,
27-
# Format value labels with one decimal place
2827
value_labels_format=dw.NumberFormat.PERCENT_UP_TO_ONE_DECIMAL,
29-
# Highlight specific column in red
28+
# Highlight specific columns with custom colors
3029
base_color="#CCCCCC",
3130
color_category={
3231
"2020/04": "rgb(21, 96, 122)",
@@ -36,6 +35,7 @@ chart = dw.ColumnChart(
3635
"2020/08": "rgb(21, 96, 122)",
3736
"2020/09": "rgb(21, 96, 122)",
3837
},
38+
# Annotations to highlight the COVID-19 period
3939
range_annotations=[
4040
dw.RangeAnnotation(
4141
x0="2020/01/01",

docs/user-guide/charts/line-charts.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# LineChart
22

3-
## Example
3+
This example, drawn from <a href="https://www.datawrapper.de/charts/lines">the Datawrapper documentation</a>, demonstrates how to create a line chart with a shaded confidence interval around the line.
44

5-
This example demonstrates how to create a line chart showing global land temperature in July from 1753-2015, with confidence intervals displayed as a shaded area.
5+
<iframe title="Global land temperature in July, 1753-2015" aria-label="Line chart" id="datawrapper-chart-9Qlvu" src="https://datawrapper.dwcdn.net/9Qlvu/1/" scrolling="no" frameborder="0" style="width: 0; min-width: 100% !important; border: none;" height="400" data-external="1"></iframe><script type="text/javascript">window.addEventListener("message",function(a){if(void 0!==a.data["datawrapper-height"]){var e=document.querySelectorAll("iframe");for(var t in a.data["datawrapper-height"])for(var r,i=0;r=e[i];i++)if(r.contentWindow===a.source){var d=a.data["datawrapper-height"][t]+"px";r.style.height=d}}});</script>
66

77
```python
88
import pandas as pd
99
import datawrapper as dw
1010

1111
# Load temperature data from GitHub
12-
url = "https://raw.githubusercontent.com/palewire/datawrapper-api-classes/main/tests/samples/line/land-temps.csv"
12+
url = "https://raw.githubusercontent.com/chekos/datawrapper/main/tests/samples/line/land-temps.csv"
1313
df = pd.read_csv(url)
1414

1515
chart = dw.LineChart(
@@ -18,56 +18,59 @@ chart = dw.LineChart(
1818
# Data source attribution
1919
source_name="Berkeley Earth",
2020
source_url="http://berkeleyearth.org/data/",
21-
# Introductory text
22-
intro="Average land temperature in July, in degrees Celsius",
23-
# Chart byline
24-
byline="John Burn-Murdoch",
2521
# Data from pandas DataFrame
2622
data=df,
27-
# Hide X-axis grid lines
28-
x_grid_display="off",
29-
# Show Y-axis grid lines
30-
y_grid_display="on",
31-
# Format Y-axis grid labels with one decimal place
32-
y_grid_format=dw.NumberFormat.ONE_DECIMAL,
33-
# Use monotone interpolation for smooth curves
34-
interpolation=dw.LineInterpolation.MONOTONE,
35-
# Configure the main temperature line
23+
# Set the suffix on our values
24+
transformations=dw.Transform(
25+
column_format=[
26+
dw.ColumnFormat(
27+
column="LandAverageTemperature",
28+
number_append=" °C",
29+
)
30+
]
31+
),
32+
y_grid_format="0",
33+
# Set the range
34+
# Format Y-axis grid labels with no decimal places
35+
custom_range_y=[8, 21],
36+
# And now the tooltip...
37+
tooltip_number_format="00.00",
38+
tooltip_x_format="YYYY",
39+
# Configure the main temperature line's color
40+
color_category={
41+
"LandAverageTemperature": "#1d81a2",
42+
},
3643
lines=[
44+
# Style the main line
3745
dw.Line(
38-
# Column to plot
3946
column="LandAverageTemperature",
40-
# Line color
41-
color="#c71e1d",
42-
# Line width
43-
width=dw.LineWidth.MEDIUM,
44-
# Show symbol on last data point
45-
symbols=dw.LineSymbol(
46-
display=dw.SymbolDisplay.LAST,
47-
size=5
48-
),
49-
# Show value label on last data point
50-
value_labels=dw.LineValueLabel(
51-
last=True
52-
)
53-
)
47+
width=dw.LineWidth.THIN,
48+
interpolation=dw.LineInterpolation.CURVED,
49+
),
50+
# Hide the other two
51+
dw.Line(
52+
column="lower",
53+
width=dw.LineWidth.INVISIBLE,
54+
),
55+
dw.Line(
56+
column="upper",
57+
width=dw.LineWidth.INVISIBLE,
58+
),
5459
],
5560
# Add shaded confidence interval area
5661
area_fills=[
57-
{
58-
"from": "lower",
59-
"to": "upper",
60-
"color": "#cccccc",
61-
"opacity": 0.5
62-
}
62+
dw.AreaFill(
63+
from_column="lower",
64+
to_column="upper",
65+
color="#cccccc",
66+
opacity=0.45,
67+
)
6368
],
6469
)
6570

6671
chart.create()
6772
```
6873

69-
<div style="min-height:433px" id="datawrapper-vis-BsBaq"><script type="text/javascript" defer src="https://datawrapper.dwcdn.net/BsBaq/embed.js" charset="utf-8" data-target="#datawrapper-vis-BsBaq"></script><noscript><img src="https://datawrapper.dwcdn.net/BsBaq/full.png" alt="" /></noscript></div>
70-
7174
## Reference
7275

7376
```{eval-rst}

docs/user-guide/charts/multiple-column-charts.md

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,5 @@
11
# MultipleColumnChart
22

3-
## Example
4-
5-
This example demonstrates how to create a multiple column chart showing the population of the world's largest cities from 1950 to 2035. The chart uses 8 panels (one for each city) with custom HTML-styled titles, highlights the year 2025 in red, and includes text and range annotations.
6-
7-
```python
8-
import pandas as pd
9-
import datawrapper as dw
10-
11-
# Load data from GitHub
12-
url = "https://raw.githubusercontent.com/palewire/datawrapper-api-classes/main/tests/samples/multiple_column/population.csv"
13-
df = pd.read_csv(url)
14-
15-
chart = dw.MultipleColumnChart(
16-
# Chart metadata
17-
title="Population of the world's largest cities, 1950 to 2035",
18-
# Data source attribution
19-
source_name="Our World in Data",
20-
source_url="https://ourworldindata.org/urbanization",
21-
# Data
22-
data=df,
23-
# Grid layout - 4 columns
24-
grid_column=4,
25-
# Fixed row height
26-
grid_row_height=140,
27-
# Y-axis format - abbreviated numbers (e.g., "10M")
28-
y_grid_format=dw.NumberFormat.ABBREVIATED_ONE_DECIMAL,
29-
# Y-axis labels inside the plot area
30-
y_grid_labels="inside",
31-
# X-axis and Y-axis grid lines off
32-
x_grid_display="off",
33-
y_grid_display="off",
34-
# Base color for columns
35-
base_color="#c9a291",
36-
# Highlight 2025 in red
37-
column_color={"2025": "#c71e1d"},
38-
# Category labels for legend
39-
category_labels={"2025": "...for 2025"},
40-
# Exclude all other years from the legend
41-
exclude_from_color_key=[
42-
"1950", "1955", "1960", "1965", "1970", "1975", "1980", "1985",
43-
"1990", "1995", "2000", "2005", "2010", "2015", "2020", "2030", "2035"
44-
],
45-
# Hide the color key
46-
show_color_key=False,
47-
# Panel titles with HTML styling
48-
panel_titles={
49-
"Beijing": "Beijing, <span style=\"color:gray; font-weight: normal;\">China</span>",
50-
"Delhi": "Delhi, <span style=\"color:gray; font-weight: normal;\">India</span>",
51-
"Dhaka": "Dhaka, <span style=\"color:gray; font-weight: normal;\"> Bangladesh </span>",
52-
"Lagos": "Lagos, <span style=\"color:gray; font-weight: normal;\">Nigeria</span>",
53-
"Mumbai (Bombay)": "Mumbai, <span style=\"color:gray; font-weight: normal;\">India</span>",
54-
"New York-Newark": "New York/Newark, <span style=\"color:gray; font-weight: normal;\">U.S.</span>",
55-
"Paris": "Paris, <span style=\"color:gray; font-weight: normal;\">France</span>",
56-
"Tokyo": "Tokyo, <span style=\"color:gray; font-weight: normal;\">Japan</span>",
57-
},
58-
# Text annotations
59-
text_annotations=[
60-
# Projection label for Mumbai
61-
dw.TextAnnotation(
62-
text="Projection",
63-
x="2018/04/30 15:23",
64-
y=36224085.8571,
65-
plot="Mumbai (Bombay)",
66-
dx=-21,
67-
dy=-8,
68-
align="tr",
69-
size=13,
70-
color="#858585",
71-
connector_line=dw.ConnectorLine(
72-
type=dw.ConnectorLineType.STRAIGHT,
73-
stroke=dw.StrokeWidth.THIN
74-
)
75-
),
76-
# Paris 2035 label
77-
dw.TextAnnotation(
78-
text="Paris 2035",
79-
x="1947/07/03 01:00",
80-
y=16409201.2857,
81-
plot="Delhi",
82-
align="tl",
83-
size=13,
84-
color="#858585"
85-
),
86-
# Delhi 2025 population callout
87-
dw.TextAnnotation(
88-
text="<b style=\"color:#b73229\">2025 population:</b>\n34.7M",
89-
x="2023/07/14 22:34",
90-
y=33128010.1429,
91-
plot="Delhi",
92-
dx=-21,
93-
dy=-29,
94-
align="tr",
95-
size=13,
96-
color="#494949",
97-
bg=True,
98-
connector_line=dw.ConnectorLine(
99-
type=dw.ConnectorLineType.STRAIGHT,
100-
stroke=dw.StrokeWidth.THIN,
101-
inherit_color=False
102-
)
103-
),
104-
# Paris growth note
105-
dw.TextAnnotation(
106-
text="Paris grew the most between 1851 to 1856 (by over 20%).",
107-
x="1947/10/03 18:05",
108-
y=43097373.9429,
109-
plot="Paris",
110-
align="tl",
111-
size=13,
112-
color="#494949",
113-
bg=True
114-
),
115-
# Lagos projection note (hidden on mobile/desktop, shown as fallback)
116-
dw.TextAnnotation(
117-
text="Lagos is expected to double in size by 2035 compared to 2015.",
118-
x="1947/07/03 01:00",
119-
y=43096075.7522,
120-
plot="Lagos",
121-
align="tl",
122-
size=13,
123-
color="#494949",
124-
bg=True,
125-
show_mobile=False,
126-
show_desktop=False
127-
),
128-
],
129-
# Range annotations
130-
range_annotations=[
131-
# Horizontal line in Paris panel
132-
dw.RangeAnnotation(
133-
x0="2009/01/23 14:50",
134-
x1="2009/01/23 14:50",
135-
y0=11765087.7143,
136-
y1=13622733.1429,
137-
plot="Paris",
138-
range_type="y",
139-
display="line",
140-
color="#888",
141-
opacity=76,
142-
stroke_type="dotted",
143-
stroke_width=2,
144-
show_in_all_plots=True
145-
),
146-
# Shaded projection period in Mumbai panel
147-
dw.RangeAnnotation(
148-
x0="2018/01/01 13:22",
149-
x1="2037/07/02 01:00",
150-
y0=26626251.1429,
151-
y1=27245466.2857,
152-
plot="Mumbai (Bombay)",
153-
range_type="x",
154-
display="range",
155-
color="#888",
156-
opacity=18,
157-
show_in_all_plots=True
158-
),
159-
],
160-
)
161-
162-
chart.create()
163-
```
164-
165-
<iframe title="Population of the world's largest cities, 1950 to 2035" aria-label="Multiple Columns" id="datawrapper-chart-ZEBmw" src="https://datawrapper.dwcdn.net/ZEBmw/1/" scrolling="no" frameborder="0" style="width: 0; min-width: 100% !important; border: none;" height="460" data-external="1"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(a){if(void 0!==a.data["datawrapper-height"]){var e=document.querySelectorAll("iframe");for(var t in a.data["datawrapper-height"])for(var r=0;r<e.length;r++)if(e[r].contentWindow===a.source){var i=a.data["datawrapper-height"][t]+"px";e[r].style.height=i}}}))}();
166-
</script>
167-
1683
## Reference
1694

1705
```{eval-rst}

0 commit comments

Comments
 (0)