Calculated Fields: Bring Formula-Driven Columns to Your CanvasXpress Charts

If you've ever wished you could just type log2(ExprA/ExprB) into your visualization tool and instantly get a new plottable variable — without exporting to a spreadsheet, doing the math, and re-importing — you're not alone. It's one of the most requested capabilities from analysts coming to CanvasXpress from tools like Tableau, and it's now part of the platform: Calculated Fields.

A calculated field is a new column computed directly from the data already loaded into your chart. No second dataset, no join, no round-trip through another application. You write a formula, CanvasXpress evaluates it safely, and the result becomes a first-class column that behaves exactly like any other variable, sample annotation, or variable annotation in your matrix.

What you can build

Calculated fields support a compact but genuinely useful expression language — enough to cover the everyday transformations analysts actually reach for:

That's enough to express real analyst workflows in a single line:

CanvasXpress automatically figures out whether the result should be a numeric column or a categorical (string) annotation, based on what the formula produces, and it handles missing or non-finite results gracefully — they show up as missing values rather than breaking your chart.

Creating a calculated field

You don't need to write any code to use this feature. From the chart's Data menu, choose Calculated Field… to open a small authoring dialog. There you:

  1. Give the field a name.
  2. Choose what it becomes — a calculated variable, a sample annotation, or a variable annotation — depending on whether you want it indexed over samples or over variables.
  3. Type the formula. A palette of available column names is right there so you don't have to remember exact spellings.
  4. Watch the live preview update as you type — a sample of computed values, the detected type (numeric or categorical), and a clear error message if the formula doesn't parse or references something that doesn't exist.
  5. Click Create.

Because validation happens as you type, you'll never accidentally apply a broken formula to your chart — the dialog simply won't let a bad expression through.

Why this is safe

Evaluating user-typed formulas sounds risky, and in a lot of tools it is — the tempting shortcut is to run the formula through eval or similarly dynamic code execution. CanvasXpress deliberately does not do that. Formulas are parsed into a small, explicit expression structure and then evaluated by walking that structure directly. There's no path from a formula string to arbitrary code execution, no access to properties, functions, or objects beyond the whitelisted math and aggregate operations described above. If a formula references an unknown identifier or an unsupported function, you get a validation error — never silent, uncontrolled execution.

It composes with everything else

This is the part that makes calculated fields more than a one-off convenience: once a formula-derived column exists, it's just another column. That means it automatically shows up everywhere columns already show up:

You compute it once, and every existing CanvasXpress feature that already understands your data model picks it up for free.

Persistence and reproducibility

Calculated fields aren't a throwaway session artifact. When you use Save as JSON (or Save Current as JSON) from the toolbar, the calculated field's definition — its name, its target, and its formula — is saved along with the rest of your chart configuration. Drop that saved file back onto a chart container and the field is recreated automatically, computed fresh against whatever data is loaded.

The same holds for the Reproduce toolbar action: it replays how the chart was built, calculated fields included, so you (or a colleague) can walk through the exact sequence of steps that produced a given view, formula and all.

You can also inspect a chart's current configuration programmatically to confirm what's been applied:

var config = cx.getConfig();

The returned object reflects everything currently in effect, including any calculated fields you've added — useful if you're scripting chart setup or auditing what a saved chart contains.

Where the boundary is

Calculated fields are intentionally scoped to derive a new column from the data already in your chart's single matrix. They do not merge in a second dataset, perform joins, or blend across tables. That's a deliberate design choice: CanvasXpress's model is a single, coherent dataset, and calculated fields extend what you can express within it rather than changing what a dataset is. If your workflow needs a join, that's a data-preparation step upstream of CanvasXpress — but everything you can compute from the columns you've already loaded is now a formula away.

Try it

Next time you find yourself exporting data just to add one derived column, open the Data menu instead. Write the formula, watch the preview confirm it, and get straight back to plotting — with color, filtering, and selection all ready to use your new field immediately.