HighStocks Tooltip is not working properly - javascript
I've simply used the out-of-the-box example from highcharts:
$(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function (data) {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
inputEnabled: $('#container').width() > 480,
selected : 1
},
title : {
text : 'Sample Stock Price'
},
series : [{
name : 'Sample Stock Price',
data : data,
type : 'areaspline',
threshold : null,
tooltip : {
valueDecimals : 0
},
fillColor : {
linearGradient : {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops : [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
}
}]
});
});
});
I replaced the "data" variable with programmatically populated values:
[[1409788800000,14215],[1409702400000,14332],[1409616000000,14569],[1409529600000,14898],[1409443200000,15144],[1409356800000,15335],[1409270400000,15531],[1409184000000,15647],[1409097600000,15454],[1409011200000,15143],[1408924800000,15179],[1408838400000,15537],[1408752000000,15784],[1408665600000,15844],[1408579200000,15998],[1408492800000,15678],[1408406400000,15148],[1408320000000,15106],[1408233600000,15327],[1408147200000,15642],[1408060800000,15781],[1407974400000,15686],[1407888000000,15349],[1407801600000,14830],[1407715200000,14770],[1407628800000,14948],[1407542400000,15217],[1407456000000,15495],[1407369600000,15414],[1407283200000,14976],[1407196800000,14494],[1407110400000,14572],[1407024000000,14979],[1406937600000,15541],[1406851200000,15905],[1406764800000,16076],[1406678400000,15997],[1406592000000,15698],[1406505600000,15777],[1406419200000,16012],[1406332800000,16239],[1406246400000,16367],[1406160000000,16393],[1406073600000,16131],[1405987200000,15862],[1405900800000,16002],[1405814400000,16206],[1405728000000,16478],[1405641600000,16683],[1405555200000,16803],[1405468800000,16666],[1405382400000,16625],[1405296000000,16992],[1405209600000,17075],[1405123200000,17127],[1405036800000,17262],[1404950400000,17351],[1404864000000,17154],[1404777600000,16943],[1404691200000,16656],[1404604800000,16718],[1404518400000,16943],[1404432000000,17197],[1404345600000,17379],[1404259200000,17505],[1404172800000,17255],[1404086400000,17191],[1404000000000,17299],[1403913600000,17468],[1403827200000,17664],[1403740800000,17741],[1403654400000,17563],[1403568000000,17371],[1403481600000,17049],[1403395200000,17144],[1403308800000,17320],[1403222400000,17492],[1403136000000,17598],[1403049600000,17670],[1402963200000,17187],[1402876800000,17157],[1402790400000,17226],[1402704000000,17425],[1402617600000,17625],[1402531200000,17746],[1402444800000,17465],[1402358400000,16844],[1402272000000,16937],[1402185600000,17043],[1402099200000,17684],[1402012800000,18140],[1401926400000,18304],[1401840000000,18104],[1401753600000,17486],[1401667200000,16666],[1401580800000,15873],[1401494400000,15528],[1401408000000,15495],[1401321600000,15474],[1401235200000,15391],[1401148800000,15380],[1401062400000,15421],[1400976000000,15352],[1400889600000,15312],[1400803200000,15248],[1400716800000,15258],[1400630400000,15323],[1400544000000,15437],[1400457600000,15492],[1400371200000,15427],[1400284800000,15429],[1400198400000,15492],[1400112000000,15473],[1400025600000,15439],[1399939200000,15400],[1399852800000,15373],[1399766400000,15373],[1399680000000,15621],[1399593600000,15645],[1399507200000,15692],[1399420800000,15666],[1399334400000,15583],[1399248000000,15533],[1399161600000,15667],[1399075200000,15514],[1398988800000,15478],[1398902400000,15389],[1398816000000,15414],[1398729600000,15161],[1398643200000,15022],[1398556800000,15305],[1398470400000,15575],[1398384000000,15608],[1398297600000,15514],[1398211200000,15339],[1398124800000,15177],[1398038400000,15352],[1397952000000,15743],[1397865600000,15983],[1397779200000,16090],[1397692800000,16069],[1397606400000,15855],[1397520000000,15761],[1397433600000,15556],[1397347200000,15737],[1397260800000,15889],[1397174400000,15961],[1397088000000,15950],[1397001600000,15853],[1396915200000,15699],[1396828800000,15906],[1396742400000,16205],[1396656000000,16394],[1396569600000,16303],[1396483200000,16228],[1396396800000,16256],[1396310400000,16065],[1396224000000,15905],[1396137600000,15863],[1396051200000,15766],[1395964800000,15646],[1395878400000,15585],[1395792000000,15583],[1395705600000,15605],[1395619200000,15590],[1395532800000,15643],[1395446400000,15609],[1395360000000,15593],[1395273600000,15550]]
The tooltip is no longer working properly, and the graph does not appear for any of the button ranges except "All"
Here is a JSFiddle of what I have:
http://jsfiddle.net/9Lwp0dw6/1/
Any help is greatly appreciated - Thank You!
In the debugger, highcharts is throwing this error - highcharts.com/errors/15. It is basically saying it wants sorted data. You will have to sort the array
Related
highchart stock : graph disappear when containing weekend data point
Recently I met a very strange problem when using highchart stock(highstock.js). I load some data points which containing Saturday data point. When application runs, at first it looks like this: No graph appear, only the navigator and the time axis label. However, when I drag the navigator to the full size, the graph appear, but the x-axis time label disappear, it looks like this: I have built a plunker here: graph disappear when met weekend data point link some main configuration codes are as below: scrollbar : { barBackgroundColor : 'gray', barBorderRadius : 7, barBorderWidth : 0, buttonBackgroundColor : 'gray', buttonBorderWidth : 0, buttonArrowColor : 'yellow', buttonBorderRadius : 7, rifleColor : 'yellow', trackBackgroundColor : 'white', trackBorderWidth : 1, trackBorderColor : 'silver', trackBorderRadius : 7, // enabled: false, liveRedraw : false }, navigator : { xAxis : { labels : { formatter : function(e) { console.log("value : " + this.value); console.log("value :" + typeof this.value) return Highcharts.dateFormat('%Y-%m-%d', this.value); } } }, handles : { backgroundColor : '#808080' }, //margin : -10 }, xAxis : { type : 'datetime', tickLength : 0 }, Can anyone tell me why?
I have found the true reason. It is not because the weekend data point, but because the data is not sorted in time ascending order.
Highcharts legend is cutting off
I am trying to plot a heatmap using highcharts api using the following chart options: { chart : { renderTo : 'chartContainer', type : 'heatmap' }, title : { text : "abcd" }, xAxis : { categories : []//categories, tickWidth : 0, title : { text : "Months" }, }, yAxis : { categories : []//categories, lineWidth : 1, title : { text : "xyz" } }, colorAxis : { min : minValue, max : maxValue, gridLineWidth : 2, marker : null, tickWidth : 0, tickInterval : tickInterval }, legend : { align : 'right', layout : 'vertical', verticalAlign: 'middle', symbolHeight : 250 }, tooltip : { enabled : false }, navigation : { buttonOptions : { verticalAlign : 'top', y : -10 } }, series : [] //series data }; But legend is somehow cutting at the top. Please check the following snapshot: Chart Screenshot I tried the different combinations of legend options mentioned in http://api.highcharts.com/highcharts#legend Also, tried increasing the height of the chart container. Still, the legend is still cutting at the top. Any help/suggestions?
Finally, the issue got resolved. It was occurring because of the 'symbolHeight' property of the legend. I reduced it to 150 and the legend stopped cutting off.
for me, the answer was to increase the legend:itemMarginTop to 20;
For me, it worked by slightly reducing the font-size. legend:{ itemStyle: { fontSize: "10px" }, } For this, I also had to change the symbolHeight to adjust it according to my font size. Font size defaults to 12px. Ref: https://api.highcharts.com/highcharts/legend.itemStyle Hope this helps. Peace.
How to add gradient colors above chart line?
Here I am getting gradient color at top of the chart area by reversing y-Axis. check the image below . yAxis: { reversed: true, showFirstLabel: false, showLastLabel: true } I don't want to reverse the y-Axis, if i am reversing the y-Axis my chart also reversed. I want the gradient color which is in top of the chart line without using this Reversed Y-axis. Suggest me to if any other options in highcharts. Could any one help me to solve this. I am working live random data. In this case only the area traveled by the data should get the gradient color , empty space other than the data in chat shouldn't get gradient color. As per #DaMaxContent answer , the output will act like below image. I don't want that gradient which filled in other area of the chart data. Could you please help me to resolve this.
The break down: You can use gridZindex and backgroundColor/fillColor properties to produce the desired effect. Only issue is that the grid has to be displayed over graph. The solution: DEMO The code behind it: chart: { type: 'area', backgroundColor: { //<<--that is what you are using as fill color linearGradient : { x1: 0, y1: 1, x2: 0, y2: 0 }, stops : [ [0, Highcharts.getOptions().colors[0]], [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] ] } }, rangeSelector: { selected: 1 }, title: { text: 'AAPL Stock Price' }, yAxis: { reversed: false, showFirstLabel: false, showLastLabel: true, gridZIndex: 1000 //<<--grid Z index is used to display grid lines over the graph instead of under it }, series: [{ name: 'AAPL Stock Price', data: data, threshold: null, fillColor : "#fff", //<<--fill color under the line to simulate effect zIndex: 1000, tooltip: { valueDecimals: 2 } }] If you wish to get rid of the marginal color areas, you can get rid off the graphs margin with chart: { [... ,] margin: 0 [, ...] } and then use the container's padding as the graph margin. More info: highcharts styling guides: http://www.highcharts.com/docs/chart-design-and-style/design-and-style grid Z index: http://www.java2s.com/Tutorials/highcharts/Example/Axis/Set_grid_line_z_index.htm background color: Changing HighCharts background color? (alternative to bg color) plot background color (bg color of *main plot only): http://api.highcharts.com/highcharts#chart.plotBackgroundColor *range selector areas will not be affected
To meet the various criteria you have asked for, I would accomplish this by creating a dummy series to create the gradient effect. Example Result: In this scenario, you will need to pre-process your data, and you will need to assign a max value for the y axis explicitly. Example Code: var max = 0; var data1 = [...your data array...]; var data2 = []; $.each(data1, function(i,point) { max = point > max ? point : max; }); max = Math.ceil(max * 1.1); $.each(data1, function(i,point) { data2.push((max - point)); }); You will then need to assign that max value as your yAxis max proeprty, and you may need to either set endOnTick: false, or otherwise account for the max resolving with your tickInterval: yAxis: { max:max, endOnTick:false } Then for your dummy series, define the background color gradient. We'll also set the showInLegend and enableMouseTracking properties to false so that it doesn't show in the legend or tooltip: { data: data2, showInLegend:false, enableMouseTracking:false, fillColor : { linearGradient : { x1: 0, y1: 1, x2: 0, y2: 0 }, stops : [ [0, Highcharts.getOptions().colors[0]], [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] ] } Fiddle Example: http://jsfiddle.net/jlbriggs/mcp3trmk/ This ensures that the gradient will always match the data, as requested.
As you can see from this js fiddle you have to add this: series: [{ name: 'AAPL Stock Price', data: data, threshold: null, fillColor : { linearGradient : { x1: 0, y1: 1, x2: 0, y2: 0 }, stops : [ [0, Highcharts.getOptions().colors[0]], [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] ] }, tooltip: { valueDecimals: 2 } }] See the documentation for further information
Set Color for Pie Chart using HighChart + JSON data
I am generating a pie chart from data stored in JSON format. I am trying to change color according to the JSON value. Ex : if value # json[0]['data'][0][0] = "FAILED" //setColor(RED). I was able to set the color for column stack charts using options.series.color, however when I tried to use this option with pie chart its converting data into series and unable to render the chart on a container. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> function getData(id) { $.getJSON("pie.php", { id: id }, function(json) { option.series = json; chart = new Highcharts.chart(options); }); } </script> can we set the color in getData function only before calling 'chart' or do i need to use Highcharts.setOptions() and define the color codes.
The better option is to create series based on your json data. This is how you can do to specify color based on data. var serie = { data: [] }; var series = [serie]; jQuery.each(jsonData, function(index, pointData) { var point = { name: pointName, y: pointData.Value, color: pointData.Value == 'FAILED' ? 'ff0000' : '00ff00', serverData: pointData }; serie.data.push(point); }); chart.series = series; OR Have a look at this easier version JSFiddle $( document ).ready(function() { var data = [{ "name": "Tokyo", "data": 3.0 }, { "name": "NewYork", "data": 2.0 }, { "name": "Berlin", "data": 3.5 }, { "name": "London", "data": 1.5 }]; // Highcharts requires the y option to be set $.each(data, function (i, point) { point.y = point.data; point.color = parseFloat(point.data) > 3 ? '#ff0000' : '#00ff00'; }); var chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'pie' }, series: [{ data: data }] }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <div id="container" style="height: 300px"></div>
we can set highchart custom color by setOption function which is as Highcharts.setOptions({ colors: ['#F64A16', '#0ECDFD',] }); It sets color to my pie chart. Another solution for dynamic 3D color Actually this customization for theme selection Here it is 3 colors sets to color variable var colors = Highcharts.getOptions().colors; $.each(colors, function(i, color) { colors[i] = { linearGradient: { x1: 0, y1: 0, x2: 1, y2: 0 }, stops: [ [0, '#0ECDFD'], [0.3, '#F64A16'], [1, color] ] }; }); & assign directly in series { type : 'column', name : 'bug', data : [], color : colors, pointWidth : 28, }
HighChart flags Data load issues
I am working on drawing graphs from our data. There is no problem on drawing graph basically. The only problem is that the flags information is not loaded and located on the graph lines. Let me give you the issues on it. Data cannot be brought to the graph if it has over 900 numbers of items. One data might have more than 4000 items. Instead using one big data, I tried to spilt one data into small pieces of data. Each piece of data has 800 items, and they are intended being loaded on the graph sequentially. However, this process was not easily done well. Sometime the graph module cannot load every piece exactly. Moreover, this process take much time than using one data. I wonder whether an appropriate way to load flag data which contains many items exits or not. $(function() { var report_data; $.ajax({ type: "post", url:"/apps.chart/chart.reportShort", data:"callback=?&report_type=CO&business_code=005930", dataType:"json", success:function(report){ report_data = report; } }); $.getJSON('/apps.chart/chart.chartList?callback=?&report_type=CO&business_code=005930', function(data) { // Create the chart $('#chartView').highcharts('StockChart', { chart: { plotBorderColor: '#346691', plotBorderWidth: 2, height: 600 }, rangeSelector : { inputEnabled: $('#chartView').width() > 400, selected : 1 }, title : { text : 'SK' }, tooltip: { type: 'datetime', dateTimeLabelFormats: { day: '%Y년 %m월 %d일' }, style: { width: '300px' }, valueDecimals: 0 }, xAxis: { type: 'datetime', dateTimeLabelFormats: { day: '%m.%d', week: '%m.%d', month: '%Y.%m', year: '%Y' } }, yAxis : { labels : { formatter : function() { var n = this.value; var reg = /(^[+-]?\d+)(\d{3})/; n += ''; while (reg.test(n)) n = n.replace(reg, '$1' + ',' + '$2'); return n; }, align : 'left', x : 5, y : 2 }, maxPadding: 0.2, minPadding: 0, minorTickInterval: 'auto', title : { text : '금액(원)', } }, series : [{ name : '종가', data : data, id : 'dataseries', marker : { enabled : true, radius : 3 }, shadow : true, tooltip : { valueDecimals : 0 } } // the event marker flags ,{ type : 'flags', data : report_data, style: { cursor: 'hand' }, onSeries : 'dataseries', shape : 'circlepin', width : 15, height : 15, color : '#121212' } ] }); }); });
Probably the problem is that you call two ajax asynchronously, so I advice you to next ajax insiae first callback and then initialise chart.