Skip to content

Events

TradeX-chart provides a publish and subscribe messaging model. The chart supports multiple subscriptions to an event.

It is also possible to use the chart to generate your on events.

Subscribing

Once the chart is initialized with the chart.start() method, any event the chart generates can be subscribed to with the chart.on(topic, handler) method.

  • @param {string} topic - event name
  • @param {function} handler - function or method
  • @param {Object} context - context the function belongs to
chart.on("stream_candleUpdate", onSomeEven, this)

The handler will be passed one parameter if any dependent upon the event.

function onSomeEvent(data) { console.log(data) }

Event handlers will be executed in first in last out order.

Unsubscribing

Unsubscribing from the event uses the chart.off(string, function, this) method.

  • @param {string} topic - event name
  • @param {function} handler - function or method
  • @param {Object} context - context the function belongs to
chart.off("stream_candleUpdate", onSomeEvent, this)

Event Publishing

The same method that the chart uses internally is also exposed on the public API. Developers can take advantage of this for their own purposes and generate their own events and use the same subscribe and unsubscribe methods detailed above.

  • @param {String} topic - The topic name
  • @param {Object} data - The data to publish
chart.emit("some_event", {value: "foo"})

Event List

The following list of events is not exhaustive as the chart is still under heavy development and subject to change until the release of version 1.0.

  • addIndicatorDone
  • addSecondary
  • chart_pan
  • chart_panDone
  • chart_render
  • chart_yAxisRedraw
  • divider_pointerdrag
  • divider_pointerdragend
  • Error
  • event_selected
  • global_resize
  • main_mousemove
  • scrollUpdate
  • setRange
  • trade_selected
  • zoomDone