Diverging Chart for Survey Agreement
If you run the staff or customer survey, the question you bring to the results is which statements people agree with and which they do not. A table of five percentages per statement, from strongly disagree to strongly agree, makes you add up the two ends of every row before you can say anything.
A diverging chart answers it. Each statement is one bar that grows from a centre line, to the right when more people agree than disagree and to the left when more disagree than agree, and the length is the net: agreement minus disagreement, in points. The chart above is bound to the grid beneath it, so filtering the rows redraws the bars. Filter the Statement column to the handful you are reporting on and the rest drop away.
Why a diverging chart and not a stacked bar chart
A stacked bar gives every statement a full-width bar cut into five colours, and to rank the statements you compare the same slice across twenty-two bars. A diverging chart does the sum for you and puts the answer on a shared centre line, so the statements people welcome and the ones they push back on separate by direction before you read a number.
The chart over a grid
The grid holds one row per statement: the statement, the share of answers at each of the five levels, and a net column that is agree plus strongly agree, minus disagree and strongly disagree. Name the statement column in x and the net column in y, and each row becomes one bar. Diverging is an opt-in chart type, so you import its module once after the charts module. Here is the example in plain JavaScript, with a few sample rows inline in place of your own.
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-diverging';
const rows = [
['I know what is expected of me', 2, 4, 10, 44, 40],
['My workload is manageable', 14, 30, 18, 28, 10],
['Pay is fair for the work', 12, 26, 22, 30, 10],
['I can work flexibly', 3, 5, 9, 36, 47],
['Change is handled well', 15, 29, 26, 22, 8],
].map(([statement, sd, d, n, a, sa], i) => ({
id: i + 1, statement, sd, d, n, a, sa, net: a + sa - sd - d,
}));
const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '320px';
document.body.append(gridEl, chartEl);
const grid = createGrid(gridEl, {
rowKey: 'id', rows,
columns: [
{ field: 'statement', title: 'Statement', filter: { type: 'set' } },
{ field: 'sd', title: 'Strongly disagree %', type: 'number' },
{ field: 'd', title: 'Disagree %', type: 'number' },
{ field: 'n', title: 'Neutral %', type: 'number' },
{ field: 'a', title: 'Agree %', type: 'number' },
{ field: 'sa', title: 'Strongly agree %', type: 'number' },
{ field: 'net', title: 'Net agreement', type: 'number' },
],
});
createChart({ grid, container: chartEl, type: 'diverging', x: 'statement', y: 'net',
title: 'Net agreement by statement (points)' });
The same thing in React
The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.
import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-diverging';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
['I know what is expected of me', 2, 4, 10, 44, 40],
['My workload is manageable', 14, 30, 18, 28, 10],
['Pay is fair for the work', 12, 26, 22, 30, 10],
['I can work flexibly', 3, 5, 9, 36, 47],
['Change is handled well', 15, 29, 26, 22, 8],
].map(([statement, sd, d, n, a, sa], i) => ({
id: i + 1, statement, strongly_disagree: sd, disagree: d, neutral: n, agree: a,
strongly_agree: sa, net: a + sa - sd - d,
}));
const columns = [
{ field: 'statement', title: 'Statement', filter: { type: 'set' } },
{ field: 'net', title: 'Net agreement', type: 'number' },
];
export function SurveyAgreement() {
const gridRef = useRef(null);
const chartRef = useRef(null);
useEffect(() => {
const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
type: 'diverging', x: 'statement', y: 'net', title: 'Net agreement by statement (points)' });
return () => chart.destroy();
}, []);
return (<>
<LatticeGrid ref={gridRef} rowKey="id" columns={columns} rows={rows} style={{ height: 240 }} />
<div ref={chartRef} style={{ height: 320 }} />
</>);
}
The options used
These are the rows of the charts reference for the options in the listings above.
| Option | Type | What it does |
|---|---|---|
grid |
Grid | Required. The grid to read. |
container |
Element or string | Required. Where to draw. |
type |
string | 'diverging' here, one bar per category grown from a central zero. |
x |
string | The category column, here the statement. |
y |
string | The measure column, here the net agreement. A positive value grows right, a negative value left. |
title |
string | Drawn above the plot. |
Reading the bars
Look first at the longest bars on each side, then at the statements near the centre line, where opinion is split or people chose neither side. In the example, flexible working and clear expectations lead on the right, while workload, change and promotion sit on the left. Filter the Statement column to the statements you answer for, and clear the filter to see all of them again.
Next
See the diverging chart beside the other ranking and change charts in the ranking and change family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.