Shared Interactions
Overview
The shared feature allows users to interact simultaneously with multiple charts in a graphset. ZingChart currently supports interactive sharing on legends, crosshairs, zooming, and scrolling.
Shared Legend
A shared legend allows users to interact with multiple charts at the same time. All charts must be contained in the same graphset array.
Setup
To enable legend sharing, you need to do the following:
See the following chart. For more on legends generally, including styling and interactive features, refer to the Legend Tutorial.
{
layout: '3x1',
graphset: [
{ //Chart One
type: 'line',
legend: {
shared: true
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Two
type: 'line',
legend: {
shared: true
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Three
type: 'line',
legend: { //Shared Legend
shared: true,
draggable: true,
dragHandler: 'icon',
header: {
text: 'Legend'
},
marker: {
type: 'circle'
}
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
}
]
}
Examples
Here is a small multiple pie chart with a shared legend.
{
layout: '1x3',
graphset: [
{
type: 'pie',
legend: {
shared: true
},
title: {
text: '2010',
y: '80%',
fontFamily: 'Georgia'
},
plot: {
valueBox: {
fontSize: 10,
fontWeight: 'normal',
offsetR: '20%'
}
},
series: [
{ values: [35]},
{ values: [34]},
{ values: [31]},
{ values: [19]},
{ values: [12]},
{ values: [9]}
]
},
{
type: 'pie',
legend: {
shared: true
},
title: {
text: '2013',
y: '80%',
fontFamily: 'Georgia'
},
plot: {
valueBox: {
fontSize: 10,
fontWeight: 'normal',
offsetR: '20%'
}
},
series: [
{ values: [65]},
{ values: [35]},
{ values: [30]},
{ values: [17]},
{ values: [16]},
{ values: [15]}
]
},
{
type: 'pie',
legend: {
shared: true,
layout: '1x6',
x: '13%',
y: '5%',
toggleAction: 'remove',
borderWidth: '1px',
borderColor: '#cccccc',
borderRadius: '3px',
header: {
text: 'Legend',
textAlign: 'center',
fontSize: 12,
fontFamily: 'Georgia',
},
footer: {
text: 'Click the legend items to repaint the charts without the selected series.',
textAlign: 'center',
fontSize: 10,
fontStyle: 'italic',
backgroundColor: 'white',
borderBottom: '1px solid #cccccc',
borderLeft: '1px solid #cccccc',
borderRight: '1px solid #cccccc'
},
item: {
fontFamily: 'Georgia',
borderRadius: '3px'
},
marker: {
type: 'circle',
size: 3
}
},
title: {
text: '2016',
y: '80%',
fontFamily: 'Georgia'
},
plot: {
valueBox: {
fontSize: 10,
fontWeight: 'normal',
offsetR: '20%'
}
},
series: [
{
values: [59],
text: 'Blue',
legendItem: {
backgroundColor: '#29A2CC',
fontColor: '#eaf7fb'
},
legendMarker: {
borderColor: '#29A2CC',
backgroundColor: '#eaf7fb'
}
},
{
values: [49],
text: 'Red',
legendItem: {
backgroundColor: '#D31E1E',
fontColor: '#fce9e9'
},
legendMarker: {
borderColor: '#D31E1E',
backgroundColor: '#fce9e9'
}
},
{
values: [31],
text: 'Green',
legendItem: {
backgroundColor: '#7CA82B',
fontColor: '#f5faeb'
},
legendMarker: {
borderColor: '#7CA82B',
backgroundColor: '#f5faeb'
}
},
{
values: [21],
text: 'Orange',
legendItem: {
backgroundColor: '#EF8535',
fontColor: '#f5faeb'
},
legendMarker: {
borderColor: '#EF8535',
backgroundColor: '#f5faeb'
}
},
{
values: [14],
text: 'Purple',
legendItem: {
backgroundColor: '#A14BC9',
fontColor: '#f5faeb'
},
legendMarker: {
borderColor: '#A14BC9',
backgroundColor: '#f5faeb'
}
},
{
values: [9],
text: 'Brown',
legendItem: {
backgroundColor: '#A05F18',
fontColor: '#f5faeb'
},
legendMarker: {
borderColor: '#A05F18',
backgroundColor: '#f5faeb'
}
}
]
}
]
}
Shared Crosshairs
Shared crosshairs allow users to view information about two or more charts at the same time. All charts must be contained in the same graphset array.
Setup
To enable shared crosshairs, you need to do the following:
See the following chart. For more on crosshairs generally, including customization and styling, refer to the Crosshairs Tutorial.
{
layout: '3x1',
graphset: [
{ //Chart One
type: 'line',
crosshairX: {
shared: true
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plot: {
tooltip: {
visible: false
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Two
type: 'line',
crosshairX: {
shared: true
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plot: {
tooltip: {
visible: false
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Three
type: 'line',
crosshairX: {
shared: true
},
scaleX: {
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plot: {
tooltip: {
visible: false
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
}
]
}
Examples
Here is a comparison of three stock funds with shared crosshairs.
{
layout: '3x1',
graphset: [
{
type: 'stock',
crosshairX: {
plotLabel: {
text: 'Open: $%open<br>High: $%high<br>Low: $%low<br>Close: $%close',
decimals: 2,
fontColor: '#29A2CC',
textAlpha: 1,
backgroundColor: 'white',
alpha: 0.7,
borderColor: '#29A2CC',
borderRadius: '3px',
multiple: true
},
scaleLabel: {
visible: false
},
lineColor: '#29A2CC',
shared: true
},
scaleX: {
minValue: 1420232400000,
step: 'day',
transform: {
type: 'date',
all: '%m/%d/%y'
},
maxItems: 6,
item: {
fontSize: 10
}
},
scaleY: {
values: '30:34:4',
format: '$%v',
guide: {
lineStyle: 'solid'
},
item: {
fontSize: 10
}
},
plot: {
aspect: 'candlestick',
tooltip: {
visible: false
},
trendUp: {
backgroundColor: '#29A2CC',
lineColor: '#29A2CC',
borderColor: '#29A2CC'
},
trendDown: {
backgroundColor: 'none',
lineColor: '#29A2CC',
borderColor: '#29A2CC'
}
},
plotarea: {
marginLeft: '17%',
marginRight: 'dynamic',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Blue<br>Stock',
fontFamily: 'Georgia',
fontColor: 'white',
x: '2%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#29A2CC',
borderRadius: '3px'
}
],
series: [
{
values: [
//Omitted for brevity.
]
}
]
},
{
type: 'stock',
crosshairX: {
plotLabel: {
text: 'Open: $%open<br>High: $%high<br>Low: $%low<br>Close: $%close',
decimals: 2,
fontColor: '#D31E1E',
textAlpha: 1,
backgroundColor: 'white',
alpha: 0.7,
borderColor: '#D31E1E',
borderRadius: '3px',
multiple: true
},
scaleLabel: {
visible: false
},
lineColor: '#D31E1E',
shared: true
},
scaleX: {
minValue: 1420232400000,
step: 'day',
transform: {
type: 'date',
all: '%m/%d/%y'
},
maxItems: 6,
item: {
fontSize: 10
}
},
scaleY: {
values: '30:34:4',
format: '$%v',
guide: {
lineStyle: 'solid'
},
item: {
fontSize: 10
}
},
plot: {
aspect: 'candlestick',
tooltip: {
visible: false
},
trendUp: {
backgroundColor: '#D31E1E',
lineColor: '#D31E1E',
borderColor: '#D31E1E'
},
trendDown: {
backgroundColor: 'none',
lineColor: '#D31E1E',
borderColor: '#D31E1E'
}
},
plotarea: {
marginLeft: '17%',
marginRight: 'dynamic',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Red<br>Stock',
fontFamily: 'Georgia',
fontColor: 'white',
x: '2%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#D31E1E',
borderRadius: '3px'
}
],
series: [
{
values: [
//Omitted for brevity.
]
}
]
},
{
type: 'stock',
crosshairX: {
plotLabel: {
text: 'Open: $%open<br>High: $%high<br>Low: $%low<br>Close: $%close',
decimals: 2,
fontColor: '#7CA82B',
textAlpha: 1,
backgroundColor: 'white',
alpha: 0.7,
borderColor: '#7CA82B',
borderRadius: '3px',
multiple: true
},
scaleLabel: {
fontColor: 'gray',
backgroundColor: 'white',
borderWidth: '1px',
borderColor: 'gray',
borderRadius: '3px'
},
lineColor: '#7CA82B',
shared: true
},
scaleX: {
minValue:1420232400000,
step: 'day',
transform: {
type: 'date',
all: '%m/%d/%y'
},
maxItems: 6,
item: {
fontSize: 10
}
},
scaleY: {
values: '30:34:4',
format: '$%v',
guide: {
lineStyle: 'solid'
},
item: {
fontSize: 10
}
},
plot: {
aspect: 'candlestick',
tooltip: {
visible: false
},
trendUp: {
backgroundColor: '#7CA82B',
lineColor: '#7CA82B',
borderColor: '#7CA82B'
},
trendDown: {
backgroundColor: 'none',
lineColor: '#7CA82B',
borderColor: '#7CA82B'
}
},
plotarea: {
marginLeft: '17%',
marginRight: 'dynamic',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Green<br>Stock',
fontFamily: 'Georgia',
fontColor: 'white',
x: '2%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#7CA82B',
borderRadius: '3px'
}
],
series: [
{
values: [
//Omitted for brevity.
]
}
]
}
]
}
Shared Zooming
Shared zooming allows users to zoom in on two or more charts at the same time. All charts must be contained in the same graphset array.
Setup
To enable shared zooming, you need to do the following:
See the following chart. For more on zooming generally, including customization and styling, refer to the Zooming, Scrollbar, and Preview Chart Tutorial.
{
layout: '3x1',
graphset: [
{ //Chart One
type: 'line',
zoom: {
shared: true
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
},
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Two
type: 'line',
zoom: {
shared: true
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
},
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Three
type: 'line',
zoom: {
shared: true
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
}
]
}
Examples
Here are three charts-a bar chart, area chart, and heat map-with shared zooming.
Note: Using blended scales in a mixed chart is another way to achieve the same shared zooming effect between two or more charts in a graphset .
{
layout: '3x1',
graphset: [
{
type: 'bar',
zoom: {
shared: true,
backgroundColor: '#29A2CC',
label: {
visible: true,
fontColor: '#29A2CC',
fontFamily: 'Georgia',
borderColor: '#29A2CC',
padding: '3%'
}
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:300:150',
item: {
fontSize: 10
}
},
plot: {
'bar-width': '50%',
backgroundColor: '#29A2CC'
},
plotarea: {
marginLeft: 'dynamic',
marginRight: '15%',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Bar<br>Chart',
fontFamily: 'Georgia',
fontColor: 'white',
x: '90%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#29A2CC',
borderRadius: '3px'
}
],
series: [
{ values: [ /* Omitted for brevity */]}
]
},
{
type: 'area',
zoom: {
shared: true,
backgroundColor: '#D31E1E',
label: {
visible: true,
fontColor: '#D31E1E',
fontFamily: 'Georgia',
borderColor: '#D31E1E',
padding: '3%'
}
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:300:150',
item: {
fontSize: 10
}
},
plot: {
lineColor: '#D31E1E',
marker: {
size: 3,
backgroundColor: '#D31E1E'
},
backgroundColor: '#D31E1E'
},
plotarea: {
marginLeft: 'dynamic',
marginRight: '15%',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Area<br>Chart',
fontFamily: 'Georgia',
fontColor: 'white',
x: '90%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#D31E1E',
borderRadius: '3px'
}
],
series: [
{ values: [ /* Omitted for brevity */]}
]
},
{
type: 'heatmap',
zoom: {
shared: true,
backgroundColor: '#7CA82B',
label: {
visible: true,
fontColor: '#7CA82B',
fontFamily: 'Georgia',
borderColor: '#7CA82B',
padding: '3%'
}
},
scaleX: {
zooming: true,
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:300:150',
item: {
fontSize: 10
}
},
plot: {
lineColor: '#7CA82B',
backgroundColor: '#7CA82B',
marker: {
backgroundColor: '#7CA82B'
}
},
plotarea: {
marginLeft: 'dynamic',
marginRight: '15%',
marginTop: 'dynamic',
marginBottom: 'dynamic'
},
labels: [
{
text: 'Heat<br>Map',
fontFamily: 'Georgia',
fontColor: 'white',
x: '90%',
y: '35%',
height: '30%',
width: '7%',
backgroundColor: '#7CA82B',
borderRadius: '3px'
}
],
series: [
{ values: [ /* Omitted for brevity */]}
{ values: [ /* Omitted for brevity */]}
{ values: [ /* Omitted for brevity */]}
]
}
]
}
Shared Scrolling
Shared scrolling allows users to scroll through two or more charts at the same time. All charts must be contained in the same graphset array.
Setup
To enable shared scrolling, you need to do the following:
See the following chart. For more on zooming and scrolling generally, including styling and customization, refer to the Zooming, Scrollbar, and Preview Chart Tutorial.
{
layout: '3x1',
graphset: [
{ //Chart One
type: 'line',
zoom: {
shared: true
},
scrollX: {
},
scaleX: {
zooming: true,
zoomTo: [0,21],
maxItems: 11,
item: {
fontSize: 10
},
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Two
type: 'line',
zoom: {
shared: true
},
scrollX: {
},
scaleX: {
zooming: true,
zoomTo: [0,21],
maxItems: 11,
item: {
fontSize: 10
},
},
scaleY: {
values: '0:400:200',
item: {
fontSize:10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
},
{ //Chart Three
type: 'line',
zoom: {
shared: true
},
scrollX: {
},
scaleX: {
zooming: true,
zoomTo: [0,21],
maxItems: 11,
item: {
fontSize: 10
}
},
scaleY: {
values: '0:400:200',
item: {
fontSize: 10
}
},
plotarea: {
margin: 'dynamic'
},
series: [
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]},
{ values: [ /* Omitted for brevity.*/ ]}
]
}
]
}
Examples
Here is a stock and volume chart with shared scrolling.
Note: Using blended scales in a mixed chart is another way to achieve the same shared scrolling effect between two or more charts in a graphset.
{
graphset: [
{
type: 'stock',
scaleX: {
minValue: 1435741200000,
step: 'day',
transform: {
type: 'date',
all: '%m/%d/%y'
},
item: {
fontSize: 10
},
visible: false,
zooming: true
},
zoom: {
shared: true,
backgroundColor: '#29A2CC'
},
scaleY: {
values: '400:700:100',
format: '$%v',
item: {
fontSize: 10
},
guide: {
lineStyle: 'dotted'
}
},
title: {
text: 'Stock & Volume',
fontFamily: 'Georgia'
},
height: '65%',
width: '100%',
x: '0%',
y: '0%',
plot: {
aspect: 'candlestick',
tooltip: {
visible: false
},
trendUp: {
backgroundColor: '#29A2CC',
borderColor: '#29A2CC',
lineColor: '#29A2CC'
},
trendDown: {
backgroundColor: 'none',
borderColor: '#D31E1E',
lineColor: '#D31E1E'
}
},
plotarea: {
marginBottom: 'dynamic'
},
crosshairX: {
shared: true,
plotLabel: {
text: 'Open: $%v0<br>High: $%v1<br>Low: $%v2<br>Close: $%v3',
decimals: 2,
multiple: true,
backgroundColor: 'white',
alpha: 0.8,
padding: '5%',
borderColor: '#29A2CC',
borderRadius: '3px',
},
scaleLabel: {
visible: false
}
},
series: [
{
values: [
//Omitted for brevity.
]
}
]
},
{
type: 'bar',
scaleX: {
minValue: 1435741200000,
step: 'day',
transform: {
type: 'date',
all: '%m/%d/%y'
},
item: {
fontSize: 10
},
zooming: true,
zoomToValues: [1435741200000,1443603600000]
},
zoom: {
shared: true,
backgroundColor: '#7CA82B'
},
scrollX: {
bar: {
backgroundColor: '#7ecde7 #d4eef7',
alpha: 0.5,
height: '15%'
},
handle: {
backgroundColor: '#29A2CC',
height: '3%'
}
},
scaleY: {
values: '0:30:10',
format: '%vM',
item: {
fontSize: 10
},
guide: {
lineStyle: 'dotted'
}
},
height: '35%',
width: '100%',
x: '0%',
y: '65%',
plot: {
'bar-width': '50%',
backgroundColor: '#7CA82B'
},
plotarea: {
marginTop: 'dynamic'
},
crosshairX: {
shared: true,
plotLabel: {
text: 'Volume: %vM',
decimals: 2,
multiple: true,
backgroundColor: 'white',
alpha: 0.8,
padding: '5%',
borderColor: '#7CA82B',
borderRadius: '3px',
},
scaleLabel: {
fontColor: 'gray',
backgroundColor: 'white',
borderWidth: '1px',
borderColor: 'gray',
borderRadius: '3px'
}
},
series: [
{
values: [
//Omitted for brevity.
]
}
]
}
]
}
Summary
Have questions about how shared chart interactions work? We're happy to help! Email support@zingchart.com or start a chat right here on this page for support.