Highcharts area chart curves to sharp - javascript

I just started using highcharts and I would like for my chart to display as something like the first image below, instead of the second image.
What I'd Like
What I have
Here is the code for what I have currently:
chart = new Highcharts.stockChart($('#' + tab + ' .chart')[0], {
chart: {
type: 'areaspline',
spacing: [10, 10, 15, 10],
events: {
load: function() {
setTimeout(function() {
interval = setInterval(function() {
requestData(asset, name)
}, 1000);
}, 1000);
}
},
},
rangeSelector: {
enabled: !1
},
navigator: {
enabled: false
},
title: {
text: name
},
xAxis: {
type: 'datetime',
tickPixelInterval: 100,
dateTimeLabelFormats: {
second: "%H:%M:%S",
minute: "%H:%M",
hour: "%H:%M",
day: "%d/%m",
week: "%Y<br/>%d-%m",
month: "%m-%Y",
year: "%Y"
}
//tickPixelInterval: 3600
},
yAxis: {
allowDecimals: true,
title: {
text: 'Values'
},
labels: {
style: {
backgroundColor: "#282828"
},
y: 12,
zIndex: 4,
formatter: function() {
return Highcharts.numberFormat(this.value, countDecimals(this.value))
}
},
opposite: false,
plotLines: [{
value: 0,
width: 1,
dashStyle: 'longdashdot',
color: '#2D2E2F'
}]
},
series: [{
name: 'Price',
dataGrouping: {
enabled: !1,
groupPixelWidth: 1
},
animation: !1,
threshold: null,
//color: '#2D2E2F',
data: []
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
align: 'center',
verticalAlign: 'bottom',
layout: 'horizontal'
},
yAxis: {
labels: {
align: 'left',
x: 0,
y: -5
},
title: {
text: null
}
},
subtitle: {
text: null
},
credits: {
enabled: false
}
}
}]
}
});
PS: The data from both charts are almost the same.
Thanks.

Related

Highcharts how to make the y axis series value return only 2 decimal places

I want to make the format of my y axis series to only return 2 decimal places.
I have this code:
$('#main-graph').highcharts({
chart:{
zoomType:'xy',
type: 'spline'
},
title: {
text: '',
x: -20 //center
},
xAxis: {
categories: stat_date,
crosshair:true,
},
yAxis: [
{ //0
title: {
text: 'Impressions'
},
},
{//1
title:{
text: "Clicks"
}
},
{ //2
title:{
text: "CTR"
}
},
{ //3
title:{
text: "CPM"
}
},
{ //4
title:{
text: "CPC"
}
},
{ //5 - secondary axis which is the SPEND axis
title: {
text: "Spend",
style:{
// color: Highcharts.getOptions().colors[0]
color: "#8B8B8B"
}
},
opposite:true
}],
tooltip: {
shared: true,
valueDecimals: 2
// pointFormat: "{point.y:,.2f}"
},
legend: {
layout: 'horizontal',
align: 'top',
verticalAlign: 'top',
borderWidth: 0,
floating:true,
x: 0,
y: 0
},
series: [{
name: 'Spend',
data: spend,
yAxis: 5,
type:'column'
}, {
name: 'Impressions',
data: imp,
yAxis: 0,
}, {
name: 'Clicks',
data: clicks,
yAxis: 1
},
{
name: 'CTR',
data: ctr,
yAxis: 2
}, {
name: 'CPM',
data: cpm,
yAxis: 3
}, {
name: 'CPC',
data: cpc,
yAxis: 4
}
]
});
}
I tried adding this line of code:
dataLabels: {
enabled: true,
formatter: function () {
return Highcharts.numberFormat(this.y,2);
}
}
but it isn't working.
Any ideas? your help will be grealty apprecaited!
Thanks!

Slow loading data highstock

I have trouble with performance of my highstock. All works, but time of plotting of my data is too slow, about 30 seconds. JSON is about 30000 points. Maybe problem in how I draw this data ? I already turn off animation, shadow, marks etc.
And here is my JS code:
$(function() {
Highcharts.setOptions({
global: {
useUTC: false,
timezoneOffset: - 3 * 60
}
});
function requestData() {
$.ajax({
url: 'values.php',
success: function(series) {
chart.addSeries({name: 'Temp1', data: series[0], yAxis:0}, false);
chart.addSeries({name: 'Temp2', data: series[1], yAxis:0}, false);
chart.redraw();
},
cache: false
});
}
chart = new Highcharts.StockChart({
chart: {
animation: false,
zoomType: 'xy',
renderTo: 'container',
events: {
load: requestData
}
},
title: {
text: 'Temperatures from DS18B20',
x: -20
},
plotOptions: {
spline: {
turboThreshold: 50000
}
},
rangeSelector: {
allButtonsEnabled: true,
buttons: [{
type: 'minute',
count: 10,
text: '10min'
}, {
type: 'minute',
count: 30,
text: '30min'
}, {
type: 'all',
text: 'all'
}],
buttonTheme: {
width:60
},
selected: 2
},
xAxis: {
type: 'datetime',
categories: true,
ordinal: false,
// tickInterval: 100*3600,
minTickInterval:100000,
labels: {
align: 'center',
formatter:function(){
return Highcharts.dateFormat('%H:%M:%S',this.value);
}
}
},
yAxis: {
labels: {
format: '{value}°C',
style: {
color: Highcharts.getOptions().colors[0]
}
},
title: {
text: 'Temperature',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: false
},
legend: {
enabled: true,
align: 'right',
backgroundColor: '#DBFFDB',
borderColor: 'black',
borderWidth: 2,
layout: 'vertical',
verticalAlign: 'top',
y: 200,
shadow: true
},
tooltip: {
shared: true
},
series: []
});
});

How to do a data overlap independently column in Highcharts

I would like to have something similar to the image below, but the columns representing the classes all stack together now. How do I separate them and allow them to load dynamically as well?
Also I need a legend that says green is band 1, yellow is band 2, orange is band 3 and red is band 4, how do i do that as well? My code is in the JS Fiddle page. I am not allowed to use jQuery, need to use pure JavaScript.
var options = {
chart: {
renderTo : 'container',
type: 'column'
},
title: {
text: 'Topic & Subtopic Mastery'
},
subtitle: {
text: 'Average Level-Stream Mastery vs Average Class Mastery'
},
xAxis: {
categories: topics
},
yAxis: {
min: 0,
max: 100,
title: {
text: 'Mastery'
}
},
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
shadow: true
},
tooltip: {
shared: true,
valueSuffix: ' %'
},
plotOptions: {
column: {
grouping: false,
shadow: false
}
},
series: resultsData
};
http://jsfiddle.net/kscwx139/2/
I came up with a solution you are looking for with specifying x and y axis data for level and giving appropriate width to the point.
$(function() {
var chart;
$(document).ready(function() {
var i = 0;
Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
if (i == 0) {
i++;
return Highcharts.Color(color)
.setOpacity(1)
.get('rgba');
} else {
i++;
return Highcharts.Color(color)
.setOpacity(0.5)
.get('rgba');
}
});
var colors = Highcharts.getOptions().colors;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
borderColor: null
},
title: {
text: 'Mailboxes over Quota'
},
subtitle: {
text: 'Mailbox Size in MB'
},
exporting: {
enabled: false
},
credits: {
enabled: false
},
xAxis: {
categories: ["Overall Topic", "Topic 1", "Topic 2"],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Total',
align: 'high'
},
allowDecimals: false,
},
tooltip: {
formatter: function() {
return '' +
this.series.name + ': ' + Highcharts.numberFormat(this.y, 0, '.', ',');
}
},
legend: {
enabled: true
},
credits: {
enabled: false
},
series: [{
name: 'Level',
color: colors[0],
data: [{
y: 86,
x: 0.25
}, {
y: 80,
x: 1.25
}, {
y: 95,
x: 2.25
}],
pointWidth: 80
}, {
name: '4A',
data: [90, 88, 97]
}, {
name: '4B',
data: [95, 78, 92]
}, {
name: '4C',
data: [80, 69, 84]
}]
});
});
});
To show in label inside your column you can use below code.
plotOptions: {
column: {
dataLabels: {
enabled: true,
formatter: function() {
return this.series.name;
},
y: 25,
}
}
}
You can see it in action at this JSFIddle

High charts showing the composition of count as tooltip

I have a chart as below.
http://jsfiddle.net/Mn6sB/4/
$(function () {
$('#chartContainer').highcharts({
chart: {
renderTo: 'chartContainer',
type: 'column',
marginTop:50,
spacingBottom: 5,
marginBottom: 100
},
credits: {
enabled: false
},
title: {
text: 'Product health',
},
subtitle: {
text: ''
},
xAxis: {
type: 'datetime',
minTickInterval: 24 * 3600 * 1000,
dateTimeLabelFormats: {
month: '%e %b',
year: '%b'
}
},
yAxis: {
min: 0,
max:100,
tickInterval:10,
title: {
text: 'Passrate'
},
},
legend: {
title: {
text: '<span style="font-size: 9px; color: #666; font-weight: normal">To toggle between different branches click on the branch names in the legend</span>',
style: {
fontStyle: 'italic'
}
},
layout: 'horizontal',
},
tooltip: {
formatter: function() {
return 'Branch: <b>'+ this.series.name +
'</b><br/>Date: '+ Highcharts.dateFormat('%e %b',this.x)+
'</b><br/>Pass rate: '+ this.y +'%';
}
},
plotOptions: {
spline: {
dataLabels: {
enabled: 'True'
},
enableMouseTracking: false
}
},
series: [{name: 'BranchX', data:[[Date.UTC(2013,9,3),88],[Date.UTC(2013,9,4),100],[Date.UTC(2013,9,5),100],[Date.UTC(2013,9,6),100],[Date.UTC(2013,9,7),100],[Date.UTC(2013,9,8),100],[Date.UTC(2013,9,9),100],]},{name: 'BranchY', data:[[Date.UTC(2013,9,3),75.27],[Date.UTC(2013,9,4),83.33],[Date.UTC(2013,9,5),100],[Date.UTC(2013,9,6),63.64],[Date.UTC(2013,9,7),98.31],[Date.UTC(2013,9,8),98.9],[Date.UTC(2013,9,9),64.71],]},]
});
});
This is a column graph showing the pass percentage.
I wanted to pass the numbers (passcount, total count) which were used to calculate the % vlaues, so that I can show them as tooltip. Is is possible?
yes this is possible and simple
pass the addl numbers in the series along with data
access them from tool tip as shown below from the formatter
tooltip:{
formatter: function() {
this.point.options.passCount
this.point.options.total
}
}
series:[{
data: [{
x: timestamp,
y: value,
passCount: someVlaue,
totalCount: someValue
},{
x: timestamp,
y: value,
passCount: someVlaue,
totalCount: someValue
},{
x: timestamp,
y: value,
passCount: someVlaue,
totalCount: someValue
}]
}]

Tick position on X axis

How can I limit showing ticks on X axis in Highcharts? The last one is outter of X axis:
My source:
var options = {
chart: {
renderTo: 'chart',
events: {
load: function(event) {
}
},
type: 'spline',
animation: false
},
title: {
text: ''
},
colors: [
'#499878','black'
],
rangeSelector: {
enabled: false
},
credits: {
enabled: false
},
tooltip: {
shared: true,
crosshairs: true
},
series: [{
name: 'Temperature (°C)',
type: 'spline',
tooltip : {
valueDecimals: 2,
valueSuffix: ' °C'
},
yAxis: 0,
color: '#89A54E',
data: []
},{
name: 'Wind speed (m/s)',
type: 'spline',
tooltip : {
valueDecimals: 2,
valueSuffix: ' m/s'
},
yAxis: 1,
color: '#4572A7',
data: []
},{
name: 'Humidity (%)',
type: 'spline',
tooltip : {
valueDecimals: 2,
valueSuffix: ' %'
},
yAxis: 2,
color: '#910000',
data: []
},{
name: 'Wind direction (°)',
type: 'spline',
tooltip : {
valueDecimals: 2,
valueSuffix: ' °'
},
yAxis: 3,
color: '#000000',
dashStyle: 'shortdot',
data: []
}],
xAxis: {
type: 'datetime',
tickInterval: 10000,
min: 0,
max: 0
},
yAxis: [{
labels: {
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
},
gridLineWidth: 1,
opposite: true
},{
labels: {
formatter: function() {
return this.value +' m/s';
},
style: {
color: '#4572A7'
}
},
title: {
text: 'Wind speed',
style: {
color: '#4572A7'
}
},
gridLineWidth: 1,
opposite: false,
min: 0
},{
labels: {
formatter: function() {
return this.value +' %';
},
style: {
color: '#910000'
}
},
title: {
text: 'Humidity',
style: {
color: '#910000'
}
},
gridLineWidth: 1,
opposite: true
},{
labels: {
formatter: function() {
return this.value +' °';
},
style: {
color: '#000000'
}
},
title: {
text: 'Wind direction',
style: {
color: '#000000'
}
},
opposite: false,
reversed: true,
min: 0,
max: 360,
minorGridLineDashStyle: 'longdash',
minorTickInterval: 'auto',
minorTickWidth: 0,
tickInterval: 90
}],
plotOptions: {
spline: {
lineWidth: 3,
states: {
hover: {
lineWidth: 5
}
},
marker: {
enabled: false
}
},
scatter: {
marker: {
enabled: true
}
}
}
};
I found out it's matter of oveflow: 'justify'. jsfiddle
What happens if you use 'spacingRight' (http://api.highcharts.com/highcharts#chart.spacingRight) as below:
chart: {
renderTo: 'chart',
events: {
load: function(event) {
}
},
type: 'spline',
animation: false,
spacingRight: 100 // you may change this for testing...
},

Categories

Resources