使用highcharts画图

本文介绍如何使用Highcharts库绘制柱状图,并提供了详细的配置参数说明。包括图表样式设置、数据展示方式及交互功能实现等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript" src="Scripts/jquery-1.7.min.js"></script>
<script type="text/javascript" src="Scripts/highcharts/highcharts.js"></script> <script type="text/javascript" src="Scripts/highcharts/themes/grid.js"></script>

 

        //renderTo    要显示的ID
        //title_text  标题
        //subtitle    副标题
        //yAxis_text  Y轴文字
        //tip_text    提示文字
        //series_name 分组的名称
        //series_data 数据
        function drawColumn(renderTo, title_text, subtitle, yAxis_text,tip_text,series_name, series_data) {
            $(document).ready(function () {
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: renderTo,  //放置图表的容器
                        type: 'column'       //图表类型
                    },
                    title: {                //主标题
                        text: title_text
                    },
                    subtitle: {             //副标题
                        text: subtitle
                    },
                    credits: {
                        enabled: false      //禁用名片
                    },
                    exporting: {
                        enabled: false      //禁用导出,打印图片按钮
                    },
                    xAxis: {
                        categories: [
                                '1月',
                                '2月',
                                '3月',
                                '4月',
                                '5月',
                                '6月',
                                '7月',
                                '8月',
                                '9月',
                                '10月',
                                '11月',
                                '12月'
                            ],
                        labels: {
                            //rotation: -45,//控制斜体
                            align: 'right',
                            style: {font: 'normal 10px 宋体'},
                            x:5
                            }
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: yAxis_text
                        }
                    },
                    legend: {
                        layout: 'vertical',
                        backgroundColor: '#FFFFFF',
                        align: 'left',
                        verticalAlign: 'top',
                        x: 100,
                        y: 70,
                        floating: true,
                        shadow: true,
                        enabled:false//禁用图例
                    },
                    tooltip: {
                        formatter: function () {
                            return '' + this.x + ': ' + Highcharts.numberFormat(this.y)+tip_text;
                        }
                    },
                    plotOptions: {
                        column: {
                             cursor: 'pointer',
                             //allowPointSelect:true,
                             point: {
                                events: {
                                    click: function() {
                                        //window.open();                                       
                                        tt(this.x+1);//点击柱子跳转URL                                        
                                    }
                                }
                            },
                            pointPadding: 0.2,
                            borderWidth: 0,
                            pointWidth:15    //显示的宽度
                        }
                    },                    
                    series: [{
                        name: series_name,
                        data: series_data,  //逗号不要多余
                        dataLabels:{     //在柱子的顶部显示值
                            enabled:true,
                            formatter:function(){
                                if(this.y>0){
                                    return Highcharts.numberFormat(this.y);
                                }                                
                            }
                        }
                    }]
                });
            });
        }
    </script>
    <script type="text/javascript">
        function tt(month) {
            window.location.href = "SearchCer.aspx?month=" + month;
        }
    </script>

如果你想对一个柱子使用不同的颜色的话:将series中的 data格式改成这样: [{"color":"red","y":49.9}],加入一个color属性控制它的颜色

转载于:https://www.cnblogs.com/wubh/archive/2012/08/21/2649139.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值