Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用表格显示HighCharts_Javascript_Jquery_Html_Highcharts - Fatal编程技术网

Javascript 如何使用表格显示HighCharts

Javascript 如何使用表格显示HighCharts,javascript,jquery,html,highcharts,Javascript,Jquery,Html,Highcharts,我正试图通过高图表和表格一起显示表格数据。但不知何故,图表和表格并没有显示在html页面中。我的代码如下。我需要在标签之间写下吗?如果我打印普通文本,它就会显示出来 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/

我正试图通过
高图表
和表格一起显示表格数据。但不知何故,图表和表格并没有显示在html页面中。我的代码如下。我需要在
标签之间写下吗?如果我打印普通文本,它就会显示出来

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
        charts
    </title>
    <script src="js/jquery-migrate-1.0.0.js" type="text/javascript"></script>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        /**
        * Create the data table
        */
        Highcharts.drawTable = function () {
            // user options
            var tableTop = 310,
                colWidth = 100,
                tableLeft = 20,
                rowHeight = 20,
                cellPadding = 2.5,
                valueDecimals = 1,
                valueSuffix = ' °C';
            // internal variables
            var chart = this,
                series = chart.series,
                renderer = chart.renderer,
                cellLeft = tableLeft;
            // draw category labels
            $.each( chart.xAxis[0].categories, function ( i, name ) {
                renderer.text(
                    name,
                    cellLeft + cellPadding,
                    tableTop + ( i + 2 ) * rowHeight - cellPadding
                ).css( {
                    fontWeight: 'bold'
                } ).add();
            } );
            $.each( series, function ( i, serie ) {
                cellLeft += colWidth;
                // Apply the cell text
                renderer.text(
                    serie.name,
                    cellLeft - cellPadding + colWidth,
                    tableTop + rowHeight - cellPadding
                ).attr( {
                    align: 'right'
                } ).css( {
                    fontWeight: 'bold'
                } ).add();

                $.each( serie.data, function ( row, point ) {

                    // Apply the cell text
                    renderer.text(
                        Highcharts.numberFormat( point.y, valueDecimals ) + valueSuffix,
                        cellLeft + colWidth - cellPadding,
                        tableTop + ( row + 2 ) * rowHeight - cellPadding
                    )
                        .attr( {
                            align: 'right'
                        } )
                        .add();

                    // horizontal lines
                    if ( row == 0 ) {
                        Highcharts.tableLine( // top
                            renderer,
                            tableLeft,
                            tableTop + cellPadding,
                            cellLeft + colWidth,
                            tableTop + cellPadding
                        );
                        Highcharts.tableLine( // bottom
                            renderer,
                            tableLeft,
                            tableTop + ( serie.data.length + 1 ) * rowHeight + cellPadding,
                            cellLeft + colWidth,
                            tableTop + ( serie.data.length + 1 ) * rowHeight + cellPadding
                        );
                    }
                    // horizontal line
                    Highcharts.tableLine(
                        renderer,
                        tableLeft,
                        tableTop + row * rowHeight + rowHeight + cellPadding,
                        cellLeft + colWidth,
                        tableTop + row * rowHeight + rowHeight + cellPadding
                    );

                } );

                // vertical lines
                if ( i == 0 ) { // left table border
                    Highcharts.tableLine(
                        renderer,
                        tableLeft,
                        tableTop + cellPadding,
                        tableLeft,
                        tableTop + ( serie.data.length + 1 ) * rowHeight + cellPadding
                    );
                }

                Highcharts.tableLine(
                    renderer,
                    cellLeft,
                    tableTop + cellPadding,
                    cellLeft,
                    tableTop + ( serie.data.length + 1 ) * rowHeight + cellPadding
                );
                if ( i == series.length - 1 ) { // right table border
                    Highcharts.tableLine(
                        renderer,
                        cellLeft + colWidth,
                        tableTop + cellPadding,
                        cellLeft + colWidth,
                        tableTop + ( serie.data.length + 1 ) * rowHeight + cellPadding
                    );
                }

            } );
        };
        /**
        * Draw a single line in the table
        */
        Highcharts.tableLine = function ( renderer, x1, y1, x2, y2 ) {
            renderer.path( ['M', x1, y1, 'L', x2, y2] )
                .attr( {
                    'stroke': 'silver',
                    'stroke-width': 1
                } )
                .add();
        }
        /**
        * Create the chart
        */
        window.chart = new Highcharts.Chart( {
            chart: {
                renderTo: 'container',
                events: {
                    load: Highcharts.drawTable
                },
                borderWidth: 2
            },
            title: {
                text: 'Average monthly temperatures'
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },
            yAxis: {
                title: {
                    text: 'Temperature (°C)'
                }
            },
            legend: {
                y: -300
            },
            series: [{
                name: 'Tokyo',
                data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
            }, {
                name: 'New York',
                data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
            }, {
                name: 'Berlin',
                data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
            }, {
                name: 'London',
                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
            }]
        } );
    </script>
</head>
<body>
    <script type="text/javascript" src="http://www.highcharts.com/js/testing-exporting.js"></script>
    <div id="container" style="height: 600px;margin-top:20px;width: 600px"></div>

</body>
</html>

图表
/**
*创建数据表
*/
Highcharts.drawTable=函数(){
//用户选项
var桌面=310,
colWidth=100,
表左=20,
行高=20,
单元填充=2.5,
valueDecimals=1,
valueSuffix=‘摄氏度’;
//内部变量
var图表=此,
series=chart.series,
renderer=chart.renderer,
cellLeft=tableLeft;
//绘制类别标签
$.each(chart.xAxis[0]。类别,函数(i,名称){
.text(
名称
单元格左+单元格填充,
桌面+(i+2)*行高-单元格填充
).css({
fontWeight:“粗体”
})。添加();
} );
$。每个(系列,功能(i,系列){
cellLeft+=colWidth;
//应用单元格文本
.text(
serie.name,
cellLeft-cellPadding+colWidth,
桌面+行高-单元格填充
).attr({
对齐:“右”
})。css({
fontWeight:“粗体”
})。添加();
$.each(系列数据、函数(行、点){
//应用单元格文本
.text(
Highcharts.numberFormat(点y,数值小数)+数值后缀,
cellLeft+colWidth-cellPadding,
桌面+(行+2)*行高-单元格填充
)
.attr({
对齐:“右”
} )
.add();
//水平线
如果(行==0){
Highcharts.tableLine(//顶部
渲染器,
表左,
桌面+手机垫,
cellLeft+colWidth,
桌面+手机垫
);
Highcharts.tableLine(//底部
渲染器,
表左,
桌面+(serie.data.length+1)*行高+单元格填充,
cellLeft+colWidth,
桌面+(serie.data.length+1)*行高+单元格填充
);
}
//水平线
海图.台线(
渲染器,
表左,
桌面+行*行高+行高+单元格填充,
cellLeft+colWidth,
桌面+行*行高+行高+单元格填充
);
} );
//垂直线
如果(i==0){//左表边框
海图.台线(
渲染器,
表左,
桌面+手机垫,
表左,
桌面+(serie.data.length+1)*行高+单元格填充
);
}
海图.台线(
渲染器,
左撇子,
桌面+手机垫,
左撇子,
桌面+(serie.data.length+1)*行高+单元格填充
);
如果(i==series.length-1){//右表边框
海图.台线(
渲染器,
cellLeft+colWidth,
桌面+手机垫,
cellLeft+colWidth,
桌面+(serie.data.length+1)*行高+单元格填充
);
}
} );
};
/**
*在表格中画一条线
*/
Highcharts.tableLine=函数(渲染器,x1、y1、x2、y2){
路径(['M',x1,y1',L',x2,y2])
.attr({
“笔划”:“银色”,
“笔划宽度”:1
} )
.add();
}
/**
*创建图表
*/
window.chart=新的Highcharts.chart({
图表:{
renderTo:'容器',
活动:{
加载:Highcharts.drawTable
},
边框宽度:2
},
标题:{
文字:“月平均气温”
},
xAxis:{
类别:[一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月]
},
亚克斯:{
标题:{
文字:“温度(°C)”
}
},
图例:{
y:-300
},
系列:[{
名称:"东京",,
数据:[7.0,6.9,9.5,14.5,18.2,21.5,25.2,26.5,23.3,18.3,13.9,9.6]
}, {
名称:'纽约',
数据:[-0.2,0.8,5.7,11.3,17.0,22.0,24.8,24.1,20.1,14.1,8.6,2.5]
}, {
名称:“柏林”,
dat