Highcharts属性

来源:互联网 发布:量子计算机 知乎 编辑:程序博客网 时间:2024/05/02 06:11
  1. 原文地址:http://zhaoxian705.blog.163.com/blog/static/54190157201171511433536/
  2. Highcharts.setOptions({global:{useUTC : false}});  
  3. $(function(){    
  4.     //声明报表对象    
  5.     var chart = new Highcharts.Chart({    
  6.         chart: {  
  7.         renderTo: 'container'// 报表显示在 页面位置 container 为 div 定义的属性  
  8.         defaultSeriesType: 'spline'// 定义报表类型 例如:line ,spline ,colume  
  9.         events: {  
  10.                 load:  getForm  //调用js 方法  
  11.             }  
  12.         },  
  13.         title:{  
  14.             text:'实时监测曲线图" //定义曲线报表 名称  
  15.         },  
  16.         xAxis: {  
  17.             type: 'datetime'// 定义时间轴的 类型  
  18.             maxPadding : 0.05,  
  19.             minPadding : 0.05,  
  20.             tickWidth:1,//刻度的宽度  
  21.             lineWidth :1,//自定义x轴宽度  
  22.             gridLineWidth :1,//默认是0,即在图上没有纵轴间隔线  
  23.             lineColor : '#990000'     
  24.         },  
  25.         yAxis: {  
  26.                 max:12// 定义Y轴 最大值  
  27.                 min:0// 定义最小值  
  28.                 minPadding: 0.2,   
  29.                 maxPadding: 0.2,  
  30.                 tickInterval:1// 刻度值  
  31.                 title: {  
  32.                     text: 'PH值'  
  33.                 },  
  34.                 // plotLines 表示为定义曲线报表中的 (刻度线)或者叫做(定义的区间范围)  
  35. // 一下为2条表示线  
  36.                 plotLines: [{   
  37.                             value: 6,  
  38.                             color: 'green',  
  39.                             dashStyle: 'shortdash',  
  40.                             width: 2,  
  41.                             label: {  
  42.                                 text: '正常'  
  43.                             }  
  44.                         },{  
  45.                             value: 8,  
  46.                             color: 'green',  
  47.                             dashStyle: 'shortdash',  
  48.                             width: 2,  
  49.                             label: {  
  50.                                 text: '正常'  
  51.                             }  
  52.                         }  
  53.                 }]  
  54.         },  
  55.         tooltip: {  // 表示为 鼠标放在报表图中数据点上显示的数据信息  
  56.             formatter: function() {  
  57.                   return '<b>'+'日期:' +'</b>'  
  58. +Highcharts.dateFormat('%Y-%m-%d %H:%M:%S'this.x) +'<br/>'+  
  59.                    '<b>'+'<%=lbname%>:' +'</b>'this.y+'  <%=shll%>';  
  60.             }  
  61.         },  
  62.         series: [{  
  63.             name: 'PH',  
  64.             data: [] // 此处存放数据值 用,分开 例如:1.8,8.9,null,9.2,   如果在某一点数据为空    
  65. //可以用null 来表示   
  66.             //如果是想动态扶植  这个位置 应该为空 即:data: []  
  67.         }]  
  68.     });    
  69.     // 与后台进行数据交互  
  70.     function getForm(){    
  71.         jQuery.getJSON("test!test.do?id=123456"null, function(data) {     
  72.             //为图表设置值     
  73.             chart.series[0].setData(data);     
  74.         });       
  75.     }    
  76.     //定时刷新 列表数据  
  77.    $(document).ready(function() {    
  78.        //每隔3秒自动调用方法,实现图表的实时更新    
  79.        window.setInterval(getForm,50000);     
  80.    });    
  81. });  
  82.   
  83. //定义 曲线报表图 的样式  
  84.     Highcharts.theme = {  
  85.        colors: ['#058DC7''#50B432''#ED561B''#DDDF00''#24CBE5''#64E572''#FF9655',  
  86.  '#FFF263''#6AF9C4'],  
  87.        chart: {  
  88.           backgroundColor: {  
  89.              linearGradient: [00500500],  
  90.              stops: [  
  91.                 [0'rgb(255, 255, 255)'],  
  92.                 [1'rgb(240, 240, 255)']  
  93.              ]  
  94.           },  
  95.           borderWidth: 2,  
  96.           plotBackgroundColor: 'rgba(255, 255, 255, .9)',  
  97.           plotShadow: true,  
  98.           plotBorderWidth: 1  
  99.        },  
  100.        title: {  
  101.           style: {   
  102.              color: '#000',  
  103.              font: 'bold 16px "Trebuchet MS", Verdana, sans-serif'  
  104.           }  
  105.        },  
  106.        subtitle: {  
  107.           style: {   
  108.              color: '#666666',  
  109.              font: 'bold 12px "Trebuchet MS", Verdana, sans-serif'  
  110.           }  
  111.        },  
  112.        xAxis: {  
  113.           gridLineWidth: 1,  
  114.           lineColor: '#000',  
  115.           tickColor: '#000',  
  116.           labels: {  
  117.              style: {  
  118.                 color: '#000',  
  119.                 font: '11px Trebuchet MS, Verdana, sans-serif'  
  120.              }  
  121.           },  
  122.           title: {  
  123.              style: {  
  124.                 color: '#333',  
  125.                 fontWeight: 'bold',  
  126.                 fontSize: '12px',  
  127.                 fontFamily: 'Trebuchet MS, Verdana, sans-serif'  
  128.   
  129.              }              
  130.           }  
  131.        },  
  132.        yAxis: {  
  133.           //minorTickInterval: 'auto'  // 此处会在Y轴坐标2点之前出现小格  所以就没有使用。  
  134.        },  
  135.        legend: {  
  136.           itemStyle: {           
  137.              font: '9pt Trebuchet MS, Verdana, sans-serif',  
  138.              color: 'black'  
  139.           },  
  140.           itemHoverStyle: {  
  141.              color: '#039'  
  142.           },  
  143.           itemHiddenStyle: {  
  144.              color: 'gray'  
  145.           }  
  146.        },  
  147.        labels: {  
  148.           style: {  
  149.              color: '#99b'  
  150.           }  
  151.        }  
  152.     };  
  153.     var highchartsOptions = Highcharts.setOptions(Highcharts.theme); 
  154. 常用的文档说明:

    1.chart:
    renderTo 图表的页面显示容器
    defaultSeriesType 图表的显示类型(line,spline, scatter, splinearea bar,pie,area,column)
    margin 上下左右空隙
    events 事件
    click function(e) {}
    load function(e) {}

    2.xAxis:yAxis:
    属性:
    gridLineColor 网格颜色
    reversed 是否反向 true ,false
    gridLineWidth 网格粗细
    startOnTick 是否从坐标线开始画图区域
    endOnTick 是否从坐标线结束画图区域
    tickmarkPlacement 坐标值与坐标线标记的对齐方式on,between
    tickPosition 坐标线标记的样式 向内延伸还是向外延伸(insidel,outside)
    tickPixelInterval 决定着横坐标的密度
    tickColor 坐标线标记的颜色
    tickWidth 坐标线标记的宽度
    lineColor 基线颜色
    lineWidth 基线宽度
    max 固定坐标最大值
    min 固定坐标最小值
    plotlines 标线属性
    maxZoom
    minorGridLineColor
    minorGridLineWidth
    /minorTickColor
    title: 
    enabled: 是否显示
    text: 坐标名称
    Labels 坐标轴值显示类 默认:defaultLabelOptions
    formatter 格式化函数
    enabled 是否显示坐标轴的坐标值
    rotation 倾斜角度
    align 与坐标线的水平相对位置
    x 水平偏移量
    y 垂直偏移量
    style 
    font 字体样式 默认defaultFont
    color 颜色
    3.Tooltip 数据点的提示框
    enabled 鼠标经过时是否可动态呈现true,false
    formatter 格式化提示框的内容样式

    4.plotOptions 画各种图表的数据点的设置
    defaultOptions 默认设置
    属性
    Area类:
    lineWidth 线宽度
    fillColor area的填充颜色组
    marker{} 设置动态属性
    shadow 是否阴影 true,false
    states 设置状态?
    Line类
    dataLabels: 数据显示类
    enabled 是否直接显示点的数据true,false
    5.series
    name 该条曲线名称
    data[] 该条曲线的数据项
    addPoint([x,y],redraw,cover) 添加描点,redraw 是否重画,cover是否左移
    setData: function(data, redraw) 重新设置Data数组,redraw是否重画
    remove: function(redraw) 删除曲线
    redraw: function() 重画曲线
    marker :
    enabled 是否显示描点

0 0
原创粉丝点击