API Reference

Class: Share

CIQ. Share

new Share()

Manages chart sharing and uploading.

See the Chart Sharing tutorial for more details.


createImage(stx [, params], cb)

Creates a png image of the current chart and everything inside the container associated with the chart when it was instantiated; including HTML. Elements outside the chart container will NOT be included.

If widthPX and heightPX are passed in then the image will be scaled to the requested dimensions.

It will dynamically try to load js/thirdparty/html2canvas.min.js if not already loaded.

This function is asynchronous and requires a callback function. The callback will be passed a data object or canvas which can be sent to a server or converted to an image.

Important Notes:

  • This method will rely on Promises. If your browser does not implement Promises, be sure to include a polyfill.

  • This method does not always work with React or Safari

  • Canvases can only be exported if all the contents including CSS images come from the same domain, or all images have cross origin set properly and come from a server that supports CORS; which may or may not be possible with CSS images.

  • When using the charts from file:///, make sure to include html2canvas statically instead of allowing this method to load it dynamically.
    <script src="js/thirdparty/html2canvas.min.js"></script>

Name Type Argument Description
stx object

Chart object

params object <optional>

Parameters to describe the image.

Name Type Argument Description
widthPX number <optional>

Width of image to create. If passed then params.heightPX will adjust to maintain ratio.

heightPX number <optional>

Height of image to create. If passed then params.widthPX will adjust to maintain ratio.

imageType string <optional>

Specifies the file format your image will be output in. The dfault is PNG and the format must be suported by your browswer.

hide array <optional>

Array of strings; array of the CSS selectors of the DOM elements to hide, before creating a PNG

cb function

Callback when image is available fc(data) where data is the serialized image object

  • ChartIQ Advanced Package plug-in
  • 3.0.0 Function signature changed to take parameters.
  • 4.0.0 Addition of parameters.hide.

shareChart(stx [, override], cb)

Convenience function that serves as a wrapper for createImage and uploadImage. It will create an image using the default parameters. If you wish to customize the image you must use CIQ.Share.createImage separately and then call CIQ.Share.uploadImage.

Name Type Argument Description
stx object

Chart Object

override object <optional>

Parameters that overwrite the default hosting location from https://share.chartiq.com to a custom location.

Name Type Argument Description
host object <optional>
path object <optional>
cb function

Callback when the image is uploaded.

  • 2015-11-01

// here is the exact code this convenience function is using
CIQ.Share.createImage(stx, {}, function (imgData) {
	var id = CIQ.uniqueID();
	var host = "https://share.chartiq.com";
	var url = host + "/upload/" + id;
	if (override) {
		if (override.host) host = override.host;
		if (override.path) url = host + override.path + "/" + id;
	var startOffset = stx.getStartDateOffset();
	var metaData = {
		layout: stx.exportLayout(),
		drawings: stx.exportDrawings(),
		xOffset: startOffset,
		startDate: stx.chart.dataSegment[startOffset].Date,
		endDate: stx.chart.dataSegment[stx.chart.dataSegment.length - 1].Date,
		id: id,
		symbol: stx.chart.symbol,
	var payload = { id: id, image: imgData, config: metaData };
	CIQ.Share.uploadImage(imgData, url, payload, function (err, response) {
		if (err !== null) {
			CIQ.alert("error sharing chart: ", err);
		} else {
			cb(host + response);
	// end sample code to upload image to a server

uploadImage(dataImage, url [, payload], cb)

Uploads an image to a server. The callback will take two parameters. The first parameter is an error condition (server status), or null if there is no error. The second parameter (if no error) will contain the response from the server. 'payload' is an optional object that contains meta-data for the server. If payload exists then the image will be added as a member of the payload object, otherwise an object will be created 'dataImage' should be a data representation of an image created by the call canvas.toDataURL such as is returned by CIQ.Share.createImage If you are getting a status of zero back then you are probably encountering a cross-domain ajax issue. Check your access-control-allow-origin header on the server side

Name Type Argument Description
dataImage string

Serialized data for image

url string

URL to send the image

payload object <optional>

Any additional data to send to the server should be sent as an object.

cb function

Callback when image is uploaded

  • ChartIQ Advanced Package plug-in