Date on a Highstock chart

0

I'm trying to create a chart with the framework Highcharts to create a chart, which framewor itself provides, highstock .

I am trying to generate a line type graph, the values are correct, but the date is wrong. I looked in a file of the framework where in the examples which they demonstrate, search the data.

A part of the excerpt:

[
[1285718400000,41.05],
[1285804800000,40.54],
/* Oct 2010 */
[1285891200000,40.36],
[1286150400000,39.81],
[1286236800000,41.28],
[1286323200000,41.31],
[1286409600000,41.32],
[1286496000000,42.01],
[1286755200000,42.19],
[1286841600000,42.65],
[1286928000000,42.88],
[1287014400000,43.19],
[1287100800000,44.96],
[1287360000000,45.43],
[1287446400000,44.21],
[1287532800000,44.36],
[1287619200000,44.22],
[1287705600000,43.92],
[1287964800000,44.12],
[1288051200000,44.01],
[1288137600000,43.98],
[1288224000000,43.61],
[1288310400000,43.00],
/* Nov 2010 */
[1288569600000,43.45],
[1288656000000,44.19],
[1288742400000,44.69],
[1288828800000,45.47],
[1288915200000,45.30],
[1289174400000,45.52],

I soon realized that the left values, with 13 characters, could be the date.

In my code I did it this way:

Note: The two code snippets are in the same file.

PHP:

$valorTendencia[] = array(strtotime($value->DataHoraPrevisao),$value->Valor);
$encodeValorTendencia = json_encode($valorTendencia, JSON_NUMERIC_CHECK);

JavaScript:

<script type="text/javascript"> 
    // Create the chart
    Highcharts.stockChart('container', {

        rangeSelector: {
            selected: 1
        },

        title: {
            text: 'AAPL Stock Price'
        },

        series: [{
            name: 'AAPL',
            data: <?php echo $encodeValorTendencia; ?>
        },{
            name: 'Teste',
            data: <?php echo $encodeValorObtencao; ?>
        }]
    });
</script>

But get a date from 1970, and the dates I want are current.

In the variable $value->DataHoraPrevisao is the dates that I want to use and are in this format: (string) 2017-09-01 03:00:00 .

At API I could not find anything related.

    
asked by anonymous 27.09.2017 / 18:24

1 answer

1

I was able to solve by concatenating a string in front of strtotime($value->DataHoraPrevisao) , being as follows:

$valorTendencia[] = array(strtotime($value->DataHoraPrevisao)."000",$value->Valor);
$encodeValorTendencia = json_encode($valorTendencia, JSON_NUMERIC_CHECK);
    
27.09.2017 / 20:09