phpjquerylaravelhighcharts

Highcharts error 14 when passing in an manually created JSON string


I'm in need of help passing info to Highcharts in order to chart durations. Part of the application I'm working on tracks the times of a baby's diaper changes. When run, I get Highcharts error #14, which I know is the passing of a string, rather than a number. I tried changing the datatype of my x-axis, but the error still appears.

The graph code:

`$(function () { 
    $('#diaperContainer').highcharts({
        title: {
            text: 'Diaper Chart'
        },
        chart: {
            type: 'line'
        },
        xAxis: {
            type: 'datetime',
            title: {
                text: 'Time of Diaper Change'
            }
        },
        yAxis: {
            title: {
                text: 'Type of Change'
            }
        },
        tooltip: {
            backgroundColor: '#FCFFC5',
            borderColor: 'black',
            borderRadius: 10,
            borderWidth: 3,
            shared: true,
        },
        series: [{
            data: [{{ $diaperData }}]
        }]
    });
});`

The logic in the event controller, pulling database info:

$diaperData = array();
    $diapers = $baby->diapers;

    foreach ($diapers as $diaper) {
        if ($diaper->number_one && $diaper->number_two){
            array_push($diaperData, "['" . date('Y-m-d H:i:s', strtotime($diaper->created_at)) . "', '3']");
        } elseif ($diaper->number_one){
            array_push($diaperData, "['" . date('Y-m-d H:i:s', strtotime($diaper->created_at)) . "', '1']");
        } elseif ($diaper->number_two) {
            array_push($diaperData, "['" . date('Y-m-d H:i:s', strtotime($diaper->created_at)) . "', '2']");
        }
    }
    $diaperData = join($diaperData, ',');

Solution

  • Did you try dropping the ticks around the numbers 1, 2 and 3 in the event controller?