Sparklines — win/loss bars with summary value


Economist GGPlot Excel Paul Tol Black And White Solarized Stata Tableau Wall Street CanvasXpress
<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" : "Sparklines",
         "sparklineType" : "winloss",
         "sparklineAggregate" : "mean",
         "title" : "Quarterly revenue change by region (win / loss)"
      }

      // 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" : [
               "QoQ Change"
            ],
            "smps" : [
               "Q1-N",
               "Q2-N",
               "Q3-N",
               "Q4-N",
               "Q5-N",
               "Q6-N",
               "Q1-S",
               "Q2-S",
               "Q3-S",
               "Q4-S",
               "Q5-S",
               "Q6-S",
               "Q1-E",
               "Q2-E",
               "Q3-E",
               "Q4-E",
               "Q5-E",
               "Q6-E",
               "Q1-W",
               "Q2-W",
               "Q3-W",
               "Q4-W",
               "Q5-W",
               "Q6-W"
            ],
            "data" : [
               [
                  3.2,
                  -1.5,
                  2.1,
                  4.0,
                  -0.8,
                  1.9,
                  -2.1,
                  1.2,
                  -3.0,
                  0.5,
                  2.2,
                  -1.1,
                  5.0,
                  4.1,
                  -2.2,
                  3.3,
                  1.0,
                  2.8,
                  -1.0,
                  -2.5,
                  1.1,
                  -0.4,
                  0.9,
                  -1.8
               ]
            ]
         },
         "x" : {
            "Region" : [
               "North",
               "North",
               "North",
               "North",
               "North",
               "North",
               "South",
               "South",
               "South",
               "South",
               "South",
               "South",
               "East",
               "East",
               "East",
               "East",
               "East",
               "East",
               "West",
               "West",
               "West",
               "West",
               "West",
               "West"
            ]
         }
      }

      // Create the configuration for the graph
      var config = {
         "graphType" : "Sparklines",
         "sparklineType" : "winloss",
         "sparklineAggregate" : "mean",
         "title" : "Quarterly revenue change by region (win / loss)"
      }

      // 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>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/r/cX-sparklines2-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
x=read.table("https://www.canvasxpress.org/data/r/cX-sparklines2-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
smpAnnot=x,
graphType="Sparklines",
sparklineAggregate="mean",
sparklineType="winloss",
title="Quarterly revenue change by region (win / loss)"
)
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 = "sparklines2",
    data = {
      "y": {
        "vars": ["QoQ Change"],
        "smps": ["Q1-N", "Q2-N", "Q3-N", "Q4-N", "Q5-N", "Q6-N", "Q1-S", "Q2-S", "Q3-S", "Q4-S", "Q5-S", "Q6-S", "Q1-E", "Q2-E", "Q3-E", "Q4-E", "Q5-E", "Q6-E", "Q1-W", "Q2-W", "Q3-W", "Q4-W", "Q5-W", "Q6-W"],
        "data": [
          [3.2, -1.5, 2.1, 4.0, -0.8, 1.9, -2.1, 1.2, -3.0, 0.5, 2.2, -1.1, 5.0, 4.1, -2.2, 3.3, 1.0, 2.8, -1.0, -2.5, 1.1, -0.4, 0.9, -1.8]
        ]
      },
      "x": {
        "Region": ["North", "North", "North", "North", "North", "North", "South", "South", "South", "South", "South", "South", "East", "East", "East", "East", "East", "East", "West", "West", "West", "West", "West", "West"]
      }
    },
    config = {
      "graphType": "Sparklines",
      "sparklineType": "winloss",
      "sparklineAggregate": "mean",
      "title": "Quarterly revenue change by region (win / loss)"
    },
    width = 600,
    height = 600
  )

  # Display the chart in its own Web page
  show_in_browser(chart)
Run this notebook: Open in Binder
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import graph

graph(
  CanvasXpress(
    render_to = "sparklines2",
    data = {
      "y": {
        "vars": ["QoQ Change"],
        "smps": ["Q1-N", "Q2-N", "Q3-N", "Q4-N", "Q5-N", "Q6-N", "Q1-S", "Q2-S", "Q3-S", "Q4-S", "Q5-S", "Q6-S", "Q1-E", "Q2-E", "Q3-E", "Q4-E", "Q5-E", "Q6-E", "Q1-W", "Q2-W", "Q3-W", "Q4-W", "Q5-W", "Q6-W"],
        "data": [
          [3.2, -1.5, 2.1, 4.0, -0.8, 1.9, -2.1, 1.2, -3.0, 0.5, 2.2, -1.1, 5.0, 4.1, -2.2, 3.3, 1.0, 2.8, -1.0, -2.5, 1.1, -0.4, 0.9, -1.8]
        ]
      },
      "x": {
        "Region": ["North", "North", "North", "North", "North", "North", "South", "South", "South", "South", "South", "South", "East", "East", "East", "East", "East", "East", "West", "West", "West", "West", "West", "West"]
      }
    },
    config = {
      "graphType": "Sparklines",
      "sparklineType": "winloss",
      "sparklineAggregate": "mean",
      "title": "Quarterly revenue change by region (win / loss)"
    },
    width = 600,
    height = 600
  )
)
using CanvasXpress

canvasxpress(Dict(
  "y" => Dict(
    "vars" => ["QoQ Change"],
    "smps" => ["Q1-N", "Q2-N", "Q3-N", "Q4-N", "Q5-N", "Q6-N", "Q1-S", "Q2-S", "Q3-S", "Q4-S", "Q5-S", "Q6-S", "Q1-E", "Q2-E", "Q3-E", "Q4-E", "Q5-E", "Q6-E", "Q1-W", "Q2-W", "Q3-W", "Q4-W", "Q5-W", "Q6-W"],
    "data" => [
      [3.2, -1.5, 2.1, 4.0, -0.8, 1.9, -2.1, 1.2, -3.0, 0.5, 2.2, -1.1, 5.0, 4.1, -2.2, 3.3, 1.0, 2.8, -1.0, -2.5, 1.1, -0.4, 0.9, -1.8]
    ]
  ),
  "x" => Dict(
    "Region" => ["North", "North", "North", "North", "North", "North", "South", "South", "South", "South", "South", "South", "East", "East", "East", "East", "East", "East", "West", "West", "West", "West", "West", "West"]
  )
);
  graphType = "Sparklines",
  sparklineType = "winloss",
  sparklineAggregate = "mean",
  title = "Quarterly revenue change by region (win / loss)"
)
⇧