Search code examples
javascriptcandlestick-chartlightweight-charts

lightweight-charts Uncaught Error: Value is null


Lightweight Charts Version: 3.1.3

I am using your chart for the cryptocurrency trade application in Vue project but no matter what I get this error below is a sample code

There is no duplicated or null data.


import {createChart} from "lightweight-charts";
export default {
data() {
return {
                chartProperties: {
                  width: 700,
                  height: 300,
                  timeScale: {
                     timeVisible: true,
                     secondsVisible: false
                },
                layout: {
                    //backgroundColor: '#262C49', //Dark Theme
                    //textColor: '#80859E',
                    fontSize: 12,
                    fontFamily: 'irsans ,Calibri'
                }
            },
            chartData: [],
            candleSeries: null,
}
}
mounted() {

let cdata = [
{
close: 22750.76
high: 22759.53
low: 22750.25
open: 22752.8
time: 1608635340
},
....
];

this.chartElement = document.getElementById('chart');
this.chartProperties.width = this.chartElement.offsetWidth;
this.chart = createChart(this.chartElement, this.chartProperties);
this.candleSeries = this.chart.addCandlestickSeries();

this.candleSeries.setData(cdata);

Actual behavior:

The chart is drawn with no candlestick

enter image description here

and repeated error of Uncaught Error: Value is null

enter image description here

jsfiddle


Solution

  • If you get this error 99% chance that your data source has one of three problems

    1. part of the data is null
    2. there is duplication on data in timestamp
    3. my problem: data should be ordered by time in ASC order, not in desc.