javascriptecharts

How to create Forecast Chart using ECharts


I want to create a forecast chart with Actual (a line chart) and projected values (a dotted chart). Here is an example made with Excel: enter image description here

I want to create the same chart using the ECharts library but I couldn't find any example to use from their web page https://echarts.apache.org/examples/en/:

It would be very helpful if there is an approach to build this chart using javascript, I don't mind using other libraries like ChartJs if they have this possibility.


Solution

  • try this.

    option = {
        xAxis: {
            type: 'category',
            data: [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            data: [0, 20, 30, 45, 40, 50, 51, 52, 50, 49, 56, 55],
            type: 'line',
            smooth: true,
            lineStyle: {
                color: 'red'
            }
        }, {
            data: [null, null, null, null, null, null, null, null, null, null, null, 55, 50, 49, 48],
            type: 'line',
            smooth: true,
            lineStyle: {
                color: 'blue',
                type: 'dashed'
            }
        }]
    };
    

    It's a very simple example but it should solve your issue. I didn't add the legend, but you should be able to do that without any issues.