Change highstock chart zones on click yAxis - javascript

Here is my working example, its works good but i try change color for zones when i click on chart:
<script type="text/javascript">
function minutesFromMidnight() {
var midnight = new Date();
midnight.setHours( 24 );
midnight.setMinutes( 0 );
midnight.setSeconds( 0 );
midnight.setMilliseconds( 0 );
return Math.floor(1440 -(( midnight.getTime() - new Date().getTime() ) / 1000 / 60));
}
$.getJSON('http://waluty.breakermind.com/symbols/getsymbolsm1chart.php?s=GBPJPY&callback=?', function (data) {
// Plot line id name
var PlotLineId="PlotLine";
// create the chart
var chart = new Highcharts.stockChart('container', {
chart: {
spacing: 20,
height: 600,
backgroundColor: '#2e2e40',
style: {
fontFamily: 'Roboto, sans-serif'
},
resetZoomButton: {
theme: {
display: 'none'
}
},
events: {
click: function(evt) {
var yValue = evt.yAxis[0].value;
var yAxis = evt.yAxis[0].axis;
$.each(yAxis.plotLinesAndBands,function(){
if(this.id===PlotLineId)
{
this.destroy();
}
});
yAxis.addPlotLine({
value: yValue,
width: 2,
color: '#99ff00',
color: '#ff3D00',
dashStyle: 'solid',
id: PlotLineId
});
zones: [{
value: 0,
color: '#ff3300'
}, {
value: yValue,
color: '#ff3300'
}, {
color: '#3c3'
}]
}
}
},
// buttons navigation png
drilldown: {
activeAxisLabelStyle: {
color: '#202033'
},
activeDataLabelStyle: {
color: '#202033'
}
},
// Scroll chart navogator
navigator: {
enabled: true,
height: 50,
margin: 20,
maskFill: "rgba(102,133,194,0.2)",
maskInside: true,
outlineColor: "#3c3",
outlineWidth: 1,
handles: {
backgroundColor: "#3c3",
borderColor: "#202033"
}
},
// scroll bar bottom
navigation: {
buttonOptions: {
symbolStroke: '#3C3',
theme: {
fill: '#202033'
}
}
},
scrollbar: {
barBackgroundColor: '#3c3',
barBorderRadius: 5,
barBorderWidth: 0,
buttonBackgroundColor: '#ff3d00',
buttonBorderWidth: 0,
buttonBorderRadius: 5,
trackBackgroundColor: 'none',
trackBorderWidth: 8,
trackBorderRadius: 5,
trackBorderColor: '#202033'
},
rangeSelector : {
selected : 1
},
// disabled in css
rangeSelector : {
allButtonsEnabled: true,
buttons: [{
type: 'minute',
count: 1,
text: '1m'
}, {
type: 'minute',
count: 5,
text: '5m'
}, {
type: 'minute',
count: 15,
text: '15m'
}, {
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'hour',
count: 4,
text: '4h'
}, {
type: 'day',
count: 1,
text: '1D'
}, {
type: 'week',
count: 1,
text: '1W'
}, {
type: 'month',
count: 1,
text: '1MN'
}, {
type: 'year',
count: 1,
text: '1Y'
}, {
type: 'all',
text: 'All'
}],
inputEnabled:false,
buttonTheme: {
fill: '#202033',
stroke: '#3c3',
style: {
color: '#707073'
},
states: {
hover: {
fill: '#339933',
stroke: '#000',
style: {
color: 'white'
}
},
select: {
fill: '#ff3d00',
stroke: '#fff',
style: {
color: 'white'
}
}
}
},
inputBoxBorderColor: '#505053',
inputStyle: {
backgroundColor: '#202033',
color: 'silver'
},
labelStyle: {
color: 'silver'
}
},
title: {
text: 'Wykres <?php echo $s; ?>'
},
xAxis: [{
//alternateGridColor: '#FDFFD5',
plotLines: [{ // mark the weekend
color: '#ff3d00',
width: 2,
value: Date.UTC(2017, 2, 3),
dashStyle: 'longdashdot'
}],
tickInterval: 24 * 3600 * 1000,
// one day x label intervals (poziona skala)
type: 'datetime',
labels: {
style: {
color: '#3a3a4s',
fontSize: '1em'
}
},
}],
yAxis: [{
title: {
text: 'Exchange rate'
},
plotLines: [{
value: 0,
color: 'green',
dashStyle: 'shortdash',
width: 2,
label: {
text: 'Last quarter minimum'
}
}, {
value: 0,
color: 'red',
dashStyle: 'shortdash',
width: 2,
label: {
text: 'Last quarter maximum'
}
}],
//alternateGridColor: '#eee',
gridLineColor: "#202033",
gridLineDashStyle: "longdash",
gridLineWidth: 1,
labels: {
style: {
color: '#eee',
fontSize: '1em'
}
},
}],
series: [{
id: "main",
type: 'spline',
name: '<?php echo $s; ?>',
color: '#33CC33',
negativeColor: '#FF3D00',
data: data,
tooltip: {
color: '#fdcc66',
negativeColor: '#202033',
valueDecimals: 4,
valueSuffix: ' USD',
pointFormat: '<span style="color:{series.color}">Profit / Loss {series.name}</span>: <b>{point.y:.3f}</b><br/>'
},
tooltip: {
color: '#fdcc66',
color: '#ff6600',
negativeColor: '#FFC4C4',
valueDecimals: 4,
valueSuffix: ' USD',
pointFormat: '<span style="color:{series.color}"> {series.data[0]} Profit / Loss {series.name}</span>: <b>{point.y}</b><br/>'
},
dataGrouping: {
units: [[
'millisecond', // unit name
[1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
], [
'second',
[1, 2, 5, 10, 15, 30]
], [
'minute',
[1, 2, 5, 10, 15, 30]
], [
'hour',
[1, 2, 3, 4, 6, 8, 12]
], [
'day',
[1]
], [
'week',
[1]
], [
'month',
[1, 3, 6]
], [
'year',
null
]]
},
zones: [{
value: 0,
color: '#ff3300', dashStyle: 'solid'
}, {
value: 140,
color: '#ff3300'
}, {
color: '#3c3',
dashStyle: 'solid'
}]
}]
});
console.log(chart.series[0]);
// alert(chart.series[0].data[5].y);
console.log(chart.series[0].xData.indexOf(Date.UTC(2017, 2, 3)));
var id = chart.series[0].xData.indexOf(Date.UTC(2017, 2, 3));
var price = chart.series[0].yData[id];
console.log(price);
//console.log(chart.get("container").data[5].y);
//alert(chart.series[0].data[data.length-1].y);
});
function getYPrice(series){
// get yPrice with date
var id = series.xData.indexOf(Date.UTC(2017, 2, 3));
return series.yData[id];
}
</script>
How change zones level on click (when i click on chart i draw line on yAxis (price) value and then i want change zones levels to this value)?
How can i do that?

You need to call update() method on a proper series - and set new zones for the series.
events: {
click: function(evt) {
var yValue = evt.yAxis[0].value;
var yAxis = evt.yAxis[0].axis;
$.each(yAxis.plotLinesAndBands, function() {
if (this.id === PlotLineId) {
this.destroy();
}
});
yAxis.addPlotLine({
value: yValue,
width: 2,
color: '#99ff00',
color: '#ff3D00',
dashStyle: 'solid',
id: PlotLineId
}, false);
var zones = [{
value: 0,
color: '#ff3300'
}, {
value: yValue,
color: '#ff3300'
}, {
color: '#3c3'
}]
this.series[0].update({
zones: zones
});
}
}
example: http://jsfiddle.net/5uaoyrwd/

Related

spline chart highchart to fill the color in series

I have created one highchart in jsfiddle
Highcharts.chart('container', {
chart: {
type: 'areaspline',
},
title: {
text: 'Soverign Capped 1 year PD',
align: 'left',
backgroundColor: 'gray',
style: {
fontSize: "12px",
}
},
subtitle: {
text: '30 days moving average',
align: 'left',
style: {
color: 'gray',
fontSize: "8px",
}
},
xAxis: {
categories: [
'10/11/2019',
'11/11/2019',
'12/11/2019',
'1/11/2020',
'2/11/2020',
'3/11/2020',
'4/11/2020'
],
min: 0.5,
max: 5.5,
startOnTick: false,
endOnTick: false
},
yAxis: {
title: {
text: 'PD%',
align: 'high',
fontWeight: 'bold'
},
max: 25,
startOnTick: false,
endOnTick: false
},
tooltip: {
enabled: false
},
credits: {
enabled: false
},
plotOptions: {
series: {
marker: {
enabled: false
},
states: {
inactive: {
opacity: 1
}
},
dataLabels: {
enabled: true,
inside: true,
style: {
fontWeight: "bold",
},
formatter: function() {
if (this.x == "4/11/2020") {
return this.series.name;
}
}
}
},
enableMouseTracking: false,
tooltip: {
enabled: false
},
areaspline: {
fillOpacity: 1,
},
},
series: [{
color: '#fbb189',
name: 'Deitrioting',
showInLegend: false,
data: [25, 25, 25, 25, 25, 25, 25]
},
{
color: '#fff2d0',
name: 'Stable',
showInLegend: false,
data: [3, 4, 5, 5, 4, 10, 10]
}, {
color: '#c2e0b7',
name: 'Improving',
showInLegend: false,
data: [1, 3, 4, 3, 3, 5, 7]
},
{
name: '',
showInLegend: false,
type: 'spline',
data: [7.0, 6.9, 9.5, 12, 23, 4, 3]
}
]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
Currently, I have defined different colour for the different series. But for the last date, I want to set the red colour for all the series.
Can you help me with this?
Sample image attached below.
You can use zones:
plotOptions: {
...,
areaspline: {
...,
zones: [{
value: 5.5
}, {
color: 'red',
value: 6.5
}],
},
}
Live demo: https://jsfiddle.net/BlackLabel/m4u5zt8g/
API Reference: https://api.highcharts.com/highcharts/series.area.zones

Highcharts age pyramid stacked bar (grouping)

I would like to use the highcharts age pyramid for men and women. Men and women can fall into three different categories. For example a, b and c. I would like to have a stacked bar for the three groups for men and women separately per age. Hopefully you can help me with this.
I have created the following age pyramid example, but as you can see, it has not yet been possible to add more than two groups.
JavaScript
var chart = Highcharts.chart('container', {
chart: {
type: 'bar',
marginLeft: 10
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
xAxis: {
left: '50%',
categories: ['15-19', '20-21'],
lineWidth: 0,
tickWidth: 0,
labels: {
align: 'left',
x: -18
},
title: {
text: 'Age Group',
align: 'high',
rotation: 0,
x: 40
}
},
yAxis: [{
left: '55%',
width: '45%',
labels: {
enabled: false
},
title: {
x: -160,
text: 'Female'
},
gridLineWidth: 0
}, {
reversed: true,
width: '45%',
offset: 0,
labels: {
enabled: false
},
title: {
x: 170,
text: 'Male'
},
gridLineWidth: 0
}],
series: [{
data: [1, 3],
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
[0, '#3F7EBF'],
[1, '#1F3F5F']
]
},
}, {
data: [2, 5],
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
[0, '#980061'],
[1, '#4C0030']
]
},
yAxis: 1
}]
});
This is what i want to achieve in the end:
This chart type is not supported by Highcharts library out of the box.
However, something similar can be created using two charts next to each other with one axis reversed. Check demo and code posted below.
Code:
Highcharts.chart('container1', {
chart: {
type: 'bar'
},
title: {
text: ''
},
xAxis: {
categories: ['15-19', '20-21', '21-25'],
labels: {
enabled: false
}
},
yAxis: {
min: 0,
reversed: true,
title: {
text: 'males',
align: 'high'
}
},
credits: {
enabled: false
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'A',
data: [5, 3, 4]
}, {
name: 'B',
data: [2, 2, 3]
}, {
name: 'C',
data: [3, 4, 4]
}]
});
Highcharts.chart('container2', {
chart: {
type: 'bar'
},
title: {
text: ''
},
xAxis: {
categories: ['15-19', '20-21', '21-25'],
labels: {
align: 'center'
}
},
yAxis: {
min: 0,
title: {
text: 'females',
align: 'low'
}
},
credits: {
enabled: false
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'A',
data: [2, 4, 1]
}, {
name: 'B',
data: [5, 2, 1]
}, {
name: 'C',
data: [4, 1, 2]
}]
});
#container1 {
width: 45%;
float: left;
}
#container2 {
width: 55%;
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container1"></div>
<div id="container2"></div>
Demo:
https://jsfiddle.net/BlackLabel/cg5af2dz/
Just a multiple series of data
series: [{
name: 'A (m)',
data: [6, 2],
yAxis: 1
}, {
name: 'B (m)',
data: [2, 2],
yAxis: 1
},
...
]
and stacking: 'normal'
series: {
stacking: 'normal'
}
solves the problem
var chart = Highcharts.chart('container', {
chart: {
type: 'bar',
height: 170,
marginLeft: 10
},
title: '',
plotOptions: {
bar: {
dataLabels: {
enabled: false,
}
},
series: {
stacking: 'normal'
}
},
xAxis: {
left: '50%',
categories: ['15-19', '20-21'],
lineWidth: 0,
tickWidth: 0,
offset: 0,
labels: {
enabled: true,
align: 'left',
x: -18
},
stackLabels: {
enabled: true,
align: 'right',
x: 20
},
title: {
text: 'age group',
align: 'high',
rotation: 0,
x: 40
}
},
yAxis: [{
left: '55%',
width: '45%',
offset: 0,
labels: {
enabled: false
},
title: {
x: -210,
text: 'males'
},
gridLineWidth: 0
}, {
reversed: true,
width: '45%',
offset: 0,
labels: {
enabled: false
},
title: {
x: 210,
text: 'females'
},
stackLabels: {
enabled: true,
align: 'left',
x: -20
},
gridLineWidth: 0
}],
series: [{
name: 'A (m)',
data: [6, 2],
color: '#000',
yAxis: 1
}, {
name: 'B (m)',
data: [2, 2],
color: '#02aff1',
yAxis: 1
}, {
name: 'C (m)',
data: [2, 2],
color: '#e0301e',
yAxis: 1
}, {
name: 'A (f)',
data: [2, 2],
color: '#000',
}, {
name: 'B (f)',
data: [2, 2],
color: '#02aff1',
}, {
name: 'C (f)',
data: [6, 2],
color: '#e0301e',
}]
});
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<div id="container"></div>

Highcharts - Custom format for dateTimeLabelFormats (1st hour, 2nd hour....)

I am using Highcharts with Area graph.
How can I customize xAxis label as hourly basis with suffix as 1st, 2nd, 3rd etc...?
Online Demo
Current format:
01th hour, 02th hour, 03th hour ....
This has to be changed as below:
1st hour, 2nd hour, 3rd hour....
I have tried to convert as above by using ordinal method, but not working though...
May be placing the ordinal script is wrong?
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
Full Code:
$(function (n) {
// Everything in common between the charts
var commonOptions = {
colors: ['#fe5758', '#99cc03', '#33b5e6', '#fd8f40', '#e7ca60', '#40abaf', '#f6f7f8', '#e9e9eb'],
chart: {
style: {
fontFamily: 'Roboto Light',
fontWeight: 'normal',
fontSize: '12px',
color: '#585858',
}
},
title: {
text: null
},
subtitle: {
text: null
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
xAxis: {
title: {
style: {
fontFamily: 'Roboto',
color: "#000",
}
},
labels: {
style:{ color: '#000' }
},
lineColor: '#e4e4e4',
lineWidth: 1,
tickLength: 0,
},
yAxis: {
title: {
style: {
fontFamily: 'Roboto',
color: "#000",
}
},
offset:-6,
labels: {
style:{ color: '#bbb' }
},
tickInterval: 100,
lineColor: '#e4e4e4',
lineWidth: 1,
gridLineDashStyle: 'dash',
},
series: [{
backgroundColor: "rgba(0 ,0, 0, 0.5)",
}],
// Area Chart
plotOptions: {
area: {
stacking: 'normal',
lineWidth: 1,
fillOpacity: 0.1,
marker: {
lineWidth: 1.5,
symbol: 'circle',
fillColor: 'white',
},
legend: {
radius: 2,
}
}
},
tooltip: {
useHTML: true,
shared: true,
backgroundColor: '#5f5f5f',
borderWidth: 0,
style: {
padding:10,
color: '#fefefe',
}
},
legend: {
itemStyle: {
fontFamily: 'Roboto Light',
fontWeight: 'normal',
fontSize: '12',
color: '#666666',
},
marker: {
symbol: 'square',
verticalAlign: 'middle',
radius: '4',
},
symbolHeight: 6,
symbolWidth: 6,
},
};
$('#areaChartTwoWay-time').highcharts(Highcharts.merge(commonOptions, {
chart: { type: 'area' },
xAxis: {
title: { text: 'Hours', },
type: 'datetime',
min:Date.UTC(2016,04,16,1,0,0,0),
minRange: 12 * 3600 * 500,
dateTimeLabelFormats: {
hour: '%Hth hour',
},
},
yAxis: {
tickInterval: 30,
title: { text: 'Total views', },
offset:0,
},
series: [{
name: 'Unique open',
lineColor: '#fb8b4b',
marker: { lineColor: '#fb8b4b', fillColor: 'white', },
data: [88, 68, 79, 39, 48, 69, 69, 18, 40, 62, 91, 61, 39],
legendIndex:1,
pointInterval: 3600 * 500,
pointStart:Date.UTC(2016,04,16,1,0,0,0),
}, {
name: 'Forwards',
lineColor: '#99cc03',
marker: { lineColor: '#99cc03', fillColor: 'white', },
data: [3, 8, 15, 12, 61, 32, 43, 18, 9, 12, 22, 18, 12],
legendIndex:0,
pointInterval: 3600 * 500,
pointStart:Date.UTC(2016,04,16,1,0,0,0),
}]
}));
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
$('.highcharts-grid > path:last-child').remove();
$('.highcharts-markers > path:last-child').remove();
});
You could call another function to get the ordinal. A quick google found this method:
function getGetOrdinal(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
This takes a number and returns a string, which is made up of the number with he correct ordinal appended.
This won't work with dateTimeLabelFormats though. For your use, you could use a simple label formatter.
I've updated your online demo here also:
http://jsfiddle.net/6nz0sod1/2/
Hope this helps
Source: https://ecommerce.shopify.com/c/ecommerce-design/t/ordinal-number-in-javascript-1st-2nd-3rd-4th-29259

Draw vertical lines and horizontal bands

Am plotting array directly to series of my high chart.I need to show vertical lines in x-axis and horizontal bands in y axis as different colors.
Need to add vertical lines and horizontal bars according to values displayed in chart.
Here is my code:
$('#container').highcharts({
title: {
text: 'Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
credits: {
enabled: false
},
colors: ['red'],
xAxis: {
// categories: [],
title: {
text: 'Time'
},
},
yAxis: {
title: {
text: 'Rate'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Heart Rate',
data: data_arr
}]
});
For that, you can use chart.xAxis[0].categories.length to access the length of xAxis, and chart.xAxis[0].categories[] to access the values of xAxis' elements.
Check the following example:
$(function() {
$('#container').highcharts({
xAxis: {
categories: [10, 20, 30, 40, 50, 60, 70]
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]
}]
});
// the button action
var hasPlotLine = false,
$button = $('#button'),
chart = $('#container').highcharts();
$button.click(function() {
for (i = 1; i < chart.xAxis[0].categories.length; i++) {
if (chart.xAxis[0].categories[i] > 30) {
chart.xAxis[0].addPlotLine({
value: i,
color: 'red',
width: 2,
id: 'plot-line-1'
});
}
}
});
});
To set up vertical/horizontal lines/Bands use plotBands or/and plotLines options:
For lines:
plotLines: [{
color: '#FF0000',
width: 2,
value: 5.5
}]
For Band
plotBands: [{ // mark the weekend
color: '#FCFFC5',
from: Date.UTC(2010, 0, 2),
to: Date.UTC(2010, 0, 4)
}],
You can read more here:
http://api.highcharts.com/highcharts#xAxis.plotBands
http://api.highcharts.com/highcharts#xAxis.plotLines
Check the following example jsfiddle
$(function() {
$('#container').highcharts({
title: {
text: 'Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
credits: {
enabled: false
},
colors: ['red'],
xAxis: {
// categories: [],
title: {
text: 'Time'
},
plotLines: [{
color: 'blue',
width: 1,
value: 1,
dashStyle: 'longdashdot',
zIndex: 3
}, {
color: 'blue',
width: 1,
value: 2,
dashStyle: 'longdashdot',
zIndex: 3
}, {
color: 'blue',
width: 1,
value: 3,
dashStyle: 'longdashdot',
zIndex: 3
}],
zIndex: 3,
},
yAxis: {
title: {
text: 'Rate'
},
plotBands: [{ // mark the weekend
color: '#BEE9B4',
from: 1,
to: 4
}, { // mark the weekend
color: '#EB813B',
from: 4,
to: 6
}, { // mark the weekend
color: '#E93A0F',
from: 6,
to: 8
}],
zIndex: 2,
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: [{
type: 'spline',
name: 'Heart Rate',
data: [4, 5, 1, 2, 8, 7, 4, 1]
}]
});
});

Highcharts Pie Chart Specify Pie Slice Gradient Color

I have a Highcharts Pie Chart and I am using radial gradients.
Demo: http://jsfiddle.net/19vyugeL/1/
Issue: Apply specific gradient color to specific pie slice. For a normal color I use the color: on the data, but I dont know how to do that with the gradients.
Goal: I want the "Remaining" budget slice the color it currently is and all the "Spent" slices the other color (green).
$(function () {
// Create the chart
$('#container9').highcharts({
colors: [{
radialGradient: {
cx: 0.5,
cy: 0.3,
r: 0.7
},
stops: [
[0, RemainingColor1],
[1, RemainingColor2]
]
}, {
radialGradient: {
cx: 0.5,
cy: 0.3,
r: 0.7
},
stops: [
[0, SpentColor1],
[1, SpentColor2]
]
}],
chart: {
type: 'pie',
marginTop: 50,
marginBottom: 5,
},
title: {
text: 'Total Budget - $440,000'
},
subtitle: {
text: 'Total Spent - $103,057'
},
plotOptions: {
series: {
borderWidth: 2
},
pie: {
allowPointSelect: true,
borderWidth: 3,
borderColor: 'black',
dataLabels: {
style: {
fontSize: 9,
},
distance: -1,
y: -10,
x: 10,
color: TextColor,
enabled: true,
inside: true,
verticalAlign: 'top',
format: '{point.name}<br/> {point.y}%<br/>${point.spend}'
}
},
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: {point.y:.2f}% - ${point.spend} of Total'
},
series: [{
name: new Date().getFullYear() + " National Spend ",
data: [{
name: new Date().getFullYear() + " Remaining Budget",
y: 79,
spend: '336,943',
// color: RemainingColor1,
}, {
name: "Wave 2",
y: 23,
// color: SpentColor1,
spend: '97,693'
}, {
name: "Wave 3",
y: 3,
// color: SpentColor1,
spend: '5,364',
}]
}]
});
});
Define the array colors, and then you can access it when you assign the color:
$(function () {
colors = [{
radialGradient: {
cx: 0.5,
cy: 0.3,
r: 0.7
},
stops: [
[0, RemainingColor1],
[1, RemainingColor2]
]
}, {
radialGradient: {
cx: 0.5,
cy: 0.3,
r: 0.7
},
stops: [
[0, SpentColor1],
[1, SpentColor2]
]
}];
// Create the chart
$('#container9').highcharts({
chart: {
type: 'pie',
marginTop: 50,
marginBottom: 5,
},
title: {
text: 'Total Budget - $440,000'
},
subtitle: {
text: 'Total Spent - $103,057'
},
plotOptions: {
series: {
borderWidth: 2
},
pie: {
allowPointSelect: true,
borderWidth: 3,
borderColor: 'black',
dataLabels: {
style: {
fontSize: 9,
},
distance: -1,
y: -10,
x: 10,
color: TextColor,
enabled: true,
inside: true,
verticalAlign: 'top',
format: '{point.name}<br/> {point.y}%<br/>${point.spend}'
}
},
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: {point.y:.2f}% - ${point.spend} of Total'
},
series: [{
name: new Date().getFullYear() + " National Spend ",
data: [{
name: new Date().getFullYear() + " Remaining Budget",
y: 79,
spend: '336,943',
color: colors[0],
}, {
name: "Wave 2",
y: 23,
color: colors[1],
spend: '97,693'
}, {
name: "Wave 3",
y: 3,
color: colors[1],
spend: '5,364',
}]
}]
});
});
http://jsfiddle.net/19vyugeL/3/

Categories