0

我正在尝试制作热图 highcart。我正在绘制一定时间内所有购买的图表。我有一组数据点数组[[timestamp,purchase amount],[timestamp,purchase amount]]。我希望我的图表有一个显示购买金额的 y 轴和一个显示购买时间的 x 轴(所有时间都在上午 8 点到下午 6 点之间)。购买日期无关紧要,只有时间无关。我不得不作弊并使 x 轴时间线性化,并使时间像 10.55 (10:55) 一样浮动。这显然不是一个好的解决方案,因为它会在图表中留下空白 (.6-.99)。除了线性之外,我所做的任何尝试都会给我一个显示从午夜开始几分钟的 x 轴。这是我当前的代码,解决方法很差。

function scatterChartTimeMapper(timestamp){
        var ourDate = new Date(timestamp*1000);
        var hour = (ourDate.getHours()+1).toString();
        var mins = ourDate.getMinutes();

        if(mins<10)
            mins = "0" + mins;
        if(mins%10===0)
            mins = mins.toString();

        var time = hour + "."  + mins;

        return parseFloat(time);
} 

for(i=0;i<data.length;i++)
        {    
            var timePoint =      scatterChartTimeMapper(parseFloat(data[i].trim()));
            var segmentArray = [timePoint,parseFloat(data[i+1].trim())];
            newArray.push(segmentArray);
            i++;
        }

我的图表 JSON 是:数据:

            { 
                chart: {
                    type: 'scatter',
                    backgroundColor : 'transparent',
                    zoomType: 'xy'
                },
                title: {
                    text: bundle.action_fields_full.chart_title
                },
                subtitle: {
                    text: bundle.action_fields_full.sub_title
                },
                xAxis: {
                    title: {
                        enabled: true,
                        text: 'Time Of Day'
                    },
                    type : 'linear',
                    startOnTick: true,
                    endOnTick: true,
                    showLastLabel: true
                },
                yAxis: {
                    title: {
                        text: 'Tranaction Amount'
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 55,
                    floating: true,
                    backgroundColor: '#FFFFFF',
                    borderWidth: 1
                },
                plotOptions: {
                    scatter: {
                        marker: {
                            radius: 5,
                            states: {
                                hover: {
                                    enabled: true,
                                    lineColor: 'rgb(100,100,100)'
                                }
                            }
                        },
                        states: {
                            hover: {
                                marker: {
                                    enabled: false
                                }
                            }
                        },
                        tooltip: {
                            headerFormat: '<b>{series.name}</b><br>',
                            pointFormat: 'Time {point.x} , €{point.y} '
                        }
                    }
                },
                series: [{
                    name: 'Transactions',
                    color: 'rgba(223, 83, 83, .5)',
                    data: newArray
                }]
            } };
4

0 回答 0