Adding series markers to highcharts area chart - json

I am attempting to create an area chart based on a timeline and everything works until I add a series marker. I have tried a few different patterns but can't get the chart to render with a marker.
Attempt 1: replace [x,y] item with [{x,y,marker}] object
data: [[1384219800000,2],
[{x:1384269600000,y:7,marker:{symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"}}],
[1384279900000,1]]
Attempt 2: replace [x,y] item with [x, {y,marker}] object
data: [[1384219800000,2],
[1384269600000, {y:7,marker:{symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"}}],
[1384279900000,1]]
This is the working area chart without the marker. This renders fine until I try to add the marker notation
$(function () {
$('#container').highcharts({
chart: {
type: 'area'
},
title: {
style: {
display: 'none'
}
},
subtitle: {
style: {
display: 'none'
}
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: ''
},
min: 0,
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null
},
legend: {
borderWidth: 0,
enabled: true,
align: 'right',
verticalAlign: 'top',
x: -5,
y: -15,
floating: true
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 0,
lineColor: '#666666',
enabled: false
}
}
},
series:
[{
name: 'Items',
color: '#3399CC',
data: [[1384219800000,2],[1384269600000,7],[1384279900000,1]]
}],
navigation:
{
menuItemStyle: {
fontSize: '10px'
}
},
navigator: {
enabled: true
},
scrollbar: {
enabled: false
},
rangeSelector: {
enabled: false
}
});
});

Your first syntax is close to correct, except you need to drop the [] around the {} and enable the marker for that specific point:
data: [
[1384219800000,2],
{
x:1384269600000,
y:7,
marker:{
enabled: true,
symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"
}
},
[1384279900000,1]
]
Fiddle here.

Related

ApexCharts impossible to set the logarithmic option in javascript

I use a DrawChart method and try to set the logarithmic option to the yaxis to true without success:
The datas (for the series) contains :
"[{type:"bar",data:[1.19576304413727E-08,1.30322021618667E-07]}]"
I try to place the logarithmic : true option in several place without succes. For me it must be placed into the yaxis part.
Thank you in advance
chart.updateOptions({
series: datas,
chart: {
toolbar: {
show: showToolbar
},
animations: {
enabled: false
},
type: 'bar'
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '50%',
endingShape: 'rounded'
}
},
stroke: {
show: true,
width: 2,
colors: ['transparent']
},
xaxis: {
title: {
text: 'Masse'
},
categories: categories//,
//tickAmount: 10
},
yaxis: {
labels: {
formatter: function (value) {
//var ex;
return value.toExponential();
//return value;
}
},
title: {
text: unit
},
tickAmount: 10
//min: min,
//max: max,
//decimalsInFloat: 3
},
grid: {
padding: {
left: 50,
right: 50
}
},
legend: {
show: true,
position: 'bottom',
horizontalAlign: 'left',
showForSingleSeries: true,
showForNullSeries: true,
showForZeroSeries: true
},
})
I found the problem !
When you have log values really small (like 5.32E-9), the logarithm option doesnt work if you try to display the legend thrue a JS function.
So multiply by 1E10 the divide into the JS function (where you display the legend) by 1E10.

How to update just data attribute under series in highcharts with json?

I am currently new on this and I am looking for the easiest way to load, from a json file, the data for different series, but keeping other attributes of each serie as they are in the javascript.
So as shown in the below code, there are two series "Carbon" and "Add". The JSON file will just have the data for both series:
[
{"data":[70]},
{"data":[-30]}
]
The script that I have is as the one below:
$(function () {
$(document).ready(function(){
$.getJSON('carbonData.json', function(data) {
var carbon = new Highcharts.chart({
chart: {
renderTo: 'Carbon',
marginLeft:-30,
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false,
type: 'bar'
},
credits: {
enabled: false
},
title: {
text: ''
},
xAxis: {
labels:{enabled:false},
lineWidth: 0,
minorTickLength: 0,
tickLength: 0,
gridLineWidth: 0,
minorGridLineWidth: 0,
categories: ['']
},
yAxis: {
labels:{
enabled: false,
},
plotLines: [{
value: -30,
label: {
text: 'Target<br/>30 kg/t',
style:{fontSize: "10px"},
rotation:0,
align: 'center',
x: 0,
y:25
}
},{
value: 70,
label: {
text: 'Target<br/>70 kg/t',
style:{fontSize: "10px"},
rotation:0,
align: 'center',
x: 0,
y:25
}
}],
gridLineWidth: 0,
minorGridLineWidth: 0,
min: -45,
max:75,
title: {
text: ''
}
},
colors:['#4572A7','#AA4643'],
legend: {
enabled: false,
},
tooltip: {
enabled:false,
},
plotOptions: {
series: {
stacking: 'normal',
}
},
series: [{
name: 'Carbon',
data: [70],
dataLabels: {
enabled:true,
x: 16,
format: '{series.name}<br/>{point.y} kg/t',
style: {
align: 'center',
fontSize: "10px",
fontWeight:'normal',
textOutline: false,
fontFamily: 'sans-serif',
'text-anchor': 'middle'
}
}
}, {
name: 'Add',
data: [-30],
dataLabels: {
enabled:true,
x:13,
formatter: function() {
return this.series.name+'<br/>'+Math.abs(this.y)+' kg/t';
},
style: {
color: 'white',
align: 'center',
fontSize: "10px",
fontWeight:'normal',
textOutline: false,
fontFamily: 'sans-serif',
'text-anchor': 'middle'
}
}
}]
});
});
});
});
So I am looking to map the information of the JSON file to each of the series correspondingly.
Thanks.
Use setData method:
var data = [{
"data": [70]
},
{
"data": [-30]
}
]
var chart = Highcharts.chart('container', {
series: [{
color: 'red',
data: []
}, {
color: 'blue',
data: []
}]
});
document.getElementById("data").addEventListener('click', function() {
data.forEach(function(el, i) {
chart.series[i].setData(el.data);
});
});
Live demo: http://jsfiddle.net/BlackLabel/z5aLvgxq/
API: https://api.highcharts.com/class-reference/Highcharts.Series#setData

Highcharts load date values in X axis

I have a Highcharts chart which gets it's data from a JSON request.
function slowips(target){
var options = {
chart: {
renderTo: target,
type: 'spline',
borderColor: '#0072C6',
borderWidth: 3
},
title: {
text: 'Responsetime'
},
subtitle: {
text: 'Nr.1 is slowest'
},
legend: {
enabled: true,
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
yAxis: {
title: {
text: 'Milliseconds'
},
min: 0
},
exporting: {
enabled: false
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%Y'
},
labels: {
enabled: true,
},
minorTickLength: 0,
tickLength: 0,
},
plotOptions: {
spline: {
animation: false,
enableMouseTracking: false,
marker: {
enabled: false
}
}
},
series: [{}]
};
$.getJSON('graphs/test.php', function(data) {
options.series = data;
var chart = new Highcharts.Chart(options);
});
}
slowips();
This is an example JSON input:
[ { "name":"sddf", "data": [ ["2013-02-01 00:01:00", 2 ], ["2013-02-02 00:02:00", 2.55 ] ] } ]
Also tried:
[ { "name":"sddf", "data": [ [Date.UTC(12, 3, 09), 2 ], [Date.UTC(12, 3, 10), 2.55 ] ] } ]
The first JSON example renders a chart, but with incorrect X axis data. The second JSON does not render the chart.
Please help out!
You need to use timestamps, so when you load first JSON, then you need to parse it by Date.UTC() / Data.parse(), but functions cannot be places in json inside (as you have in second example).

highcharts correct json input

UPDTAED:Now with the below code, the json is parsing correctly ,
But the columns are not displayed on the initial load, if i put the cursor over i can see the tooltip displaying the series name and value. However, if i re-size the browser window the columns appear. i tried adding chart.redraw(); after the updatedChart(); but it dosent help my div is as below
<div id="container" style="min-width: 400px ; height: 650; margin:0 auto"></div>
Any ideas please? Also, i cannot re-produce this problem on jsfiddle and have tested this on safari,chrome and firefox (all showing this strange behavior)
var chart;
options = {
chart: {
renderTo: 'container',
type: 'column',
},
title: {
text: 'Some title'
},
subtitle: {
text: 'subtitle'
},
xAxis: {
categories: [],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'y-Axis',
align: 'high'
}
},
tooltip: {
formatter: function() {
return '' + this.series.name + ': ' + this.y + ' ';
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -100,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series:
[]
};
$(document).ready(function() {
chart= new Highcharts.Chart(options)
console.log("calling update chart");
updateChart();
});
function updateChart() {
$.ajax({
type: "GET",
url: "test.json",
async: false,
dataType: "json",
success: function(data){
console.log(data);
var i=0;
$.each(data,function(index,item){
console.log(data.Chart1[index]);
console.log("i value is "+i);
chart.addSeries(data.Chart1[index]);
i++;
});
}
});
}
}
my json input file is below
[
{
name: 'name1',
y: [32.6,16.6,1.5]
}, {
name: 'name2',
y: [6.7,0.2,0.6]
}, {
name: 'name3',
y: [1,3.7,0.7]
}, {
name: 'name4',
y: [20.3,8.8,9.5]
},{
name: 'name5',
y: [21.5,10,7.2]
}, {
name: 'name6',
y: [1.4,1.8,3.7]
}, {
name: 'name7',
y: [8.1,0,0]
}, {
name: 'name8',
y: [28.9,8.9,6.6]
}
]
Edited:
var chart = null,
options = {
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Some title'
},
subtitle: {
text: 'subtitle'
},
xAxis: {
categories: [],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'y-Axis',
align: 'high'
}
},
tooltip: {
formatter: function() {
return '' + this.series.name + ': ' + this.y + ' ';
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -100,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: []
};
$(document).ready(function() {
updateChart();
});
function updateChart() {
$.getJSON('test.json', function(data) {
// check if the chart's already rendered
if (!chart) {
// if it's not rendered you have to update your options
options.series = data;
chart = new Highcharts.Chart(options);
} else {
// if it's rendered you have to update dinamically
jQuery.each(data, function(seriePos, serie) {
chart.series[seriePos].setData(serie, false);
});
chart.redraw();
}
});
}
Fiddle: LINK

how to change color of scencha bar charts?

I am new to Scencha. I am using a bar chart example of Scencha charts. I could not change colors of the charts, it comes by default. Where can I change the color in the following code? How can I transpose bar chart also, it comes as left to right?
var barChart = new Ext.chart.Panel({
title: 'Bar Chart',
layout: 'fit',
iconCls: 'bar',
dockedItems: {
iconCls: 'shuffle',
iconMask: true,
ui: 'plain',
handler: onRefreshTap1
},
items: [{
xtype: 'chart',
cls: 'barcombo1',
theme: 'Demo',
store: store1,
animate: true,
shadow: false,
legend: {
position: {
portrait: 'right',
landscape: 'top'
}
},
interactions: [
'reset',
'togglestacked',
{
type: 'panzoom',
axes: {
left: {}
}
},
{
type: 'iteminfo',
gesture: 'taphold',
panel: {
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
title: 'Details'
}],
html: 'Testing'
},
listeners: {
'show': function(me, item, panel) {
var storeItem = item.storeItem;
// panel.update('<ul><li><b>Month:</b> ' + storeItem.get('name') + '</li><li><b>Value: </b> ' + storeItem.get('2008') + '</li></ul>');
}
}
},
{
type: 'itemcompare',
offset: {
x: -10
},
listeners: {
'show': function(interaction) {
var val1 = interaction.item1.value,
val2 = interaction.item2.value;
barChart.descriptionPanel.setTitle('Trend from ' + val1[0] + ' to ' + val2[0] + ' : ' + Math.round((val2[1] - val1[1]) / val1[1] * 100) + '%');
barChart.headerPanel.setActiveItem(1, {
type: 'slide',
direction: 'left'
});
},
'hide': function() {
barChart.headerPanel.setActiveItem(0, {
type: 'slide',
direction: 'right'
});
}
}
}],
axes: [{
type: 'Numeric',
position: 'bottom',
fields: ['TY', 'LY'],
label: {
renderer: function(v) {
return v.toFixed(0);
}
},
title: 'Hits (Billions)',
minimum: 0
},
{
type: 'Category',
position: 'left',
fields: ['name'],
title: 'Weeks'
}],
series: [{
type: 'bar',
label: {
Field:'TY'
},
xField: 'name',
yField: ['TY', 'LY'],
axis: 'bottom',
highlight: true,
showInLegend: true
}]
}]
});
Change the type 'bar' to 'column' in the following snippet:
series: [{
type: 'bar',
label: {
Field:'TY'
},