Archive for the 'Javascript' Category

Dynamic Forms for SharePoint: Now with field tooltip

Change log
May 16. 2013
Changes in v2.971

  • Fixed required field check for multichoice columns.

This update requires you to update the *.js.

May 13. 2013
Changes in v2.97

  • Fixed missing trigger for Currency field.
  • Added option to initially hide a list of fields. This option is found under the Misc tab.

This update requires you to update the *.js.

May 13. 2013
Changes in v2.961

  • Fixed a bug in bringing fields visible when NOT using Tabs.
  • Cosmetics: Hidden the “Edit button” behind an image. Update the CSS file to have it initially hidden.

This update requires you to update both the *.js file and the *.css file.

May 10. 2013
Changes in v2.96

  • Disabled the solution when the page is in edit mode to prevent errors.
  • Fixed a glitch in “reversing” rules when using multichoice checkboxes.
  • Attempted to fix a chrome issue with disappearing scrollbars.
  • Added an option to include an overlay with “Loading, please wait…” to prevent flashing the unformatted form when loading – see details below.

In this release only the *.js file has changed, but if you want to use the overlay, follow the instructions below.

Overlay
IMG

If you have some errors in your setup, or you do not have the latest version of the DFFS solution (2.96+), you will see this message after 5 seconds:
IMG

To use the overlay, place a HTML Form Web part ABOVE the form, and insert this code:

<style type="text/css">
.dffsOverlay{
	font-size:16px;
	padding-top:100px;
	text-align:center;	
	width:100%;
	height:100%;
	background-color:#F5F5F5;
	position:absolute;
	top:0;
	left:0;
	z-index:9999;
	cursor:default;
}
</style>
<div id='dffs_loadingOverlay' class='dffsOverlay'>Loading, please wait...</div>
<script type="text/javascript">
	setTimeout(function(){
		var oDiv = document.getElementById("dffs_loadingOverlay");
		if(oDiv !== null){
			oDiv.innerHTML = "<span style='font-size:20px'>This took forever!<span style='font-size:12px'><br><br>Ensure Dynamic Forms for SharePoint v2.96+ is referred correctly.<br><br>Click to close this overlay.</span></span>";
			oDiv.onclick = function(){
	   			this.parentNode.removeChild(this);
			};
		}
	},5000);
</script>
The article

I have updated the Dynamic Forms for SharePoint solution and incorporated the Form Field Tooltip for SharePoint 2007 and SharePoint 2010 solution.

The DFFS solution still supports SharePoint 2007, 2010 and 2013.

New in this release
Added tooltip:
Config
IMG
Form
IMG

Keep focus on tab through DispForm to EditForm
I have rigged it so that you will keep focus on the same tab when you edit a list item from DispForm.

How to update
You must update both the *.js and the *.css file. Get the latest version of the files from here

If this is the first time you implement this solution, please start with the first article linked above for setup instructions.

Update spjs-utility.js
You should update spjs-utility.js to v1.15 as I have fixed a bug in “getFieldValue” when using “Allow ‘Fill-in’ choices”.

Please comment below if you find a bug – or you like this solution.

Alexander

SharePoint form: present fields side-by-side: Updated version

I have previously posted a solution for presenting form fields side-by-side.

This is an updated version derived from the DFFS project.

I have made this updated version by request from Steve Eberl because the older version proved incompatible with IE10. Hopefully this new version will be more compatible, but honestly: I have not tested it in IE10, as I have not installed it yet!

I have done some quick tests in SharePoint 2007 and SharePoint 2010. I guess it will work for SharePoint 2013 also, but this has not been confirmed. Please let me know if someone has tested it.

<script type="text/javascript" src="/test/English/Javascript/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="/test/English/Lists/SideBySide/spjs-utility.js"></script>
<script type="text/javascript">

spjs_sideBySide = {
	"data":{"css":false},
	"apply":function(fObj,arr){
		var h, b;
		if(!spjs_sideBySide.data.css){
			var cssArr = [];
			cssArr.push("<style type='text/css'>");
			cssArr.push(".sbs_FieldTable td.ms-formbody{border-top:none;width:auto;}");
			cssArr.push(".sbs_FieldTable td.ms-formlabel{border-top-color:#d8d8d8;width:auto;}");
			cssArr.push(".sbs_FieldTable input.ms-long{width:auto;}");
			cssArr.push("</style>");
			$("body").append(cssArr.join(""));
			spjs_sideBySide.data.css = true;
		}
		$.each(arr,function(i,o){
			if($("#sbs_OuterTR_"+o.index).length===0){
				$(fObj[o.fin]).before("<tr class='sbs_OuterTR' id='sbs_OuterTR_"+o.index+"'><td valign='top' colspan='2'><table class='sbs_OuterTable' style='width:100%' cellpadding='0' cellspacing='0'><tr class='sbs_InnerTR' id='sbs_InnerTR_"+o.index+"'></tr></table></td></tr>");
			}
			h = $(fObj[o.fin]).css("display") === "none";
			b = [];
			b.push("<td FieldDispName='"+$(fObj[o.fin]).attr('FieldDispName')+"' FieldType='"+$(fObj[o.fin]).attr('FieldType')+"' class='sbs_Field' fin='"+o.fin+"' id='sbs_Field_"+o.fin+"' valign='top' style='white-space:nowrap;");			
			if(h){
				b.push("display:none;");				
			}
			b.push("'>");
			b.push("<table class='sbs_FieldTable' style='width:100%' id='sbs_FieldTable_"+o.fin+"' cellpadding='0' cellspacing='0'></table>");
			b.push("</td>");
			$("#sbs_InnerTR_"+o.index).append(b.join(""));
			if(o.labelHidden){
				$(fObj[o.fin]).find("td.ms-formlabel").hide();
				if(o.padHiddenLabel){
					$("#sbs_FieldTable_"+o.fin).append("<tr class='sbs_FieldLabel' id='sbs_FieldLabel_"+o.fin+"'><td class='ms-formlabel'> </td></tr>");
				}
			}else{
				$("#sbs_FieldTable_"+o.fin).append("<tr class='sbs_FieldLabel' id='sbs_FieldLabel_"+o.fin+"'></tr>");
				$(fObj[o.fin]).find("td.ms-formlabel").appendTo($("#sbs_FieldLabel_"+o.fin));
			}
			$(fObj[o.fin]).appendTo($("#sbs_FieldTable_"+o.fin));
			fObj[o.fin] = $("#sbs_Field_"+o.fin)[0];
			if(h){
				$(fObj[o.fin]).find("td.ms-formbody").parent().show();
			}				
		});
	},
	"resize":function(){
		if(GetUrlKeyValue('IsDlg')!=='1'){
			return;
		}
		if(_spPageContextInfo.webUIVersion === 15){
			ExecuteOrDelayUntilScriptLoaded(function(){
				SP.UI.ModalDialog.get_childDialog().autoSize();
			}, "sp.js");
		}else{
			// http://blog.collabware.com/2012/10/30/tips-tricks-sharepoint-2010-modal-dialogs/
			var dlg = SP.UI.ModalDialog.get_childDialog();
			if(dlg != null) {				
				if(!dlg.$S_0 && dlg.get_$Z_0()){
					dlg.autoSize();
					var xPos, yPos, win = SP.UI.Dialog.get_$1(), xScroll = SP.UI.Dialog.$24(win), yScroll = SP.UI.Dialog.$26(win);
					xPos = ((SP.UI.Dialog.$1d(win) - dlg.$2_0.offsetWidth) / 2) + xScroll; 
					if (xPos < xScroll + 10) {
						xPos = xScroll + 10;
					}
					yPos = ((SP.UI.Dialog.$1c(win) - dlg.$2_0.offsetHeight) / 2) + yScroll;
					if (yPos < yScroll + 10) {
						yPos = yScroll + 10;
					}
					dlg.$T_0 = xPos;
					dlg.$U_0 = yPos;
					dlg.$m_0(dlg.$T_0, dlg.$U_0);
					dlg.$H_0.style.width = Math.max(dlg.$6_0.offsetWidth - 64, 0) + 'px';
					dlg.$2B_0();
				}
			}
		}
	}
}

var fields = init_fields_v2();
/*
	index: Use the same index for all fields in the same row.
	fin: FieldInternalName of the field.
	labelHidden: Hide form label.
	padHiddenLabel: If labelHidden = true, set this to true to fill the empty space left from the hidden formlabel.
*/

var arr = [
	{"index":"1","fin":"FirstName","labelHidden":false,"padHiddenLabel":true},
	{"index":"1","fin":"MiddleName","labelHidden":false,"padHiddenLabel":true},
	{"index":"1","fin":"LastName","labelHidden":false,"padHiddenLabel":true},
	{"index":"2","fin":"DropDownChoice","labelHidden":false,"padHiddenLabel":true},
	{"index":"2","fin":"RadioButtonsChoice","labelHidden":false,"padHiddenLabel":true},
	{"index":"2","fin":"CheckboxesChoice","labelHidden":false,"padHiddenLabel":true}
];

spjs_sideBySide.apply(fields,arr)
// For SP 2010
spjs_sideBySide.resize();
</script>

Please let me know whether it is functioning as expected.

Alexander

Dynamic Forms for SharePoint: Now with side-by-side

Change log
May 06. 2013
I have released v2.95 – you find it here
April 28. 2013
Bugfixes in v2.94:

  • Fixed a bug regarding comparing date and time columns where the trigger column is empty.

April 14. 2013
Bugfixes in v2.93:

  • Fixed bug in validating required rich text field when using non English letters.
  • Fixed bug where fields appearing in the “orphan fields tab” when using Side by Side.
  • Prevented the ID column from appearing in the “orphan fields tab”.
  • Fixed bug where people pickers lost their value in EditForm in Chrome (and possibly other non-IE browsers).

There are changes in both “DynamicFormsForSharePoint_v2.js” and “default.css” – ensure you update both.

March 29. 2013
Bugfixes in v2.91:

  • Fixed bug in side-by-side functionality regarding the “fields” not getting the correct fieldtype and fielddispname attributes.
  • Fixed bug where the field label was repeated multiple times when combining side-by-side with readonly, and then switching tab.

I have released version 2.90 of Dynamic Forms for SharePoint with these changes:

  • Added content type choice as possible trigger field.
  • Added side-by-sice capabilities.
  • Fixed a bug where the link to add tabs were missing for the first setup.
  • Changed the function that dynamically resizes the dialog. This new function is created by Sing Chan, and can be found here
  • Added a fix for some occurrences where the variable L_Menu_LCID was missing in a SP2013 setup.
  • Fixed a bug in SP.UI.RTE.js that occurs when hiding rich text columns in SP2010. The workaround is provided by John Chapman.

Refer these articles for background information and setup instructions:
Dynamic Forms for SharePoint: Production
Dynamic Forms for SharePoint – Now with Tabs
Dynamic Forms for SharePoint: Now with support for SharePoint 2013

How to use the Content type as trigger

In NewForm and DispForm the content type is not visible other than in the URL. You must use the trigger “URL Query string parameter”, and “This value” like this:

ContentTypeId=YourContentTypeID

Please note that the default content type id not always shows up in the URL. If you click the “New Item” in the ribbon (in SP2010), it is included, but if you click the “Add new item” below the list view, it is not. You should therefore add rules for the “not default content type”.

How to find the ContentTypeId
Go to list settings, click the content type you want the id from, and then look at the URL. You will find it like this:

ctype=0x010300E461AB843CED5C47B6795DF8C440401A

In EditForm, you can select the content type select ine the trigger fields and address it by its display name.

Details on the side-by-side functionality

I have added an option to place fields side-by-side in the tabs like this:
IMG

The configuration is setup like this:
IMG

The yellow input fields is used to specify a common index number for the fields that are to be presented side-by-side. The fields will be lined up with the topmost field in the selection.

The checkbox is used to hide the form label for the fields like this:
IMG

Please consider the side-by-side functionality BETA, and report any bugs back to me by adding a comment below.

Alexander

SPJS Charts for SharePoint: Export to Excel and SP2013 support

A few months ago I received this email from Aymeric:

Hi Alexander,

I’ve created a JS API to use with Sharepoint. You may want to have a look at it: http://aymkdn.github.com/SharepointPlus/
I think this library could be useful for some other people. It’s on GitHub so feel free to share any comments.

Thank you,
Aymeric

It took me “forever” to look at this API, but I finally had a go at it, and decided to use one of the methods: createFile in the SPJS Charts for SharePoint solution to be able to export the chart data to Excel as a CSV file.

New in v3.4 of SPJS Charts for SharePoint

You find the “Enable export to Excel as comma-separated values (CSV)” under the “Advanced options” section in the SPJS Charts for SharePoint GUI. When you enable this feature (done individually for each chart), you can hover over the chart to show a label in the bottom right corner of the chart. Hit this to create the file. When the file is successfully created, you are prompted to open it directly.

To achieve this I included the file “sharepointplus-3.0.3.js” in the CEWP code, and I created a function that exports the chart data as comma-separated values, which I then “inject” in a dedicated document library using Aymerics API method “createFile”. This document library is automatically created the first time you save a chart with the “Export feature” enabled.

You do NOT have to load the “sharepointplus-3.0.3.js” file if you do not intend to use the export to CSV feature. If you try to enable it, and “sharepointplus-3.0.3.js” is not loaded, you will get instruction on how to get hold of the file.

The exported files

The files are named from the path to the page where the chart is located, the chart id and the user ID of the user exporting the chart. This means that the library “SPJS_ExcelExports” will not get filled up as the file is overwritten for each time the user exports the same chart. If you want to keep the file, save it in another location, or at least save it with another name to prevent it from being overwritten.

Example of the CEWP code with “sharepointplus-3.0.3.js” loaded:

<style type="text/css">
div.chartLoadingOverlay{
	font-style:italic;
	color:gray;
	border:1px silver solid;
	background-color:#F5F5F5;
	line-height:250px;
	height:250px;
	width:500px;	
	text-align:center;	
	margin:2px;
}
</style>

<!-- The chart container is set up with an overlay to let the user know the chart is rendering -->
<div id="MyChart1">
	<div class='chartLoadingOverlay'>Loading chart please be patient...</div>
</div>

<script type="text/javascript">
/*****************************************************
		Address all containers
*****************************************************/
// All charts must be represented by a container with a unique id. 
// This container  must be present in the page
var arrOfChartContainers = ["MyChart1"];
var loadRC = false;
// Set this to true to allow for the use of variables in the "Filter setup textarea"
var allowEval = false;
// Set this to true to delay the loading of the chart.
var loadManually = true;
// You can override chart options set in the GUI
var chartOptionOverride = {"TheChartID":{"title":"This is the chart title!"}};
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="/test/English/Charts/Javascript/SPJS_ChartsForSharePoint_v3.4.js"></script>
<!-- Used to enable export of chart data as CSV -->
<script type="text/javascript" src="/test/English/Charts/Javascript/sharepointplus-3.0.3.js"></script>
<!-- Used to enable export of chart data as CSV -->
<script type="text/javascript">
// This function will load the charts
function manualLoad(){
	loadManually = false;
	spjs_GenerateChart();
}

// Delay the call to the function by 10ms to give the overlay time to render 
setTimeout(function(){
	manualLoad();
},10);
</script>
SharePoint 2013

In v3.4 I have made a “quick pass” trough the code to fix some compatibility issues for SharePoint 2013.

Because this solution is funded with an occasional beer donation, I cannot fully test it as if it was a commercial product. Therefore I must rely on you guys to find the rest of the bugs. Post them here, and I’ll fix them as soon as I can manage.

Alexander

Dynamic Forms for SharePoint: Now with support for SharePoint 2013

Change log

May 06. 2013
I have released v2.95 – you find it here

March 19. 2013
v2.81 fixes a bug occurring when you set a boolean column as required.

March 01. 2013
I have released v2.8 with some new features, and a few bugfixes.
New features:

  • Add the ability to insert custom CSS and JavaScript (in the Misc tab)
  • Added “URL Query string parameter” as trigger for a rule.

Bug fixes:

  • Validating an empty lookup column with the text (none) failed. This has been fixed by checking the val() property which will be 0.
  • “showFieldDescriptionWhenReadonly” had a bug preventing it from functioning.
  • If you selected the same field twice in a tab, it misbehaved. I now strip away any duplicates by removing the last occurrence.

IMG
Refer these articles for background information and setup instructions:
Dynamic Forms for SharePoint: Production
Dynamic Forms for SharePoint – Now with Tabs

The Dynamic Forms for SharePoint solution now supports SharePoint 2013. Please note that I have just started looking at SharePoint 2013, and have tested the solution in a “Microsoft Office 365 Developer Preview” only.

There might be issues with a “non office 365″ install, but you will have to tell me about it in the comments section below.

The code is shared between SharePoint 2007, SharePoint 2010 and SharePoint 2013.

Changes from v2.65

  • Fixed bug where the tab setup link is missing in initial setup.
  • Added “show field description when readonly” switch under “Misc” section.
  • Added support for SP 2013.
  • Small change to the file default.css to remove form background color in SP 2013 (goes better with the SP 2013 look).
  • Added error handling when using invalid characters in the custom css setup in the heading configuration and including.
  • Added support for rules comparing date columns against other date columns in the form, or validation of empty / not empty date columns.

Setup
The setup for SP 2013 is similar to that for SP 2010. Please note that you need to update spjs-utility.js to use Dynamic Forms for SharePoint v2.7 – not only for SP 2013: get spjs-utility.js here.

See change log where you download spjs-utility.js. For setup instruction, see the first article linked in the top of this article.

Please post any findings below this article.

Please support my work by buying me a beer

PayPal

Translate choice column values in NewForm, DispForm and EditForm

Change log

25.02.2013 Updated the code and changed the variable “fields” to “localizeFields” to avoid interference with other scripts.


I got a request for a solution for translating choice column values in a form.

This solution changes the text in the drop-down list, radio button or checkbox in NewForm or EditForm, leaving the “value” untouched. In DispForm the field value is “localized” directly.

This means that the text the user sees is changed, but the value that SharePoint sees is the original. This means that the value shown in the form is localized, but the value stored in the SharePoint list when saving the form is not.

Add this code to a CEWP or HTML Form web part BELOW the list form web part in NewForm, DispForm and EditForm of your list.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var translationSettings = {
					"MyDropDownMenu":
						{
							"Yes":{"1044":"Ja","default":"Yes"},
							"No":{"1044":"Nei","default":"No"}
						},
					"MyMultiChoice":
						{
							"Choice 1":{"1044":"Valg 1","default":"Choice 1"},
							"Choice 2":{"1044":"Valg 2","default":"Choice 2"},
							"Choice 3":{"1044":"Valg 3","default":"Choice 3"}
						}
					};

var localizeFields = init_fields_v2();
var isDispForm = $("input:button[id$='SaveItem']").length===0;

$.each(translationSettings,function(fin,t){
	if(localizeFields[fin] !== undefined){
		var fType, arr, txt, tTxt;
		fType = "";
		txt = "";
		tTxt = "";
		if($(localizeFields[fin]).attr("fieldtype") === "SPFieldChoice"){
			if(!isDispForm){
				if($(localizeFields[fin]).find("select").length > 0){
					fType = "select";
				}else if($(localizeFields[fin]).find("select").length === 0 && $(localizeFields[fin]).find("input:radio").length > 0){
					fType = "radio";
				}
			}else{
				fType = "dispform";
			}
		}else if($(localizeFields[fin]).attr("fieldtype") === "SPFieldMultiChoice"){
			if(!isDispForm){
				fType = "multichoice";
			}else{
				fType = "dispform";
			}
		}else{
			return;
		}
		switch(fType){
			case "dispform":
				arr = $(localizeFields[fin]).find('.ms-formbody').text().replace(/[ xA0]+$/,'').split("; ");
				tTxt = [];
				$.each(arr,function(i,txt){	
					if(t[txt] !== undefined){
						tTxt.push(t[txt][L_Menu_LCID] !== undefined ? t[txt][L_Menu_LCID] : t[txt]["default"]);
					}
				});
				$(localizeFields[fin]).find('.ms-formbody').text(tTxt.join("; "));
			break;
			case "select":				
				$(localizeFields[fin]).find("select option").each(function(i,opt){
					txt = $(this).text();
					if(t[txt] !== undefined){
						tTxt = t[txt][L_Menu_LCID] !== undefined ? t[txt][L_Menu_LCID] : t[txt]["default"];
						$(this).text(tTxt);
					}
				});
			break;
			case "radio":
			case "multichoice":
				$(localizeFields[fin]).find("input").each(function(i,opt){
					txt = $(this).next().text();
					if(t[txt] !== undefined){
						tTxt = t[txt][L_Menu_LCID] !== undefined ? t[txt][L_Menu_LCID] : t[txt]["default"];
						$(this).next().text(tTxt);
					}
				});
			break;
		}
	}
});

// This function is found in spjs-utility.js and can be removed from here if you already have referred this library.
function init_fields_v2(){
	var res = {};
	$("td.ms-formbody").each(function(){
	var myMatch = $(this).html().match(/FieldName="(.+)"s+FieldInternalName="(.+)"s+FieldType="(.+)"s+/);	
		if(myMatch!=null){
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var type = myMatch[3];
			if(type=='SPFieldNote'){
				if($(this).find('script').length>0){
					type=type+"_HTML";
				}else if($(this).find("div[id$='_TextField_inplacerte']").length>0){
					type=type+"_EHTML";
				}				
			}
			if(type=='SPFieldLookup'){
				if($(this).find('input').length>0){
					type=type+"_Input";
				}
			}
			// Build object
			res[fin] = this.parentNode;
			$(res[fin]).attr('FieldDispName',disp);
			$(res[fin]).attr('FieldType',type);
		}		
	});
	return res;
}
</script>

The translation is set up in the variable “translationSettings” like this:
var translationSettings = {
“FieldInternalName”:
{
“Actual value 1″:{“1044″:”Norwegian value 1″,”default”:”Default value 1″},
“Actual value 1″:{“1044″:”Norwegian value 1″,”default”:”Default value 2″}
}
};

You can add alternate languages by using the LCID. The selected LCID must be among the installed language packs on your SharePoint server.

Ask if something is unclear.

Alexander

Lookup column relinker – cross site – for SharePoint 2007 and SharePoint 2010 – using JavaScript

I have previously posted a solution that, among other features, lets you relink a lookup column. This article introduces a new tool that does lookup column relinking only.

SharePoint 2007
IMG

SharePoint 2010
IMG

Get the code here, and ensure you use the correct version.

The difference between the 2007 and the 2010 version is that in 2007, you must place the code in a web part in the site where the lookup column resides.

You can target another site, but must run the code in the site where the column you want to alter is located.

In the 2010 version, you can change the source web as long as you target a web within the site collection.

If you like the solution, buy me a beer!

Alexander

SPJS Charts for SharePoint update 20.09.2012

27.09.2012 v3.3.6 includes these changes:

  • Changed the method for caching the filter values when loading the charts and changing the filter dropdowns. This should fix any errors when you have multiple filtered charts in one page.
  • Added option to override “chart options” set in the GUI by adding an object to the CEWP like this:
    var chartOptionOverride = {"MyChart1":{"title":"This is the chart title!"}};
    

See the CEWP code example for v3.3.6 in the download section


In v3.3.5 I have added these features:

  1. Changed the way the chart and the accessories are rendered to keep all items within the “chart container”. This helps in positioning the charts in the page.
  2. Added option to load the chart manually.
  3. Added option to display a placeholder / overlay when the chart is loading. This will prevent the page from looking like it has frozen while loading a heavy chart. The page is still unresponsive – but at least it looks better.
1.

What happens under the hood is that the chart is created in a separate container – dynamically created within the container defined in the CEWP. For those interested, this container is named containerId_chart. Where “containerId” is the id defined in the array “arrOfChartContainers” in the CEWP.

2.

You can delay the loading of the chart by 4000ms (4 seconds) like this:

<div id="MyChart1"></div>
<script type="text/javascript">
/*****************************************************
		Address all containers
*****************************************************/
// All charts must be represented by a container with a unique id. 
// This container  must be present in the page
var arrOfChartContainers = ["MyChart1"];
var loadRC = false;
var allowEval = false;

var loadManually = true;
function manualLoad(){
	loadManually = false;
	spjs_GenerateChart();
}

setTimeout(function(){
	manualLoad();
},4000);

</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="/test/English/Charts/Javascript/3.3/SPJS_ChartsForSharePoint_v3.3.5.js"></script>

Or you can make a button and call the chart manually like this:

<input type="button" onclick="manualLoad()" value="Load chart">
<div id="MyChart1"></div>
<script type="text/javascript">
/*****************************************************
		Address all containers
*****************************************************/
// All charts must be represented by a container with a unique id. 
// This container  must be present in the page
var arrOfChartContainers = ["MyChart1"];
var loadRC = false;
var allowEval = false;

var loadManually = true;
function manualLoad(){
	loadManually = false;
	spjs_GenerateChart();
}
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="/test/English/Charts/Javascript/3.3/SPJS_ChartsForSharePoint_v3.3.5.js"></script>
3.

To have a placeholder like this while the chart loads:
IMG

You must add this code to your CEWP:

<style type="text/css">
.chartLoadingOverlay{
	font-style:italic;
	color:gray;
	border:1px silver solid;
	background-color:#F5F5F5;
	line-height:250px;
	height:250px;
	width:500px;	
	text-align:center;	
	margin:2px;
}
</style>

<div id="MyChart1"></div>
<script type="text/javascript">
/*****************************************************
		Address all containers
*****************************************************/
// All charts must be represented by a container with a unique id. 
// This container  must be present in the page
var arrOfChartContainers = ["MyChart1"];
var loadRC = false;
var allowEval = false;

var loadManually = true;
function manualLoad(){
	loadManually = false;
	spjs_GenerateChart();
}
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="/test/English/Charts/Javascript/3.3/SPJS_ChartsForSharePoint_v3.3.5.js"></script>
<script type="text/javascript">

$.each(arrOfChartContainers,function(i,id){
	$("#"+id).html("<div class='chartLoadingOverlay'>Loading chart please be patient...</div>");
});
setTimeout(function(){
	manualLoad();
},100);
</script>

The setTimeout is necessary to let the browser render the overlay before it freezes while retrieving the data for the chart.

Please note the these features require v3.3.5 of SPJS Charts for SharePoint.

You find the files, and additional information in this article

Alexander




%d bloggers like this: