Skip to content

Compare action

Use this action with change({ id: 'Compare', context }).

Context

  • id?: Get | Update (Update is assumed if omitted)
  • plots: array of comparison plots
    • type: Symbol | Expression | Seasonal
    • uid: optional plot uid
    • symbol when type is Symbol
    • expression when type is Expression
    • seasonal when type is Seasonal
    • oppositeScale: true | false (leftScale is still accepted but deprecated)
    • curves: optional curve overrides
  • symbols: deprecated compatibility alias for symbol-only compare list
  • alignOnExpirations: true | false

Behavior

Configures comparison plots against the main plot.

  • Supports symbol, expression, and seasonal comparison plots.
  • Existing comparison plots are replaced by the incoming plots list.
  • If a compare item supplies uid, it must be unique across all plots currently on the chart, regardless of plot type.
  • Duplicate caller-supplied uid values within the same compare request are rejected.
  • The package exports generateUid() if you want to pre-generate compare plot ids in the host app.
  • By default, comparison plots share the main axis.
  • oppositeScale: true puts a plot on the secondary/opposite axis.
  • If curves is omitted, comparison plots render as lines with automatic colors.
  • Curve values are merged with defaults, so partial overrides are fine.
  • alignOnExpirations: true overlays eligible non-seasonal plots (mainly futures) as if they traded in the same year; the tooltip still shows actual trade dates.
  • Seasonal comparison plots align internally, so alignOnExpirations does not control seasonal alignment.

Get returns the same top-level shape (plots, alignOnExpirations). Returned plots include canonical oppositeScale plus deprecated leftScale as a compatibility alias.

Example:

chart.change({
id: "Compare",
context: {
plots: [
{ type: "Symbol", symbol: "AAPL" },
{ type: "Seasonal", seasonal: "CLM24", oppositeScale: true },
],
alignOnExpirations: true,
},
});