当我将代码从Jsfiddle传输到我的服务器时,为什么我的Highchart看起来有所不同?

时间:2018-04-17 03:29:59

标签: javascript highcharts

我从Jsfiddle获取了我的确切代码并将其添加到我服务器上的代码中。图表绘制,但它以奇怪的方式格式化。没有控制台错误。

此处的图片显示了图表在我的网站上的显示方式:Image

这是JSfiddle(它应该看的样子):http://jsfiddle.net/smq59yf9/33/

CODE:

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/broken-axis.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="ContainerGraph1" style="width: 500px; height: 400px; margin: 0 auto"></div>

JAVASCRIPT

Highcharts.wrap(Highcharts.Axis.prototype, 'getLinePath', function (proceed, lineWidth) {
    var axis = this,
        path = proceed.call(this, lineWidth),
        x = path[1],
        y = path[2];

    Highcharts.each(this.breakArray || [], function (brk) {
        if (axis.horiz) {
            x = axis.toPixels(brk.from);
            path.splice(3, 0,
                'L', x - 4, y, // stop
                'M', x - 9, y + 5, 'L', x + 1, y - 5, // left slanted line
                'M', x - 1, y + 5, 'L', x + 9, y - 5, // higher slanted line
                'M', x + 4, y
            );
        } else {
            y = axis.toPixels(brk.from);
            path.splice(3, 0,
                'L', x, y - 4, // stop
                'M', x + 5, y - 9, 'L', x - 5, y + 1, // lower slanted line
                'M', x + 5, y - 1, 'L', x - 5, y + 9, // higher slanted line
                'M', x, y + 4
            );
        }
    });
    return path;
});

/**
 * On top of each column, draw a zigzag line where the axis break is.
 */
function pointBreakColumn(e) {
    var point = e.point,
        brk = e.brk,
        shapeArgs = point.shapeArgs,
        x = shapeArgs.x,
        y = this.translate(brk.from, 0, 1, 0, 1),
        w = shapeArgs.width,
        key = ['brk', brk.from, brk.to],
        path = ['M', x, y, 'L', x + w * 0.25, y + 4, 'L', x + w * 0.75, y - 4, 'L', x + w, y];

    if (!point[key]) {
        point[key] = this.chart.renderer.path(path)
            .attr({
                'stroke-width': 2,
                stroke: point.series.options.borderColor
            })
            .add(point.graphic.parentGroup);
    } else {
        point[key].attr({
            d: path
        });
    }
}

Highcharts.chart('ContainerGraph1', {
    chart: {
        type: 'line'
    },
    title: {
        text: 'Monthly Average Temperature'
    },

    xAxis: {
     lineColor: 'black',
        lineWidth: 2,
                title: {
            text: 'Temperature (°C)'
        }

    },
    yAxis: {
     lineColor: 'black',
        lineWidth: 2,
        breaks: [{
            from: 1,  //adds break 
            to: 3
        }],

        title: {
            text: 'Temperature (°C)'
        }
    },
    credits: {
      enabled: false
  },
  exporting: { enabled: false },
    plotOptions: {
        line: {
            dataLabels: {
                enabled: false
            },
            enableMouseTracking: false
        }
    },
     legend: {
            enabled: false // hides legend 
        },
    series: [{
        name: 'Tokyo',
         color: '#000000',
        data: [[1999,7],[2000,8], [2001,10], [2002,12], [2003,27]  ]
    }, {
        name: 'London',
        data: [[1999,6]], // include if want to keep break 
         color: '#ffffff'
    }]
});

如果有人知道为什么会这样格式化,我会非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

总是检查CSS ...我在代码中的其他地方使用了一些相同的变量,它搞砸了Highchart的格式。