3
votes

I want to create a scater with datetime as the xAxis, I managed to do so but the x-interval is with days, I am having a hard time doing so where the x-interval is with minutes.

My JS:

function startDashboard3DScatter() {
    $.getJSON('/Handlers/MainHandler.ashx?op=getNetwork', function (data) {
        Highcharts.getOptions().colors = $.map(Highcharts.getOptions().colors, function (color) {
            return {
                radialGradient: {
                    cx: 0.4,
                    cy: 0.3,
                    r: 0.5
                },
                stops: [
                    [0, color],
                    [1, Highcharts.Color(color).brighten(-0.2).get('rgb')]
                ]
            };
        });
        // Set up the chart
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'networkAlerts',
                margin: 100,
                type: 'scatter',
                width: 600,
                height: 300,
                options3d: {
                    enabled: true,
                    alpha: 10,
                    beta: 30,
                    depth: 250,
                    viewDistance: 5,

                    frame: {
                        bottom: { size: 1, color: 'rgba(0,0,0,0.02)' },
                        back: { size: 1, color: 'rgba(0,0,0,0.04)' },
                        side: { size: 1, color: 'rgba(0,0,0,0.06)' }
                    }
                }
            },
            title: {
                text: 'Network'
            },
            plotOptions: {
                scatter: {
                    width: 100,
                    height: 100,
                    depth: 20
                },
                series: {
                    marker: {
                        lineWidth: 1
                    }
                }
            },
            yAxis: {
                min: 0,
                title: { text: 'Risk Score' }
            },
            xAxis: {
                min: 0,
                max: 6,
                gridLineWidth: 1,
                title: { text: 'Time line' },
                labels: {
                    formatter: function () {
                        var date = new Date();
                        date.setDate(date.getDate() - this.value);
                        return date.toDateFormat();// this.value + ' %';
                    }
                }
            },
            zAxis: {
                min: 0,
                max: 10
            },
            legend: {
                enabled: false
            },
            series: data
        });
    });
};

My data response from the get request =

data = 
[ 
    {"name":"name1", "id":"D/1", "color": "#55BF3B", "data": [[6, 100]]},
    {"name":"name2", "id":"D/5", "color": "#55BF3B", "data": [[3, 1]]}
]

The data is ['days before today, yValue']

So i have done this where i send the days before today and i format xAxis, the problem as i said is that the points are with 1day interval and i want to make it 1 minute or 1 hour interval.

Any ideas, I am stuck on this for days.

1

1 Answers

2
votes

Ok the solution wasn't very hard after all:

Changed:

labels: {
    formatter: function () { 
        var date = new Date(new Date().getTime() - (this.value * 60 * 60 * 1000));
        return date.toDateFormat();
    }
}

And in the Server code return the hours instead of days and it works.