Skip to content

Decision tree ​

Choices, chances and outcomes, with the best path in bold. Good for comparing options whose result is uncertain.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'decision',
  root: {
    name: 'New product?',
    children: [
      {
        name: 'Launch',
        cost: 40,
        children: [
          { name: 'Strong demand', probability: 0.4, value: 186 },
          { name: 'Fair demand', probability: 0.35, value: 76 },
          { name: 'Weak demand', probability: 0.25, value: 7 },
        ],
      },
      {
        name: 'Test first',
        cost: 10,
        children: [
          {
            name: 'Good test',
            probability: 0.55,
            children: [{ name: 'Launch', cost: 40, value: 149 }, { name: 'Stop', value: 0 }],
          },
          { name: 'Bad test', probability: 0.45, value: 0 },
        ],
      },
      { name: 'Do nothing', value: 0 },
    ],
  },
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type decision takes:

/** Decisions (squares), chances (circles) and outcomes; the best choice is drawn bold. */
interface DecisionSpec extends Base {
  type: 'decision';
  root: DecisionNode;
}

/** A node of a decision tree. A branch with `probability` leaves a chance node; an end has a `value`. */
interface DecisionNode {
  name: string;

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it