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.
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 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>
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