強大的jQuery Chart組件-Highcharts

來源:互聯網
上載者:User

Highcharts是一個製作圖表的純Javascript類庫,主要特性如下:

  • 相容性:相容當今所有的瀏覽器,包括iPhone、IE和Firefox等等;
  • 對個人使用者完全免費;
  • 純JS,無BS;
  • 支援大部分的圖表類型:直線圖,曲線圖、地區圖、地區曲線圖、柱狀圖、餅裝圖、散布圖;
  • 跨語言:不管是PHP、Asp.net還是Java都可以使用,它只需要三個檔案:一個是Highcharts的核心檔案highcharts.js,還有a canvas emulator for IE和Jquery類庫或者MooTools類庫;
  • 提示功能:滑鼠移動到圖表的某一點上有提示資訊;
  • 放大功能:選中圖表部分放大,近距離觀察圖表;
  • 易用性:無需要特殊的開發技能,只需要設定一下選項就可以製作適合自己的圖表;
  • 時間軸:可以精確到毫秒

下載外掛程式

Highcharts

http://www.highcharts.com/download

jquery

http://jquery.com/

本次介紹是把highcharts中的第一個檔案拷貝過來,然後把其他的功能加在了這個檔案中,然後查詢相關資料,匯出圖片格式不需要連到官方伺服器了,只需要在本地就可以。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="highchart_export_module_asp_net._Default" %>

<!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 runat="server">
    <title>Highchart js export module sample</title>
    <!-- 1.引入jquery庫 -->
    <script src="Javascript/jquery-1.5.1.js" type="text/javascript"></script>
    <!-- 2.引入highcharts的核心檔案 -->
    <script src="http://highcharts.com/js/highcharts.js" type="text/javascript"></script>
    <!-- 3.引入匯出需要的js庫檔案 -->
    <script src="http://highcharts.com/js/modules/exporting.js" type="text/javascript"></script>
</head>
<script language="javascript" type="text/javascript">
    var chart;
    $(document).ready(function () {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'line', //圖表類別,可取值有:line、spline、area、areaspline、bar、column等
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Monthly Average Temperature', //設定一級標題
                x: -20 //center
            },
            subtitle: {
                text: 'Source: WorldClimate.com', //設定二級標題
                x: -20
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
            'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']//設定x軸的標題
            },
            yAxis: {
                title: {
                    text: 'Temperature (°C)' //設定y軸的標題
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
               this.x + ': ' + this.y + '°C';  //滑鼠放在資料點的顯示資訊,但是當設定顯示了每個節點的資料項目的值時就不會再有這個顯示資訊
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right', //設定解說文字的文字 left/right/top/
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },
            exporting: {
                enabled: true, //用來設定是否顯示‘列印’,'匯出'等功能按鈕,不設定時預設為顯示
                url: "http://localhost:49394/highcharts_export.aspx" //匯出圖片的URL,預設匯出是需要連到官方網站去的哦
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true //顯示每條曲線每個節點的資料項目的值
                    },
                    enableMouseTracking: false
                }
            },
            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>
<body>
    <form id="form1" runat="server">
    <!--5.匯入容器用於顯示圖表-->
    <div id="container" style="width: 900px;">
    </div>
    </form>
</body>
</html>

匯出的圖片格式

可以做到頁面展示和匯出的圖片一致了。

 

參考文章:

  • highcharts
  • javascript地區列印代碼
  • Highcharts用Asp.Net匯出jpg,png圖片
  • http://www.highcharts.com/ref/#exporting
  • 強大的jQuery圖表套件-Highcharts
  • http://www.helloweba.com/tag.html?tag=Highcharts
  • http://www.cnblogs.com/jsonzheng/category/298677.html
  • Export server for ASP.NET

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.