1. yuichi1004
  2. jqplot

Commits

cleonello  committed d3e4c8e

Added resetAxisValues method which allows manual updating of axis tick values without redrawing the plot. Only ticks will be updated. Added examples.

  • Participants
  • Parent commits 849bd29
  • Branches default

Comments (0)

Files changed (5)

File examples/ajax-loader.gif

Added
New image

File examples/candlestickCanvasOverlay.html

View file
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+
+<html lang="en">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+  <title></title>
+  <!--[if IE]><script language="javascript" type="text/javascript" src="../src/excanvas.js"></script><![endif]-->
+  
+  <link rel="stylesheet" type="text/css" href="../src/jquery.jqplot.css" />
+  <link rel="stylesheet" type="text/css" href="examples.css" />
+  
+  <!-- BEGIN: load jquery -->
+  <script language="javascript" type="text/javascript" src="../src/jquery-1.4.4.min.js"></script>
+  <!-- END: load jquery -->
+  
+  <!-- BEGIN: load jqplot -->
+  <script language="javascript" type="text/javascript" src="../src/jquery.jqplot.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.dateAxisRenderer.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.categoryAxisRenderer.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.ohlcRenderer.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.canvasOverlay.js"></script>
+  
+  <!-- END: load jqplot -->
+<script language="javascript" type="text/javascript">
+  
+$(document).ready(function(){
+
+	var j = new $.jsDate();
+	
+    
+    var ohlc = [['07/06/09', 138.7, 139.68, 135.18, 135.4],
+    ['06/29/09', 143.46, 144.66, 139.79, 140.02],
+    ['06/22/09', 140.67, 143.56, 132.88, 142.44],
+    ['06/15/09', 136.01, 139.5, 134.53, 139.48],
+    ['06/08/09', 143.82, 144.56, 136.04, 136.97],
+    ['06/01/09', 136.47, 146.4, 136, 144.67],
+    ['05/26/09', 124.76, 135.9, 124.55, 135.81],
+    ['05/18/09', 123.73, 129.31, 121.57, 122.5],
+    ['05/11/09', 127.37, 130.96, 119.38, 122.42],
+    ['05/04/09', 128.24, 133.5, 126.26, 129.19],
+    ['04/27/09', 122.9, 127.95, 122.66, 127.24],
+    ['04/20/09', 121.73, 127.2, 118.6, 123.9],
+    ['04/13/09', 120.01, 124.25, 115.76, 123.42],
+    ['04/06/09', 114.94, 120, 113.28, 119.57],
+    ['03/30/09', 104.51, 116.13, 102.61, 115.99],
+    ['03/23/09', 102.71, 109.98, 101.75, 106.85],
+    ['03/16/09', 96.53, 103.48, 94.18, 101.59],
+    ['03/09/09', 84.18, 97.2, 82.57, 95.93],
+    ['03/02/09', 88.12, 92.77, 82.33, 85.3],
+    ['02/23/09', 91.65, 92.92, 86.51, 89.31],
+    ['02/17/09', 96.87, 97.04, 89, 91.2],
+    ['02/09/09', 100, 103, 95.77, 99.16],
+    ['02/02/09', 89.1, 100, 88.9, 99.72],
+    ['01/26/09', 88.86, 95, 88.3, 90.13],
+    ['01/20/09', 81.93, 90, 78.2, 88.36],
+    ['01/12/09', 90.46, 90.99, 80.05, 82.33],
+    ['01/05/09', 93.17, 97.17, 90.04, 90.58],
+    ['12/29/08', 86.52, 91.04, 84.72, 90.75],
+    ['12/22/08', 90.02, 90.03, 84.55, 85.81],
+    ['12/15/08', 95.99, 96.48, 88.02, 90],
+    ['12/08/08', 97.28, 103.6, 92.53, 98.27],
+    ['12/01/08', 91.3, 96.23, 86.5, 94],
+    ['11/24/08', 85.21, 95.25, 84.84, 92.67],
+    ['11/17/08', 88.48, 91.58, 79.14, 82.58],    
+    ['11/10/08', 100.17, 100.4, 86.02, 90.24],
+    ['11/03/08', 105.93, 111.79, 95.72, 98.24],
+    ['10/27/08', 95.07, 112.19, 91.86, 107.59],
+    ['10/20/08', 99.78, 101.25, 90.11, 96.38],
+    ['10/13/08', 104.55, 116.4, 85.89, 97.4],
+    ['10/06/08', 91.96, 101.5, 85, 96.8],
+    ['09/29/08', 119.62, 119.68, 94.65, 97.07],
+    ['09/22/08', 139.94, 140.25, 123, 128.24],
+    ['09/15/08', 142.03, 147.69, 120.68, 140.91],
+    ['09/08/08', 164.57, 164.89, 146, 148.94]
+    ];
+	
+	var ohlc = [['1/24/2011', 607.57, 612.49, 601.23, 611.08],
+['1/21/2011', 639.58, 641.73, 611.36,   611.83],
+['1/20/2011', 632.21, 634.08, 623.29,   626.77],
+['1/19/2011', 642.12, 642.96, 629.66,   631.75],
+['1/18/2011', 626.06, 641.99, 625.27,   639.63],
+['1/14/2011', 617.4, 624.27, 617.08,   624.18],
+['1/13/2011', 616.97, 619.67, 614.16,   616.69],
+['1/12/2011', 619.35, 619.35, 614.77,   616.87],
+['1/11/2011', 617.71, 618.8, 614.5,  616.01],
+['1/10/2011', 614.8, 615.39, 608.56,   614.21],
+['1/7/2011', 615.91, 618.25, 610.13,   616.44],
+['1/6/2011', 610.68, 618.43, 610.05,  613.5],
+['1/5/2011', 600.07, 610.33, 600.05,   609.07],
+['1/4/2011', 605.62, 606.18, 600.12,   602.12],
+['1/3/2011', 596.48, 605.59, 596.48,   604.35],
+['12/31/2010', 596.74, 598.42, 592.03,   593.97],
+['12/30/2010', 598, 601.33, 597.39,   598.86],
+['12/29/2010', 602, 602.41, 598.92,   601],
+['12/28/2010', 602.05, 603.87, 598.01,   598.92],
+['12/27/2010', 602.74, 603.78, 599.5,   602.38],
+['12/23/2010', 605.34, 606, 602.03,   604.23],
+['12/22/2010', 604, 607, 603.28,   605.49],
+['12/21/2010', 598.57, 604.72, 597.61,   603.07],
+['12/20/2010', 594.65, 597.88, 588.66,   595.06],
+['12/17/2010', 591, 592.56, 587.67,  590.8],
+['12/16/2010', 592.85, 593.77, 588.07,   591.71],
+['12/15/2010', 594.2, 596.45, 589.15,  590.3],
+['12/14/2010', 597.09, 598.29, 592.48,   594.91],
+['12/13/2010', 597.12, 603, 594.09,   594.62],
+['12/10/2010', 593.14, 593.99, 590.29,  592.21],
+['12/9/2010', 593.88, 595.58, 589,   591.5],
+['12/8/2010', 591.97, 592.52, 583.69,   590.54],
+['12/7/2010', 591.27, 593, 586,   587.14],
+['12/6/2010', 580.57, 582, 576.61,   578.36],
+['12/3/2010', 569.45, 576.48, 568,   573],
+['12/2/2010', 568.66, 573.33, 565.35,   571.82],
+['12/1/2010', 563, 571.57, 562.4,  564.35],
+['11/30/2010', 574.32, 574.32, 553.31,   555.71],
+['11/29/2010', 589.17, 589.8, 579.95,  582.11],
+['11/26/2010', 590.46, 592.98, 587,   590],
+['11/24/2010', 587.31, 596.6, 587.05,   594.97],
+['11/23/2010', 587.01, 589.01, 578.2,   583.01],
+['11/22/2010', 587.47, 593.44, 582.75,   591.22],
+['11/19/2010', 597, 597.89, 590.34,   590.83],
+['11/18/2010', 589, 599.98, 588.56,   596.56],
+['11/17/2010', 585, 589.5, 581.37,  583.55],
+['11/16/2010', 592.76, 597.89, 583.45,   583.72],
+['11/15/2010', 603.08, 604, 594.05,  595.47],
+['11/12/2010', 613.99, 616.9, 601.21,   603.29],
+['11/11/2010', 619.7, 619.85, 614.21,   617.19],
+['11/10/2010', 622.08, 623, 617.51, 622.88],
+['11/9/2010', 630, 630.85, 620.51,   624.82],
+['11/8/2010', 624.02, 629.49, 623.13,   626.77],
+['11/5/2010', 623.18, 625.49, 621.11,   625.08],
+['11/4/2010', 624.64, 629.92, 622.1,   624.27],
+['11/3/2010', 617.5, 621.83, 613.5,   620.18],
+['11/2/2010', 618.67, 620, 614.58,  615.6],
+['11/1/2010', 615.73, 620.66, 611.21,   615],
+['10/29/2010', 617.07, 619, 612.99,   613.7],
+['10/28/2010', 620.05, 621, 613.3,  618.58]];
+	
+	for (var i=0; i<ohlc.length; i++) {
+		//ohlc[i][0] = j.strftime('%Y-%m-%d');
+		j.add(-1, 'day');
+	}
+       
+    
+    plot1 = $.jqplot('chart1',[ohlc],{
+      title: 'Chart',
+      axesDefaults:{},
+      axes: {
+          xaxis: {
+              renderer:$.jqplot.DateAxisRenderer,
+              tickOptions:{formatString:'%b %e'}, 
+          },
+          yaxis: {
+		      min: 590,
+			  max: 650,
+              tickOptions:{formatString:'%.2f'}
+          }
+      },
+      series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}]
+    });
+    
+});
+
+function startit() {
+	counter = 0;
+	Interval = setInterval(runUpdate, 250);
+}
+
+function runUpdate() {
+	if (counter < 1000) {
+		var val = Math.random()*5 * (Math.random() - 0.5),
+			d = plot1.series[0].data,
+			dl = d.length,
+			curhi = d[dl - 1][2],
+			curlo = d[dl - 1][3],
+			curclose = d[dl - 1][4];
+			newval = curclose + val;
+			
+			
+		if (newval > curhi) { curhi = newval }
+		else if (newval < curlo) { curlo = newval }
+		
+		d[dl - 1][2] = curhi;
+		d[dl - 1][3] = curlo;
+		d[dl - 1][4] = newval;
+		
+		if (curhi > plot1.axes.yaxis.max) {
+		
+		}
+		else if (curlo < plot1.axes.yaxis.min) {
+		
+		}
+		
+		else {
+			plot1.drawSeries({}, 0);
+			counter++;
+		}
+		
+		val = d = dl = curhi = curlo = curclose = newval = null;
+	}
+	else {
+		val = d = dl = curhi = curlo = curclose = newval = null;
+		clearInterval(Interval);
+	}
+}
+
+function stopit() {
+	clearInterval(Interval);
+}
+	
+
+
+</script>
+
+  </head>
+  <body>
+<?php include "nav.inc"; ?>
+<div id="chart1" style="margin:20px;height:400px; width:800px;"></div>
+<button onclick="startit()">Start</button>
+<button onclick="stopit()">Stop</button>
+  </body>
+</html>

File examples/resetAxisTicks.html

View file
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+
+<html lang="en">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+  <title>Single Negative Point</title>
+  <!--[if IE]><script language="javascript" type="text/javascript" src="../src/excanvas.js"></script><![endif]-->
+  
+  <link rel="stylesheet" type="text/css" href="../src/jquery.jqplot.css" />
+  
+  <!-- BEGIN: load jquery -->
+  <script language="javascript" type="text/javascript" src="../src/jquery-1.4.4.min.js"></script>
+  <!-- END: load jquery -->
+  
+  <!-- BEGIN: load jqplot -->
+  <script language="javascript" type="text/javascript" src="../src/jquery.jqplot.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.dateAxisRenderer.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.ohlcRenderer.js"></script>
+
+  <!-- END: load jqplot -->
+<script language="javascript" type="text/javascript">
+  
+$(document).ready(function(){
+      $.jqplot.config.enablePlugins = true;
+	  //$.jqplot.config.catchErrors = true;
+    
+    line1 = [1, 3, 5, 7, 9];
+    plot1 = $.jqplot('chart1',[line1], {});
+	ohlc = [['1/24/2011 8:00am', 607.57, 612.49, 601.23, 611.08],
+['1/24/2011 9:00am', 639.58, 641.73, 611.36,   611.83],
+['1/24/2011 10:00am', 632.21, 634.08, 623.29,   626.77],
+['1/24/2011 11:00am', 642.12, 642.96, 629.66,   631.75],
+['1/24/2011 12:00pm', 626.06, 641.99, 625.27,   639.63],
+['1/24/2011 1:00pm', 617.4, 624.27, 617.08,   624.18],
+['1/24/2011 2:00pm', 616.97, 619.67, 614.16,   616.69],
+['1/24/2011 3:00pm', 619.35, 619.35, 614.77,   616.87],
+['1/24/2011 4:00pm', 617.71, 618.8, 614.5,  616.01],
+['1/24/2011 5:00pm', 614.8, 615.39, 608.56,   614.21]];
+	ohlc = [['8:00am', 607.57, 612.49, 601.23, 611.08],
+['9:00am', 639.58, 641.73, 611.36,   611.83],
+['10:00am', 632.21, 634.08, 623.29,   626.77],
+['11:00am', 642.12, 642.96, 629.66,   631.75],
+['12:00pm', 626.06, 641.99, 625.27,   639.63],
+['1:00pm', 617.4, 624.27, 617.08,   624.18],
+['2:00pm', 616.97, 619.67, 614.16,   616.69],
+['3:00pm', 619.35, 619.35, 614.77,   616.87],
+['4:00pm', 617.71, 618.8, 614.5,  616.01],
+['5:00pm', 614.8, 615.39, 608.56,   614.21]];
+
+    plot2 = $.jqplot('chart2',[ohlc],{
+      axes: {
+          xaxis: {
+			  numberTicks: 7,
+			  min: '7:00am',
+			  max: '7:00pm',
+              renderer:$.jqplot.DateAxisRenderer,
+              tickOptions:{formatString:'%#I:%M%p'}, 
+          },
+          yaxis: {
+		      min: 590,
+			  max: 650,
+              tickOptions:{formatString:'%.2f'}
+          }
+      },
+      series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}]
+    });
+    
+});
+
+function resetXTicks(plot, arr) {
+	// first reset the tick values, labels, scaling function.
+	plot.axes.xaxis.renderer.resetTickValues.call(plot.axes.xaxis, arr);
+	// now redraw the (all of the) series.
+	// could just redraw specific series if had mutliple series attached to multiple axes.
+	plot.drawSeries();
+};
+
+function resetYTicks(plot, arr) {
+	// first reset the tick values, labels, scaling function.
+	plot.axes.yaxis.renderer.resetTickValues.call(plot.axes.yaxis, arr);
+	// now redraw the (all of the) series.
+	// could just redraw specific series if had mutliple series attached to multiple axes.
+	plot.drawSeries();
+};
+
+function resetXYTicks(plot, xarr, yarr) {
+	// first reset the tick values, labels, scaling function.
+	plot.axes.xaxis.renderer.resetTickValues.call(plot.axes.xaxis, xarr);
+	plot.axes.yaxis.renderer.resetTickValues.call(plot.axes.yaxis, yarr);
+	// now redraw the (all of the) series.
+	// could just redraw specific series if had mutliple series attached to multiple axes.
+	plot.drawSeries();
+};
+
+
+</script>
+
+  </head>
+  <body>
+<?php include "nav.inc"; ?>
+<div id="chart1" style="height:200px; width:400px;"></div>
+<div id="chart2" style="height:200px; width:400px;"></div>
+  </body>
+</html>

File src/jqplot.core.js

View file
 						temp.width(ew);
 						temp.css('top', this.eventCanvas._offsets.top);
 						temp.css('left', this.eventCanvas._offsets.left);
-						//temp.css('lineHeight', eh+'px');
 						
 						temp2 = $('<div class="jqplot-noData-contents" style="text-align:center; position:relative; margin-left:auto; margin-right:auto;"></div>');
 						temp.append(temp2);

File src/jqplot.linearAxisRenderer.js

View file
             }
         }
     };
+	
+	// Used to reset just the values of the ticks and then repack, which will
+	// recalculate the positioning functions.  It is assuemd that the 
+	// number of ticks is the same and the values of the new array are at the
+	// proper interval.
+	// This method needs to be called with the scope of an axis object, like:
+	//
+	// > plot.axes.yaxis.renderer.resetTickValues.call(plot.axes.yaxis, yarr);
+	//
+	$.jqplot.LinearAxisRenderer.prototype.resetTickValues = function(opts) {
+		if ($.isArray(opts) && opts.length == this._ticks.length) {
+			var t
+			for (var i=0; i<opts.length; i++) {
+				t = this._ticks[i];
+				t.value = opts[i];
+				t.label = t.formatter(t.formatString, opts[i]);
+				// add prefix if needed
+				if (t.prefix && !t.formatString) {
+					t.label = t.prefix + t.label;
+				}
+				t._elem.html(t.label);
+			}
+			this.min = $.jqplot.arrayMin(opts);
+			this.max = $.jqplot.arrayMax(opts);
+			this.pack();
+		}
+		else if ($.isPlainObject(opts)) {
+		
+		}
+	};
     
     // called with scope of axis
     $.jqplot.LinearAxisRenderer.prototype.pack = function(pos, offsets) {
+		// Add defaults for repacking from resetTickValues function.
+		pos = pos || {};
+		offsets = offsets || this._offsets;
+		
         var ticks = this._ticks;
         var max = this.max;
         var min = this.min;