8

I'm in the planning process for a java based application that is used for live streaming/trading of stock/forex etc. charts. However I am not sure which charting library is the right one for the job.

Basically the charting functionality should be the same as in any trading software, such as:

  • Candlestick and/or OHLC bar charts, line charts
  • Overlaying those with other charts (Aka plotting an Moving average or similar over the candlestick chart)
  • User should be able to add lines or other objects to the chart
  • Displaying 2 charts, for example to show volume below the main chart
  • Zoom into the chart**
  • Horizontal scrolling/panning**
  • Auto-adjusting of Y axis while scrolling/panning
  • Updating of the chart when new data arrives (happens in random ms intervals), which does not only include a new OHLC data point to be added, but also to update the last OHLC data point if new data arrives before the timeframe indicates a new data point**
  • interaction with the chart such as highlighting an object the mouse points to***
  • giving back coordinates, that can be used to get the data points information, or directly get its information (OHLC data, timestamp)

** could also be done by creating a new chart each time a user action is done instead of letting the chart library do the work - however only viable if it is fast, see performance requirements.

*** Nice but not mandatory.

To make it clear - I am not searching for some magic library that does it all for me. I have no problem with writing code to get my full feature set. But some features can only reliably be implemented by the library itself (such as transforming chart coordinates from a mouse click to the right data points, because those coordinates are dependent on the size of the x and y labels, meaning guesstimating would be a bad approach), other features, when added, must still be fast enough. Depending on the library, this may not be possible.

Performance is a key factor. I have done most of this coding in python already, using matplotlib. However the more candles on the chart, the slower it gets, to a point where using multiple charts with enough data on each chart makes updates in millisecond intervals impossible in real time, despite long efforts to optimize the code. In addition, that code is restricted to one core(thanks to python GIL), no matter how many charts. So its understandable that I am desperately looking for a speedy solution and switched to java. So lets say having open 10 charts at the same time, with a few hundred OHLC data points, all updating at once should not cause a major impact in performance, barely noticeable to the human eye. This is something that can be done using java, as various commercial projects show (Oanda and Dukascopy java clients for example).

The question is, which library is up for the task? jFreeChart? JavaFX charting directly? Other options?

Does anyone know what libraries commercial projects use?

3 Answers 3

1

Vaadin Charts

If you want a web app solution written in pure Java but automagically rendered in a web browser with HTML5 web standards technologies, I suggest looking at the Vaadin Framework (open-source, free-of-cost) plus the Vaadin Charts add-on (commercial).

The Vaadin Charts add-on is a Java wrapper (to be invoked server-side) wrapping the HighCharts library built in JavaScript (used client-side in rendering the chart, but transparently to the Java programmer). So most anything HighCharts via JavaScript can do so can Vaadin Charts do via Java calls. Y

With Vaadin Charts, you get the best of both worlds: (a) all the power of Java and its many libraries, JDBC, static typing, speed, reliability, and such, along with (b) high-performance drawing of the chart within the browser locally using JavaScript.

I do not know if Vaadin Charts meets all your needs, but it does provide Candlestick charts and OHLC charts.

Vaadin has built-in support for Push technology, so your charts can be automatically updated in the web browser without user-promoting.

1

With JavaScript approach, as web content in your Java app, you can add LightningChart JS. It's been made with WebGL, and performance is magnitudes faster when comparing to Java or other JavaScript charts. LightningChart can render up to 100 million data points in real-time.

Fast zooming, scrolling, panning etc. is supported, and OHLC, mountains, line series etc. naturally.

Trading example (static data) Trading chart

There's plenty of interactive real-time examples here

1

I can't believe someone hasn't mentioned SciChart's JavaScript Chart yet!

Here's a javascript stock chart demo which encompasses the following:

  • Multiple panes with technical indicators
  • Candlestick data loaded in from CSV
  • Moving averages
  • MACD and RSI indicator panels
  • Cursor/crosshair under the mouse
  • Active legend which updates as you move the crosshair
  • Zooming, panning

JavaScript Candlestick Chart, Stock Chart, Financial Chart

A second demo which shows you how to fetch data from an exchange (BTC/USDT from Binance) and subscribe to Websocket can be found here: candlestick charts

This demo handles live updating of market data in the chart and can also be zoomed, panned.

No, it's not a JavaFX library, however it can be placed inside a WebView. Other libraries are available from SciChart such as a native Android (Kotlin/Java) trading library, native iOS trading library (Swift) and Windows / WPF.

For some performance metrics, see here: SciChart consistently benches as the fastest javascript chart, much to the dismay of competitors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.