GasparPereira04
Posts: 3
Joined: Fri Jan 07, 2022 1:35 am

Add point to chart

Hi, when i add data to chart have an error?
Captura de ecrã 2022-01-07 013935.png
Captura de ecrã 2022-01-07 013935.png (47.51 KiB) Viewed 214 times
My data to add ↷
Captura de ecrã 2022-01-07 013831.png
Captura de ecrã 2022-01-07 013831.png (11.09 KiB) Viewed 214 times
My function to add point ↷
Captura de ecrã 2022-01-07 014010.png
Captura de ecrã 2022-01-07 014010.png (16.91 KiB) Viewed 214 times
My axis config ↷

Code: Select all

chart: {
            renderTo:'chart_cont',
            type: 'line'
        },
        title: {
            text: 'Visualizações'
        },
        xAxis: {
            title: {
                text: 'Data'
            },
            type: 'text'
        },
        yAxis: {
            title: {
                text: 'Visualizações'
            }
        },
        series: [{
            name: 'Visualizações/Dia',
            showInLegend: true,
            data: []
        }],
        plotOptions: {
            line: { animation: false,
              dataLabels: { enabled: true }
            },
            series: { color: '#FF6A00' }
          }
       });
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Add point to chart

Hi GasparPereira04,

Welcome to our forum and thanks for contacting us with your question!

If I understood correctly the problem is that dates are not shown on X axis. It doesn't work because in Highcharts, dates should be expressed in UNIX timestamp format (milliseconds since Jan 1st 1970). Please provide me with a sample of your data and I will show you how to parse it.

Regards!
Mateusz Bernacik
Highcharts Developer
GasparPereira04
Posts: 3
Joined: Fri Jan 07, 2022 1:35 am

Re: Add point to chart

Code: Select all

{views: '115', data_day: '2022-01-04'}
{views: '14', data_day: '2022-01-05'}
{views: '112', data_day: '2022-01-06'}
{views: '12', data_day: '2022-01-07'}
data_day in X axis and views in Y axis
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Add point to chart

Hi GasparPereira04,

Thanks for sharing your sample data.

Here you can find two examples with your parsed data:
- datetime X axis, in this case Highcharts expects dates to be in UNIX timestamp format, expressed in milliseconds:
Demo: https://jsfiddle.net/BlackLabel/3fqt4pr1/

- category X axis:
Demo: https://jsfiddle.net/BlackLabel/0cLx4vs9/
or https://jsfiddle.net/BlackLabel/mn45yhv0/

API reference: https://api.highcharts.com/highcharts/xAxis.type

Let me know if that was what you were looking for!
Regards!
Mateusz Bernacik
Highcharts Developer
GasparPereira04
Posts: 3
Joined: Fri Jan 07, 2022 1:35 am

Re: Add point to chart

thanks, now it works but i only use 'chart.series[0].setData(data);' and X axis type category, i dont need reemap the data,
thanks for your help
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Add point to chart

You're welcome! In case of any further questions, feel free to contact us again.
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”