score:9
at first, you need to set series.turbothreshold to 0 if you have a big amount of points. this will disable the input data format check.
then, to apply column colors depending on candles, i suggest you this piece of code:
highcharts.seriestypes.column.prototype.pointattribs = (function(func) {
return function(point, state) {
var attribs = func.apply(this, arguments);
var candleseries = this.chart.series[0]; // probably you'll need to change the index
var candlepoint = candleseries.points.filter(function(p) { return p.index == point.index; })[0];
var color = (candlepoint.open < candlepoint.close) ? '#ff0000' : '#000000'; // replace with your colors
attribs.fill = state == 'hover' ? highcharts.color(color).brighten(0.3).get() : color;
return attribs;
};
}(highcharts.seriestypes.column.prototype.pointattribs));
be careful as this code will affect all of your charts that currently on page. but you can easily add some conditions to run this only on specific chart. here is a default highstock demo with the code above.
score:1
this worked perfectly for me:
$(function () {
jquery.getjson('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {
// split the data set into ohlc and volume
var volumecolor = '';
var ohlc = [],
volume = [],
datalength = data.length,
// set the allowed units for data grouping
groupingunits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < datalength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
if (i==0) {
volumecolor = '#cccccc';
} else {
if (data[i][1] >= data[i-1][1]) {
volumecolor = '#006633';
} else {
volumecolor = '#cc0033';
}
}
volume.push({
x: data[i][0], // the date
y: data[i][5],
color: volumecolor
});
}
// create the chart
$('#container').highcharts('stockchart', {
rangeselector: {
selected: 1
},
title: {
text: 'aapl historical'
},
yaxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'ohlc'
},
height: '60%',
linewidth: 2
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'volume'
},
top: '65%',
height: '35%',
offset: 0,
linewidth: 2
}],
series: [{
type: 'candlestick',
name: 'aapl',
data: ohlc,
datagrouping: {
units: groupingunits
}
}, {
type: 'column',
name: 'volume',
data: volume,
yaxis: 1,
turbothreshold: number.max_value,
datagrouping: {
enabled: false,
units: groupingunits
}
}]
});
});
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height:400px;min-width:310px"></div>
score:1
the current (highcharts 7+) solution for this, which doesn't require overriding any methods, is to simply set the color
attribute for the volume point according to the comparison between the current candlestick point's open and its close: green if <
, red if >
, and yellow if equal.
here is a minimal example.
// return a color matching the candle by comparing the open (1) and close (4)
function volumebarcolor(point) {
if (point[1] < point[4])
return 'green';
if (point[1] > point[4])
return 'red';
return 'yellow';
}
highcharts.getjson('https://www.highcharts.com/samples/data/aapl-ohlcv.json', data => {
// split the data set into ohlc and volume
const ohlc = [],
volume = [];
for (let i = 0; i < data.length; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4], // close
]);
volume.push({
x: data[i][0], // the date
y: data[i][5], // the volume
color: volumebarcolor(data[i]),
});
}
// create the chart
highcharts.stockchart('container', {
title: {
text: 'aapl historical'
},
yaxis: [{
labels: {
align: 'right',
x: -3
},
height: '60%',
}, {
labels: {
align: 'right',
x: -3
},
top: '65%',
height: '35%',
offset: 0,
}],
series: [{
type: 'candlestick',
name: 'aapl',
data: ohlc,
}, {
type: 'column',
name: 'volume',
data: volume,
yaxis: 1,
}]
});
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<div id="container"></div>
Source: stackoverflow.com
Related Query
- Change Color of Volume Columns (High/Low) in HighCharts
- How to change high and low whisker color in boxplot highcharts?
- How to change the text color in Highcharts
- Highcharts Change Bar Color Based on Value
- Highcharts dynamically change bar color based on value
- Change Highcharts Series color
- Highcharts - change background color along specific date range
- Change color of area chart programmatically in highcharts
- Highcharts column range change color for negative numbers
- Highcharts Change column color on hover
- Change Y Axis vertical line color in Highcharts
- Highcharts - how to disable color change on mouseover/hover
- change legend color high charts based on data
- Highcharts - change color of only clicked column
- How to change Highcharts xAxis label color individually?
- How to change area graph color above certain value in Highcharts
- Highcharts hide series without change legend color
- Highcharts Change Bar Background Color Based on categories value
- Highcharts, how to change hover bg color for series with multiple columns (categories)
- Highcharts --- Change sliced color on drilldown pie chart
- Highcharts change the line color if its out of the area range
- Highcharts - Change line color between points
- HighCharts - Dynamically Change Axis Title Color
- In highcharts how do I change the color of the line above the categories?
- How do I change a specific bar color in Highcharts Bar Chart?
- highcharts change rendered image source on click
- Update color of plotline label on change highcharts
- Change color in specific columns w/ multiple series
- How to change one point color on click in Highcharts
- Highcharts map doesn't change color on hover
More Query from same tag
- Drawing 3D bar charts using Highcharts through JS
- How to show unique name of every points in highCharts using angular
- High Charts Center Series Label
- Add plotbonds to Gaps defined by GapSize in Highcharts
- Angular. Highcharts. Column Chart. Positioning of Columns on X-Axis
- Change plotBands options after chart creation
- How to give color according to the percentage in Highchart - JavaScript
- How can I add internal padding to the plot area of my highchart/highstock chart?
- Issue with Dates - trying to plot MongoDB data in Highcharts via PHP
- difference between 'stackLabels' and 'dataLabels' in highcharts
- Can I use a simple path for an area chart's legend item symbol?
- Highchart point is not right in its line
- Set chart options when printing and add a footer
- How can we achieve high chart with complex json data?
- Adding a custom tooltip to a bubble chart / highchart
- Highcharts multiple charts drilldown
- How can I wrap long text labels in highchart nested groups
- In Highcharts after zoom in and zoom out some of the x-axis values are not display
- Display the value of plotband border in the highcharts
- Highcharts doesnt work on pagination next page
- how to show data json to 2 different highchart bar
- Creating HighChart pie charts as sparkline-type elements
- How do i enable scrollbar in highcharts in react
- UTC number getting displayed on xAxis with highcharts
- How to have a solid as well as dashed line in line chart highcharts
- Highcart Set From and To when I start
- Error bars with Highcharter
- Highcharts: Show x axis for missing data but ignoring certain area
- Highcharts tooltips flickering ON IE8
- Highchart bars lower half gets disappeared