Monthly grouped columns: an outbreak and its decline
Time series charts in CanvasXpress show how values change over calendar time: annual, monthly and daily series as lines, step lines, areas, columns and small multiples, with confidence bands, projections, shaded periods, event callouts, dual axes and direct end labels. These examples recreate editorial chart idioms (the Datawrapper reference set) with synthetic data and publication-style themes; every one of them is an ordinary Scatter2D, Line, Area, AreaLine, Bar, BarLine or Stacked configuration, so the same options apply to your own dated data.
<html>
<head>
<!-- Include the CanvasXpress library in your HTML file -->
<link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
<script src="https://www.canvasxpress.org/dist/canvasXpress.min.js"></script>
</head>
<body>
<!-- Create a canvas element for the chart with the desired dimensions -->
<div>
<canvas id="canvasId" width="600" height="600"></canvas>
</div>
<!-- Create a script to initialize the chart -->
<script>
// Use a data frame (2D-array) for the graph
var data =
// Create the configuration for the graph
var config = {
"graphType" : "Bar",
"titleAlign" : "plot::0",
"subtitleAlign" : "plot::0",
"legendHorizontalJustification" : 0,
"legendJustifyTo" : "plot",
"graphOrientation" : "vertical",
"theme" : "ggplot",
"colorScheme" : "User",
"colors" : [
"#56B4E9",
"#E1785B",
"#8A8A8A"
],
"xAxis" : [
"Cholera",
"Typhoid",
"Other"
],
"title" : "A cholera outbreak and the effect of a clean-water intervention",
"subtitle" : "Clinic cases per month in a fictional river town, by cause. Illustrative data.",
"smpLabelInterval" : 6,
"smpTextRotate" : 90,
"showLegend" : true,
"legendPosition" : "top",
"xAxisTitle" : "Cases per month",
"smpTitle" : "",
"decorations" : {
"line" : [
{
"value" : 45,
"color" : "#B5503C",
"width" : 2.5,
"type" : "dotted",
"label" : "Pre-outbreak clinic baseline",
"align" : "right"
}
],
"marker" : [
{
"text" : "Clean-water\nintervention begins",
"variable" : "Cholera",
"sample" : "Aug. 1855",
"type" : "curved",
"x" : 0.5,
"y" : 0.45
}
]
}
}
// Event used to create graph (optional)
var events = false
// Call the CanvasXpress function to create the graph
var cX = new CanvasXpress("canvasId", data, config, events);
</script>
</body>
</html>
<html>
<head>
<!-- Include the CanvasXpress library in your HTML file -->
<link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
<script src="https://www.canvasxpress.org/dist/canvasXpress.min.js"></script>
</head>
<body>
<!-- Create a canvas element for the chart with the desired dimensions -->
<div>
<canvas id="canvasId" width="600" height="600"></canvas>
</div>
<!-- Create a script to initialize the chart -->
<script>
// Create the data for the graph
var data = {
"y" : {
"vars" : [
"Cholera",
"Typhoid",
"Other"
],
"smps" : [
"Apr. 1854",
"May 1854",
"June 1854",
"July 1854",
"Aug. 1854",
"Sept. 1854",
"Oct. 1854",
"Nov. 1854",
"Dec. 1854",
"Jan. 1855",
"Feb. 1855",
"Mar. 1855",
"Apr. 1855",
"May 1855",
"June 1855",
"July 1855",
"Aug. 1855",
"Sept. 1855",
"Oct. 1855",
"Nov. 1855",
"Dec. 1855",
"Jan. 1856",
"Feb. 1856",
"Mar. 1856",
"Apr. 1856",
"May 1856",
"June 1856",
"July 1856",
"Aug. 1856",
"Sept. 1856"
],
"data" : [
[
3,
4,
5,
6,
110,
234,
359,
459,
540,
704,
772,
445,
352,
236,
159,
33,
31,
15,
17,
12,
12,
10,
6,
6,
8,
6,
7,
7,
7,
5
],
[
25,
14,
27,
8,
17,
26,
56,
72,
32,
74,
74,
71,
25,
60,
5,
25,
18,
33,
8,
13,
11,
11,
17,
9,
19,
20,
20,
33,
7,
31
],
[
14,
22,
28,
28,
12,
22,
22,
14,
98,
33,
28,
56,
25,
34,
23,
12,
23,
20,
12,
10,
24,
24,
13,
25,
17,
9,
15,
20,
27,
27
]
]
}
}
// Create the configuration for the graph
var config = {
"graphType" : "Bar",
"titleAlign" : "plot::0",
"subtitleAlign" : "plot::0",
"legendHorizontalJustification" : 0,
"legendJustifyTo" : "plot",
"graphOrientation" : "vertical",
"theme" : "ggplot",
"colorScheme" : "User",
"colors" : [
"#56B4E9",
"#E1785B",
"#8A8A8A"
],
"xAxis" : [
"Cholera",
"Typhoid",
"Other"
],
"title" : "A cholera outbreak and the effect of a clean-water intervention",
"subtitle" : "Clinic cases per month in a fictional river town, by cause. Illustrative data.",
"smpLabelInterval" : 6,
"smpTextRotate" : 90,
"showLegend" : true,
"legendPosition" : "top",
"xAxisTitle" : "Cases per month",
"smpTitle" : "",
"decorations" : {
"line" : [
{
"value" : 45,
"color" : "#B5503C",
"width" : 2.5,
"type" : "dotted",
"label" : "Pre-outbreak clinic baseline",
"align" : "right"
}
],
"marker" : [
{
"text" : "Clean-water\nintervention begins",
"variable" : "Cholera",
"sample" : "Aug. 1855",
"type" : "curved",
"x" : 0.5,
"y" : 0.45
}
]
}
}
// Event used to create graph (optional)
var events = false
// Call the CanvasXpress function to create the graph
var cX = new CanvasXpress("canvasId", data, config, events);
</script>
</body>
</html>
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import show_in_browser
if __name__ == "__main__":
# Define the chart with its data and configuration
chart: CanvasXpress = CanvasXpress(
render_to = "timeseries15",
data = {
"y": {
"vars": ["Cholera", "Typhoid", "Other"],
"smps": ["Apr. 1854", "May 1854", "June 1854", "July 1854", "Aug. 1854", "Sept. 1854", "Oct. 1854", "Nov. 1854", "Dec. 1854", "Jan. 1855", "Feb. 1855", "Mar. 1855", "Apr. 1855", "May 1855", "June 1855", "July 1855", "Aug. 1855", "Sept. 1855", "Oct. 1855", "Nov. 1855", "Dec. 1855", "Jan. 1856", "Feb. 1856", "Mar. 1856", "Apr. 1856", "May 1856", "June 1856", "July 1856", "Aug. 1856", "Sept. 1856"],
"data": [
[3, 4, 5, 6, 110, 234, 359, 459, 540, 704, 772, 445, 352, 236, 159, 33, 31, 15, 17, 12, 12, 10, 6, 6, 8, 6, 7, 7, 7, 5],
[25, 14, 27, 8, 17, 26, 56, 72, 32, 74, 74, 71, 25, 60, 5, 25, 18, 33, 8, 13, 11, 11, 17, 9, 19, 20, 20, 33, 7, 31],
[14, 22, 28, 28, 12, 22, 22, 14, 98, 33, 28, 56, 25, 34, 23, 12, 23, 20, 12, 10, 24, 24, 13, 25, 17, 9, 15, 20, 27, 27]
]
}
},
config = {
"graphType": "Bar",
"titleAlign": "plot::0",
"subtitleAlign": "plot::0",
"legendHorizontalJustification": 0,
"legendJustifyTo": "plot",
"graphOrientation": "vertical",
"theme": "ggplot",
"colorScheme": "User",
"colors": ["#56B4E9", "#E1785B", "#8A8A8A"],
"xAxis": ["Cholera", "Typhoid", "Other"],
"title": "A cholera outbreak and the effect of a clean-water intervention",
"subtitle": "Clinic cases per month in a fictional river town, by cause. Illustrative data.",
"smpLabelInterval": 6,
"smpTextRotate": 90,
"showLegend": True,
"legendPosition": "top",
"xAxisTitle": "Cases per month",
"smpTitle": "",
"decorations": {
"line": [
{
"value": 45,
"color": "#B5503C",
"width": 2.5,
"type": "dotted",
"label": "Pre-outbreak clinic baseline",
"align": "right"
}
],
"marker": [
{
"text": "Clean-water\nintervention begins",
"variable": "Cholera",
"sample": "Aug. 1855",
"type": "curved",
"x": 0.5,
"y": 0.45
}
]
}
},
width = 760,
height = 560
)
# Display the chart in its own Web page
show_in_browser(chart)
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import graph
graph(
CanvasXpress(
render_to = "timeseries15",
data = {
"y": {
"vars": ["Cholera", "Typhoid", "Other"],
"smps": ["Apr. 1854", "May 1854", "June 1854", "July 1854", "Aug. 1854", "Sept. 1854", "Oct. 1854", "Nov. 1854", "Dec. 1854", "Jan. 1855", "Feb. 1855", "Mar. 1855", "Apr. 1855", "May 1855", "June 1855", "July 1855", "Aug. 1855", "Sept. 1855", "Oct. 1855", "Nov. 1855", "Dec. 1855", "Jan. 1856", "Feb. 1856", "Mar. 1856", "Apr. 1856", "May 1856", "June 1856", "July 1856", "Aug. 1856", "Sept. 1856"],
"data": [
[3, 4, 5, 6, 110, 234, 359, 459, 540, 704, 772, 445, 352, 236, 159, 33, 31, 15, 17, 12, 12, 10, 6, 6, 8, 6, 7, 7, 7, 5],
[25, 14, 27, 8, 17, 26, 56, 72, 32, 74, 74, 71, 25, 60, 5, 25, 18, 33, 8, 13, 11, 11, 17, 9, 19, 20, 20, 33, 7, 31],
[14, 22, 28, 28, 12, 22, 22, 14, 98, 33, 28, 56, 25, 34, 23, 12, 23, 20, 12, 10, 24, 24, 13, 25, 17, 9, 15, 20, 27, 27]
]
}
},
config = {
"graphType": "Bar",
"titleAlign": "plot::0",
"subtitleAlign": "plot::0",
"legendHorizontalJustification": 0,
"legendJustifyTo": "plot",
"graphOrientation": "vertical",
"theme": "ggplot",
"colorScheme": "User",
"colors": ["#56B4E9", "#E1785B", "#8A8A8A"],
"xAxis": ["Cholera", "Typhoid", "Other"],
"title": "A cholera outbreak and the effect of a clean-water intervention",
"subtitle": "Clinic cases per month in a fictional river town, by cause. Illustrative data.",
"smpLabelInterval": 6,
"smpTextRotate": 90,
"showLegend": True,
"legendPosition": "top",
"xAxisTitle": "Cases per month",
"smpTitle": "",
"decorations": {
"line": [
{
"value": 45,
"color": "#B5503C",
"width": 2.5,
"type": "dotted",
"label": "Pre-outbreak clinic baseline",
"align": "right"
}
],
"marker": [
{
"text": "Clean-water\nintervention begins",
"variable": "Cholera",
"sample": "Aug. 1855",
"type": "curved",
"x": 0.5,
"y": 0.45
}
]
}
},
width = 760,
height = 560
)
)
using CanvasXpress
canvasxpress(Dict(
"y" => Dict(
"vars" => ["Cholera", "Typhoid", "Other"],
"smps" => ["Apr. 1854", "May 1854", "June 1854", "July 1854", "Aug. 1854", "Sept. 1854", "Oct. 1854", "Nov. 1854", "Dec. 1854", "Jan. 1855", "Feb. 1855", "Mar. 1855", "Apr. 1855", "May 1855", "June 1855", "July 1855", "Aug. 1855", "Sept. 1855", "Oct. 1855", "Nov. 1855", "Dec. 1855", "Jan. 1856", "Feb. 1856", "Mar. 1856", "Apr. 1856", "May 1856", "June 1856", "July 1856", "Aug. 1856", "Sept. 1856"],
"data" => [
[3, 4, 5, 6, 110, 234, 359, 459, 540, 704, 772, 445, 352, 236, 159, 33, 31, 15, 17, 12, 12, 10, 6, 6, 8, 6, 7, 7, 7, 5],
[25, 14, 27, 8, 17, 26, 56, 72, 32, 74, 74, 71, 25, 60, 5, 25, 18, 33, 8, 13, 11, 11, 17, 9, 19, 20, 20, 33, 7, 31],
[14, 22, 28, 28, 12, 22, 22, 14, 98, 33, 28, 56, 25, 34, 23, 12, 23, 20, 12, 10, 24, 24, 13, 25, 17, 9, 15, 20, 27, 27]
]
)
);
graphType = "Bar",
titleAlign = "plot::0",
subtitleAlign = "plot::0",
legendHorizontalJustification = 0,
legendJustifyTo = "plot",
graphOrientation = "vertical",
theme = "ggplot",
colorScheme = "User",
colors = ["#56B4E9", "#E1785B", "#8A8A8A"],
xAxis = ["Cholera", "Typhoid", "Other"],
title = "A cholera outbreak and the effect of a clean-water intervention",
subtitle = "Clinic cases per month in a fictional river town, by cause. Illustrative data.",
smpLabelInterval = 6,
smpTextRotate = 90,
showLegend = true,
legendPosition = "top",
xAxisTitle = "Cases per month",
smpTitle = "",
decorations = Dict(
"line" => [
Dict(
"value" => 45,
"color" => "#B5503C",
"width" => 2.5,
"type" => "dotted",
"label" => "Pre-outbreak clinic baseline",
"align" => "right"
)
],
"marker" => [
Dict(
"text" => "Clean-water\nintervention begins",
"variable" => "Cholera",
"sample" => "Aug. 1855",
"type" => "curved",
"x" => 0.5,
"y" => 0.45
)
]
)
)
























