javascript - 减少 Highcharts 中点之间的距离

标签 javascript highcharts

我正在尝试减少图表上数据点之间的距离,下面的代码来自 highcharts 示例

$(function () {
$(document).ready(function() {
    Highcharts.setOptions({
        global: {
            useUTC: false
        }
    });

    var chart;
    $('#container').highcharts({
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 5,
            events: {
                load: function() {

                    // set up the updating of the chart each second
                    var series = this.series[0];
                    setInterval(function() {
                        var x = (new Date()).getTime(), // current time
                            y = Math.random();
                        series.addPoint([x, y], true, true);
                    }, 1000);
                }
            }
        },
        title: {
            text: 'Live random data'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 50 // here i wanted to decerease bu it does not work
        },
        yAxis: {
            title: {
                text: 'Value'
            },
            plotLines: [{
                value: 0,
                width: 0.1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{ // series with random data
            name: 'Random data', // may be here 
            data: (function() {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;

                for (i = -19; i <= 0; i++) {
                    data.push({
                        x: time + i * 1000,
                        y: Math.random()
                    });
                }
                return data;
            })()
        }]
    });
});

  });

http://jsfiddle.net/V9BV4/

可以制作吗?我需要缩小 xAxis 或减小线上点之间的距离

最佳答案

为了执行您所要求的操作,您可能需要考虑:

1) 缩小图表,使各个点靠得更近(参见 http://jsfiddle.net/brightmatrix/Gq9X9/ ):

chart: {
    vtype: 'spline',
    width: 300,     /* make this value anything you want */
    animation: Highcharts.svg, // don't animate in old IE
    marginRight: 5,
    ...

这与上面提供的@falconw 的建议类似。

2) 在这个特定的实时示例中,更改数据的计算方式,以便每次更新图表时推出更多点(请参阅 http://jsfiddle.net/brightmatrix/Fp5K4/ ):

series: [{
    name: 'Random data',
    data: (function() {
        // generate an array of random data
            var data = [],
            time = (new Date()).getTime(),
            i;
            for (i = -19; i <= 0; i++) {
                data.push({
                    /* made the multiplier larger so points are closer together */
                    x: time + i * 10000,    
                    y: Math.random()
                });
            }
        return data;
    })()
}] 

底线,要么更改图表尺寸,要么使数据“更密集”,使点更加靠近。我希望这会有所帮助。

关于javascript - 减少 Highcharts 中点之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23737255/

相关文章:

javascript - Highcharts 下载带有 svg 模式的图表

javascript - Highchart 中多个标签的问题

javascript - 如何使用来自 CSV 的数据将分钟设置为 Highstock 图表中的单位

javascript - 如何在 PHP 联系表单中附加选择列表

javascript - 调整大小时,ScrollMagic 不尊重我的 div 的高度

javascript - Python : How to scrape a page to get an information that will be used to scrape another one, 等等?

javascript - 更改输入元素的只读属性: ReactJS

javascript - Blur.JS 不适用于 Amazon S3 图像

Highcharts 上下文菜单按钮在同一图表中出现三次

html - "display: none"with highcharts - 大小不正确