jqplot總結


JqPlot需要三個參數,1.位置,2.數據,3.配置。

重點是3.配置。

配置大概分為title(標題)axes(xy)series(數據的連續圖)dataRenderer外部數據加載方式,highlighter鼠標靠近,數據顯示方式,cursor鼠標樣式變化,以及顯示當前數值。

 

axes軸里面有軸名字label;軸名字的渲染引擎labelRenderer,以及軸名字相關樣式(大小fontSize,字體種類fontFamily,顏色等等);軸刻度值tickOptions(字體大小fontSize,旋轉角度angle,字體種類fontFamily);軸的渲染引擎renderer;軸刻度值的渲染引擎tickRenderer;離數據連續圖的距離pad;自動分配刻度值autoscale;刻度值和標簽值的相對位置labelPosition

 

series數據連續圖有,渲染引擎renderer(線條,柱形,圓餅等等);是否展示數值點(showMarker)

 

dataRenderer外部數據加載方式。

 

highlighter鼠標靠近,數據顯示方式。

 

cursor鼠標樣式變化,以及顯示當前數值。

 

特別說明legend

--------------------------------------------------------------------------------

官網API翻譯(很未完,因為沒時間

 

Axis
    autoscale:默認是false。當你沒設置min或max,也就是XY軸的最小或最大刻度值時,autoscale關閉。numberTicks, tickInterval 和pad這些屬性與autoscale相關。padMin和padMax這兩個屬性與autoscale無關。

 

--------------------------------------------------------------------------------

官網的exapmle(很未完,因為沒時間)

 

 

 

 

<! DOCTYPE html >
< html >
< head >
< meta  charset ="utf-8"   />
< title >line-charts </ title >
< link  rel ="stylesheet"  type ="text/css"  href ="jquery.jqplot.css"   />
<!-- [if lt IE 9]><script type="javascript" type="text/javascript" src="excanvas.js"></script><![endif] -->
< script  type ="text/javascript"  src ="jquery.js" ></ script >
< script  type ="text/javascript"  src ="jquery.jqplot.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasTextRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasAxisLabelRenderer.min.js" ></ script >
< script  type ="text/javascript" >
$(
function (){
    
var  plot1  =  $.jqplot ( ' chart1 ' , [[ 3 , 7 , 9 , 1 , 4 , 6 , 8 , 2 , 5 ]]);

    
var  plot2  =  $.jqplot ( ' chart2 ' , [[ 3 , 7 , 9 , 1 , 4 , 6 , 8 , 2 , 5 ]], {
      
//  Give the plot a title.標題
      title:  ' Plot With Options ' ,
      
//  You can specify options for all axes on the plot at once with
       //  the axesDefaults object.  Here, we're using a canvas renderer
       //  to draw the axis label which allows rotated text.
       //  axesDefaults指定的參數配置,適用於所有軸。這里是指x,y軸的label用canvas畫出
      axesDefaults: {
        labelRenderer: $.jqplot.CanvasAxisLabelRenderer
      },
      
//  An axes object holds options for all axes.
       //  Allowable axes are xaxis, x2axis, yaxis, y2axis, y3axis, ...
       //  Up to 9 y axes are supported.
      axes: {
        
//  options for each axis are specified in seperate option objects.
        xaxis: {
          label: 
" X Axis " ,
          
//  Turn off "padding".  This will allow data point to lie on the
           //  edges of the grid.  Default padding is 1.2 and will keep all
           //  points inside the bounds of the grid.
           //  pad是指,起始點是不是靠近軸。默認是1.2,這里0表示就在軸上
          pad:  0
        },
        yaxis: {
          label: 
" Y Axis "
        }
      }
    });


    
//  Some simple loops to build up data arrays.
     //  這些循環用來構造數據
   var  cosPoints  =  [];
  
for  ( var  i = 0 ; i < 2 * Math.PI; i += 0.4 ){ 
    cosPoints.push([i, Math.cos(i)]); 
  }
    
  
var  sinPoints  =  []; 
  
for  ( var  i = 0 ; i < 2 * Math.PI; i += 0.4 ){ 
     sinPoints.push([i, 
2 * Math.sin(i - . 8 )]); 
  }
    
  
var  powPoints1  =  []; 
  
for  ( var  i = 0 ; i < 2 * Math.PI; i += 0.4 ) { 
      powPoints1.push([i, 
2.5   +  Math.pow(i / 4, 2)]); 
  }
    
  
var  powPoints2  =  []; 
  
for  ( var  i = 0 ; i < 2 * Math.PI; i += 0.4 ) { 
      powPoints2.push([i, 
- 2.5   -  Math.pow(i / 4, 2)]); 
  } 
 
  
var  plot3  =  $.jqplot( ' chart3 ' , [cosPoints, sinPoints, powPoints1, powPoints2], 
    { 
      title:
' Line Style Options '
      
//  Series options are specified as an array of objects, one object
       //  for each series.
       //  series參數是一個對象數組,一個對象對應一組數據
      series:[ 
          {
            
//  Change our line width and use a diamond shaped marker.
            lineWidth: 2
            markerOptions: { style:
' dimaond '  }
          }, 
          {
            
//  Don't show a line, just show markers.
             //  Make the markers 7 pixels with an 'x' style
             //  去掉兩點之間的連線;設置字母x的大小為7px
            showLine: false
            markerOptions: { size: 
7 , style: " x "  }
          },
          { 
            
//  Use (open) circlular markers.
            markerOptions: { style: " circle "  }
          }, 
          {
            
//  Use a thicker, 5 pixel line and 10 pixel
             //  filled square markers.
             //  設置線條的粗細,以及標記的樣式
            lineWidth: 5
            markerOptions: { style:
" filledSquare " , size: 10  }
          }
      ]
    }
  );


});
</ script >

</ head >
< body >
     < div  id ="chart1" ></ div >
     < div  id ="chart2" ></ div >
     < div  id ="chart3" ></ div >
</ body >
</ html >

 

 

 

<! DOCTYPE html >
< html >
< head >
< meta  charset ="utf-8"   />
< title >axis Label Test </ title >
< link  rel ="stylesheet"  type ="text/css"  href ="jquery.jqplot.css"   />
<!-- [if lt IE 9]><script type="javascript" type="text/javascript" src="excanvas.js"></script><![endif] -->
< script  type ="text/javascript"  src ="jquery.js" ></ script >
< script  type ="text/javascript"  src ="jquery.jqplot.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasTextRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasAxisLabelRenderer.min.js" ></ script >
< script  type ="text/javascript" >
$(
function (){
//  生成測試數據
var  cosPoints  =  [];
for ( var  i  =   0 ; i  <   2   *  Math.PI; i  +=   0.1 ) {
  cosPoints.push([i, Math.cos(i)]);
}

var  plot1  =  $.jqplot( ' chart1 ' , [cosPoints], {
    series: [{
      
//  去掉點的標記
        showMarker:  false
    }],
    axes: {
        xaxis: {
          
//  軸的名字
            label:  ' Angle (radians) '
        },
        yaxis: {
            label: 
' Cosine '
        }
    }
});


var  plot2  =  $.jqplot( ' chart2 ' , [cosPoints], {
  series: [{
    showMarker: 
false
  }],
  axes: {
    xaxis: {
      label: 
' Angle (radians) ' ,
      
//  軸的名字渲染引擎
      labelRenderer: $.jqplot.CanvasAxisLabelRenderer
    },
    yaxis: {
      label: 
' Cosine ' ,
      
//  加入labelRenderer參數后,y軸label開始翻轉90°
      labelRenderer: $.jqplot.CanvasAxisLabelRenderer
    }
  }
});


var  plot3  =  $.jqplot( ' chart3 ' , [cosPoints], {
  series: [{
    showMarker: 
false
  }],
  axes: {
    xaxis: {
      label: 
' Angle (radians) ' ,
      labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
      
//  設置軸的名字的,字體和大小
      labelOptions: {
        fontFamily: 
' Georgia, Serif ' ,
        fontSize: 
' 12pt '
      }
    },
    yaxis: {
      label: 
' Cosine ' ,
      labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
      labelOptions: {
        fontFamily: 
' Georgia, Serif ' ,
        fontSize: 
' 12pt '
      }
    }
  }
});


});
</ script >

</ head >
< body >
     < div  id ="chart1" ></ div >
     < div  id ="chart2" ></ div >
     < div  id ="chart3" ></ div >
</ body >
</ html >
<! DOCTYPE html >
< html >
< head >
< meta  charset ="utf-8"   />
< title >rotated-tick-labels </ title >
< link  rel ="stylesheet"  type ="text/css"  href ="jquery.jqplot.css"   />
<!-- [if lt IE 9]><script type="javascript" type="text/javascript" src="excanvas.js"></script><![endif] -->
< script  type ="text/javascript"  src ="jquery.js" ></ script >
< script  type ="text/javascript"  src ="jquery.jqplot.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.dateAxisRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasTextRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.canvasAxisTickRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.categoryAxisRenderer.min.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.barRenderer.min.js" ></ script >
< script  type ="text/javascript" >
$(
function (){
var  line1  =  [
  [
' Cup Holder Pinion Bob ' 7 ],
  [
' Generic Fog Lamp ' 9 ],
  [
' HDTV Receiver ' 15 ],
  [
' 8 Track Control Module ' 12 ],
  [
'  Sludge Pump Fourier Modulator ' 3 ],
  [
' Transcender/Spice Rack ' 6 ],
  [
' Hair Spray Danger Indicator ' 18 ]
];

var  plot1  =  $.jqplot( ' chart1 ' , [line1], {
  title: 
' Concern vs. Occurrance ' ,
  series: [{
    
//  數據的連續圖的渲染引擎,用柱形圖表示數據
    renderer: $.jqplot.BarRenderer
  }],
  axesDefaults: {
    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
    
//  軸的標簽
    tickOptions: {
      angle: 
- 30 ,
      fontSize: 
' 10pt '
    }
  },
  axes: {
    xaxis: {
      
//  x軸用數據里面的數組第一個元素
      renderer: $.jqplot.CategoryAxisRenderer
    }
  }
});


var  plot1b  =  $.jqplot( ' chart1b ' , [line1], {
  title: 
' Concern vs. Occurrance ' ,
  series: [{
    renderer: $.jqplot.BarRenderer
  }],
  axesDefaults: {
    
//  軸的刻度值,渲染引擎
    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
    
//  軸的刻度值,字體大小,字體類型,字體角度
    tickOptions: {
      fontFamily: 
' Georgia ' ,
      fontSize: 
' 10pt ' ,
      angle: 
- 30
    }
  },
  axes: {
    xaxis: {
      
//  軸的渲染引擎
      renderer: $.jqplot.CategoryAxisRenderer
    }
  }
});

//  var line2 = [
//
   ['Nickle', 28],
//
   ['Aluminum', 13],
//
   ['Xenon', 54],
//
   ['Silver', 47],
//
   ['Sulfer', 16],
//
   ['Silicon', 14],
//
   ['Vanadium', 23]
//
 ];
var  line2  =  [
  [
' Cup Holder Pinion Bob ' 7 ],
  [
' Generic Fog Lamp ' 9 ],
  [
' HDTV Receiver ' 15 ],
  [
' 8 Track Control Module ' 12 ],
  [
'  Sludge Pump Fourier Modulator ' 3 ],
  [
' Transcender/Spice Rack ' 6 ],
  [
' Hair Spray Danger Indicator ' 18 ]
];


var  plot2  =  $.jqplot( ' chart2 ' , [line1, line2], {
series: [{
  renderer: $.jqplot.BarRenderer
}, 
//  在series里第二個對象表示,第二個數據連續的圖的配置。在這里是它的縱坐標叫y2axis,橫坐標叫x2axis
{
  xaxis: 
' x2axis ' ,
  yaxis: 
' y2axis '
}],
axesDefaults: {
  tickRenderer: $.jqplot.CanvasAxisTickRenderer,
  tickOptions: {
    
//  angle: 30
  }
},
axes: {
  xaxis: {
    renderer: $.jqplot.CategoryAxisRenderer
  },
  x2axis: {
    renderer: $.jqplot.CategoryAxisRenderer
  },
  yaxis: {
    
//  自動刻度值
    autoscale:  true
  },
  y2axis: {
    autoscale: 
true
  }
}
});

var  plot3  =  $.jqplot( ' chart3 ' , [line1], {
  title: 
' Concern vs. Occurrance ' ,
  series: [{
    renderer: $.jqplot.BarRenderer
  }],
  axesDefaults: {
    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
    tickOptions: {
      angle: 
- 30
    }
  },
  axes: {
    xaxis: {
      renderer: $.jqplot.CategoryAxisRenderer,
      tickOptions: {
        labelPosition: 
' middle '
      }
    },
    yaxis: {
      autoscale: 
true ,
      tickRenderer: $.jqplot.CanvasAxisTickRenderer,
      tickOptions: {
        labelPosition: 
' start '
      }
    }
  }
});

});
</ script >

</ head >
< body >
     < div  id ="chart1" ></ div >
     < div  id ="chart1b" ></ div >< hr  />
     < div  id ="chart2" ></ div >< hr  />
     < div  id ="chart3" ></ div >
</ body >
</ html >
<! DOCTYPE html >
< html >
< head >
< meta  charset ="utf-8"   />
< title >rotated-tick-labels </ title >
< link  rel ="stylesheet"  type ="text/css"  href ="jquery.jqplot.css"   />
<!-- [if lt IE 9]><script type="javascript" type="text/javascript" src="excanvas.js"></script><![endif] -->
< script  type ="text/javascript"  src ="jquery.js" ></ script >
< script  type ="text/javascript"  src ="jquery.jqplot.js" ></ script >
< script  type ="text/javascript"  src ="plugins/jqplot.json2.min.js" ></ script >
< script  type ="text/javascript" >
$(
function () {
    
//  Our data renderer function, returns an array of the form:
     //  [[[x1, sin(x1)], [x2, sin(x2)], ...]]
     //  構造測試數據
     var  sineRenderer  =   function () {
        
var  data  =  [[]];
        
for  ( var  i = 0 ; i < 13 ; i += 0.5 ) {
            data[
0 ].push([i, Math.sin(i)]);
        }
        
return  data;
    };
    console.log(sineRenderer());
 
    
//  we have an empty data array here, but use the "dataRenderer"
     //  option to tell the plot to get data from our renderer.
     //  這里我們第二個參數是空數組,但在第三個參數對象里面用了dataRenderer
     var  plot1  =  $.jqplot( ' chart1 ' ,[],{
        title: 
' Sine Data Renderer ' ,
        dataRenderer: sineRenderer
    });



    
//  Our ajax data renderer which here retrieves a text file.
     //  it could contact any source and pull data, however.
     //  The options argument isn't used in this renderer.
     var  ajaxDataRenderer  =   function (url, plot, options) {
        
var  ret  =   null ;
        $.ajax({
            
//  have to use synchronous here, else the function 
             //  will return before the data is fetched
            async:  false ,
            url: url,
            dataType: 
" json " ,
            success: 
function (data) {
                ret 
=  data;
            },
            error:
function (){
                ret 
=  [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ];
            }
        });
        
return  ret;
    };

    
//  The url for our json data
     var  jsonurl  =   " jsondata.txt " ;
    
debugger ;
    
//  passing in the url string as the jqPlot data argument is a handy
     //  shortcut for our renderer.  You could also have used the
     //  "dataRendererOptions" option to pass in the url.
     var  plot2  =  $.jqplot( ' chart2 ' , jsonurl, {
        title: 
" AJAX JSON Data Renderer " ,
        dataRenderer: ajaxDataRenderer,
        dataRendererOptions: {
            unusedOptionalUrl: jsonurl
        }
    });
});
</ script >
</ head >
< body >
     < div  id ="chart1" ></ div >
     < div  id ="chart2" ></ div >
</ body >
</ html >
 

 

--------------------------------------------------------------------------------

網上找的相關資料鏈接:

 

 

http://www.jqplot.com/
http://www.cnblogs.com/mofish/archive/2011/08/15/2139728.html
 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM