Highchart formatter issues - javascript

I want to create a highchart. I have 3 arrays. First array contains dates, second array contains float values and last array contains integer values.
I set tooltip setting decimal values doesnt work. Also I want to add pB series to highchart. How can I do?
First array
dates=["201401", "201401", "201401", "201402", "201402", "201402"];
Second array
krc=["2.22", "3.67", "3.03", "2.22", "3.03", "3.67"];
Last array
pB=["2", "4", "3", "2", "3", "4"];
$('#dvzKr').highcharts({
chart: {
type: 'spline'
},
title: {
text:dates[0]+" / "+ dates[max_y] +" Dates",
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: dates
},
yAxis: {
min:1,
title: {
text: 'Krc Values'
},
plotLines: [{
value: 0,
width: 1,
color: '#000000'
}]
},
tooltip: {
valueDecimals: 2
},
series: [{
name: 'Krc Values',
color: '#F7A35C',
data: krc
}]
});

You have array on strings rather than number so you have to convert them to numbers
//Second array
var krc = ["2.22", "3.67", "3.03", "2.22", "3.03", "3.67"].map(Number);
//Last array
var pB = ["2", "4", "3", "2", "3", "4"].map(Number);
You can add pB series to highchart as
series: [{
name: 'Krc Values',
color: '#F7A35C',
data: krc
}, {
name: 'pB Values',
color: '#A7A35C',
data: pB
}]
Fiddle demo

Related

How to add multiple text on xaxis

I am struggling with adding multiple texts on the x-axis. Most of the things like giving name field in x-axis don't work with Sankey diagram.
Problem: I need to add 2 texts just below my x-axis on my Sankey diagram. The first text just below and center of the blue bar. The second text I need just below gray bar but it should be in the same line with respect to first text
Here is my code
Highcharts.chart('container', {
title: {
text: ''
},
xAxis: {
type: 'football league'
},
series: [{
keys: ['from', 'to', 'weight'],
data: [
['Football', 'Messi', 20 ],
['Football', 'ronaldo', 3 ],
//['Challenged', 'Terminated', 0 ],
['Football', 'sachin', 1 ],
['Messi', 'sehqag', 12 ],
//['Instituted', ' Terminated', 0 ],
['Messi', 'ashwin', 6 ],
['Messi', ' ramesg', 2 ],
],
type: 'sankey',
name: 'Sankey demo series'
}]
});
JSFiddle: https://jsfiddle.net/anikettiwari/kLzv8sp0/26/
To add text to the chart, you can use annotations module or Highcharts.SVGRenderer:
annotations: [{
labels: [{
text: 'annotations',
point: {
x: 100,
y: 380
}
}, {
text: 'annotations2',
point: {
x: 400,
y: 380
}
}]
}]
Live demo: https://jsfiddle.net/BlackLabel/odc4jsku/
API: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#text
Docs: https://www.highcharts.com/docs/advanced-chart-features/annotations-module
I achieved this by below code
chart: {
showAxes: true
},
xAxis: {
categories: ['ANIKET','SHivam'],
labels: {
style: {
color: '#000000'
}
}
},
yAxis: {
title: '',
labels: {
formatter: function() {
return '';
},
style: {
color: '#4572A7'
}
}
},
For the y-axis it was giving me default label so for removing it I wrote the above yaxis code

last label in x axis with datetime format not coming in highchart

I have used highchart to plot chart. In which x axis has date time and y axis has numbers. but the problem is that last label on x-axis is not coming. So if you can help please help me to do it.
if i use endontick and show last label it adds 00:00:04 in end
Here is the link to jsfiddle of same code is like a 4k line code
https://goo.gl/bbwZRC
<script>
$(function () {
$('#trend1307').highcharts({
chart:{
defaultSeriesType: 'line',
events: {
load: function () {
var car = this;
$(car.series).each(function (i, serie) {
$('<li><span style="background-color: ' + serie.color + ';"></span>' + serie.name + '</li>').click(function () {
serie.visible ? serie.hide() : serie.show();
}).appendTo('#legend1307');
});
}
}
},
legend: {
enabled: false
},
title:false,
borderWidth: 1,
xAxis: {
type:'time',
title: {
text: 'Time (HH:MM:SS)'
},
categories: [ Date.UTC(2016,01,25,21,00,00)
, Date.UTC(2016,01,25,21,05,00)
, Date.UTC(2016,01,25,21,10,00)
, Date.UTC(2016,01,25,21,15,00)
, Date.UTC(2016,01,25,21,20,00)
, Date.UTC(2016,01,25,21,25,00)
, Date.UTC(2016,01,25,21,30,00)
, Date.UTC(2016,01,26,19,05,00)
, Date.UTC(2016,01,26,19,10,00)
, Date.UTC(2016,01,26,19,15,00)
, Date.UTC(2016,01,26,19,20,00)
, Date.UTC(2016,01,26,19,25,00)
, Date.UTC(2016,01,26,19,30,00)
, Date.UTC(2016,01,26,19,35,00)
, Date.UTC(2016,01,26,19,40,00)
, Date.UTC(2016,01,26,19,45,00)
, Date.UTC(2016,01,26,19,50,00)
, Date.UTC(2016,01,26,19,55,00)
, Date.UTC(2016,01,26,20,00,00)
, Date.UTC(2016,01,26,20,05,00)
, Date.UTC(2016,01,26,20,10,00)
, Date.UTC(2016,01,26,20,15,00)
, Date.UTC(2016,01,26,20,20,00)
, Date.UTC(2016,01,26,20,25,00)
, Date.UTC(2016,01,26,20,30,00)
, Date.UTC(2016,01,26,20,35,00)
, Date.UTC(2016,01,26,20,40,00)
, Date.UTC(2016,01,26,20,45,00)
, Date.UTC(2016,01,26,20,50,00)
, Date.UTC(2016,01,26,20,55,00)
, Date.UTC(2016,01,26,21,00,00)
],
type: 'datetime',
showLastLabel:true,
labels: {
format: '{value:%H:%M:%S}',
rotation: - 90,
style: {
fontSize: '9px',
color:"black"
}
},
},
yAxis: {
plotLines: [ , {
value: 25,
color: 'red',
dashStyle: 'shortdash',
width: 2,
label: {
text: 'Maximum Temperature 25°C',
style: {
fontSize: '9px',
color:"black"
}
},
zIndex: 3
}],
max:26,
labels: {
format: '{value:.1f}'
},
tickInterval: 1,
title: {
text: 'Temperature (°C)'
},
},
tooltip: {
valueSuffix: '°C'
},
series: [
{
name: 'T-464',
lineWidth:.75,
data: [
19.3,19.6,19.4,19.2,19.4,19.5,19.3,19.3,19.3,19.2,19.5,19.5,19.4,19.1,18.8,18.6,19,18.8,18.7,18.6,18.7,18.6,18.6,18.5,18.4,18.4,18.5,18.4,18.4,18.3,18.2,18.2,18.3,18.4,18.2,18.1,18.1,18.2,18.2,18,18,18.1,18.2,18.3,18.2,18.1,18.1,17.9,18,18.3,18.1,18.2,18.3,18.3,18.4,18.4,18.3,18.3,18.3,18.4,18.4,18.4,18.4,18.1,18.1,18.2,18.2,18.4,18.6,18.4,18.4,18.7,18.7,18.6,18.6,18.6,18.5,18.4,18.5,18.6,18.5,18.6,18.4,18.5,18.6,18.6,18.5,18.6,18.4,18.4,18.3,18.4,18.5,18.5,18.5,18.4,18.5,18.4,18.3,18.2,18.2,18.2,18.3,18.4,18.4,18.3,18.2,18.4,18.4,18.2,18.1,18.1,18.3,18.4,18,18.1,17.8,18,17.8,18,17.8,17.9,17.9,18,17.7,18,17.8,17.9,17.8,18.1,18,17.8,18,17.8,18.1,17.9,17.8,17.7,17.8,17.5,17.8,17.8,17.7,17.7,17.9,17.8,17.7,17.9,17.6,17.9,17.6,17.9,17.7,17.9,17.8,17.6,17.8,17.8,17.8,18,18,17.9,18.1,18.3,18.2,18.1,18.1,18.4,18.2,18.1,18.1,18.2,18.3,18.3,18.4,18.4,18.3,18.3,18.3,18.1,18.1,18.2,18.4,18.3,18.2,18.2,18.1,18,18.1,18,18.1,18.3,18.3,18.2,18.1,18.1,18.1,17.9,18,18.1,18,18,18,18,18.1,18.1,18,18,17.9,18,18.1,18.3,18.3,18.2,18.3,18.1,18,18,18.1,18.1,18.1,18.1,18.5,18.3,18.3,18.3,18.2,18.1,17.9,18,18,18.1,18.4,18.3,18.3,18,18,17.9,17.8,17.9,17.8,17.8,18.1,17.9,17.8,17.6,17.9,17.8,17.8,17.8,17.8,17.7,17.8,17.8,17.8,17.9,17.8,17.6,17.7,17.9,17.8,17.7,17.6,17.6,17.7,17.7,17.7,17.6,17.6,17.6,17.7,17.6,17.5,17.8,17.7,17.8,17.8,17.9,18.1,17.7,17.7,17.8,17.9,17.8,17.5,17.8,17.7,17.9,17.7 ],
}
, {
name: 'T-2306',
lineWidth:.75,
data: [
21.1,21.3,21.2,20.9,21.2,21.2,21,20.9,20.8,20.7,21,20.8,20.5,20.1,19.8,19.5,19.8,19.6,19.5,19.5,19.6,19.5,19.4,19.3,19.3,19.3,19.3,19.2,19.2,19.1,19.1,19.1,19.1,19.1,19,18.9,19,19.1,19,18.8,18.9,18.9,18.9,19.1,19.2,19.3,19.3,19.4,19.6,19.8,19.7,19.9,20.1,20.2,20.3,20.3,20.3,20.2,20.2,20.3,20.2,20.2,20.2,19.9,19.9,20.1,20.1,20.2,20.3,20.2,20.2,20.4,20.3,20.2,20.3,20.3,20.2,20.2,20.6,20.4,20.3,20.4,20.3,20.4,20.4,20.4,20.4,20.4,20.3,20.3,20.2,20.4,20.4,20.4,20.4,20.3,20.5,20.3,20.2,20.2,20.1,20.2,20.2,20.3,20.2,20.2,20.2,20.3,20.2,19.9,19.8,19.8,19.8,19.8,19.3,19.1,18.9,18.9,18.8,18.8,18.7,18.7,18.8,18.8,18.6,18.8,18.6,18.8,18.5,18.8,18.7,18.7,18.8,18.6,18.8,18.7,18.6,18.5,18.4,18.2,18.4,18.4,18.4,18.4,18.4,18.4,18.4,18.6,18.3,18.6,18.3,18.5,18.4,18.6,18.4,18.4,18.4,18.4,18.6,18.9,18.9,19,19.4,19.6,19.5,19.4,19.4,19.7,19.5,19.6,19.6,19.8,19.8,19.9,19.9,19.9,19.8,19.8,19.9,19.8,19.8,19.9,20,20.1,19.9,19.9,19.8,19.8,19.9,19.8,19.8,20,20,20,19.8,19.7,19.8,19.6,19.7,19.7,19.6,19.6,19.7,19.7,19.8,19.9,19.8,19.8,19.7,19.7,19.8,19.9,20,19.9,19.9,19.8,19.7,19.5,19.5,19.3,18.8,18.7,18.9,18.7,18.6,18.6,18.6,18.5,18.4,18.4,18.4,18.6,18.8,18.7,18.8,18.4,18.4,18.4,18.4,18.4,18.3,18.3,18.4,18.3,18.3,18.2,18.3,18.3,18.3,18.2,18.3,18.2,18.2,18.3,18.3,18.3,18.2,18.2,18.2,18.3,18.2,18.2,18.1,18.1,18.2,18.1,18.1,18.1,18.1,18.2,18.2,18,18.1,18.3,18.2,18.3,18.2,18.3,18.6,18.1,18.2,18.3,18.4,18.2,18,18.3,18.2,18.4,18.3 ],
}
, {
name: 'T-2282',
lineWidth:.75,
data: [
7.3,17.1,17.1,17.3,17.2,17.3,17.3,17.4,17.4,17.4,17.5,17.3,17.4,17.6,17.6,17.7,17.6,17.6,17.8,17.6,17.7,17.8,17.7,17.7,17.6,17.7,17.7,17.9,17.8,17.8,17.8,17.8,17.8,17.8,17.8,17.7,17.8,17.7,17.7,17.8,17.8,17.7,17.8,17.9,18.6,18.4,18.4,18.4,18.4,18.3,18.2,18.4,18.4,18.6,18.9,18.8,18.9,18.5,18.6,18.4,18.4,18.4,18.3,18.4,18.7,18.6,18.5,18.2,18.5,18.4,18.3,18.4,18.4,18.2,18.4,18.6,18.5,18.5,18.3,18.4,18.4,18.6,18.4,18.4,18.3,18.3,18.2,18.3,18.3,18.2,18.1,18.2,18.3,18,17.8,18.1,17.9,18,17.9,17.9,18.3,17.7,17.8,18,18.2,17.9,17.5,17.9,17.8,18.1,17.9 ],
}
, {
name: 'T-2089',
lineWidth:.75,
data: [
19.6,19.6,19.7,19.5,19.7,19.6,19.6,19.5,19.4,19.5,19.7,19.6,19.3,19.2,19,18.7,18.9,18.8,18.7,18.7,18.7,18.7,18.6,18.5,18.6,18.5,18.5,18.4,18.4,18.3,18.4,18.3,18.4,18.4,18.3,18.2,18.2,18.2,18.1,17.9,18,18.1,18.1,18.2,18.1,17.9,17.9,17.8,17.8,17.8,17.7,17.7,17.7,17.7,17.8,17.8,17.8,17.7,17.7,17.8,17.8,17.7,17.7,17.5,17.6,17.6,17.6,17.6,17.7,17.6,17.6,17.7,17.6,17.6,17.7,17.7,17.6,17.6,17.7,17.5,17.4,17.4,17.3,17.4,17.4,17.5,17.5,17.4,17.4,17.4,17.3,17.4,17.5,17.4,17.5,17.5,17.6,17.4,17.4,17.4,17.5,17.5,17.5,17.6,17.6,17.6,17.6,17.6,17.6,17.4,17.4,17.5,17.5,17.7,17.7,17.7,17.7,17.7,17.7,17.7,17.7,17.7,17.8,17.8,17.6,17.7,17.7,17.8,17.6,18,17.9,17.8,17.9,17.7,18.1,18,17.9,17.9,17.8,17.6,17.7,17.9,17.9,17.9,17.9,17.8,17.8,17.9,17.7,17.9,17.7,17.9,17.8,17.9,17.8,17.8,17.9,17.8,17.9,17.8,17.7,17.6,17.7,17.7,17.6,17.5,17.5,17.7,17.6,17.6,17.7,17.7,17.7,17.7,17.7,17.7,17.6,17.6,17.7,17.6,17.6,17.7,17.7,17.8,17.9,17.9,18.1,18.2,18.3,18.2,18.3,18.4,18.5,18.5,18.4,18.4,18.6,18.4,18.5,18.6,18.5,18.5,18.4,18.4,18.5,18.7,18.8,18.8,18.7,18.8,18.8,18.8,18.8,18.8,18.8,18.8,18.9,19,18.9,18.9,19.1,19.2,19.5,19.4,19.4,19.4,19.5,19.4,19.3,19.3,19.2,19.4,19.6,19.6,19.7,19.6,19.5,19.4,19.3,19.3,19.3,19.3,19.4,19.3,19.3,19.1,19.1,19.1,19,19.1,19.3,19.1,19.2,19.3,19.2,19.1,19.1,19.1,19.1,19.2,19.1,19.1,19.1,19,19,19,18.9,18.8,18.8,18.8,18.8,18.6,18.4,18.4,18.3,18.4,18.2,18.3,18.5,18.2,18.2,18.2,18.4,18.2,17.9,18.1,18.1,18.2,18.3 ],
}
],
plotOptions:{
line:{
marker:{
enabled : false
}
}
},
legend:{
enabled:false
}
});
});</script>
Don't use categories. In your case:
Set xAxis.type to datetime (not type: 'time'!). Remove categories, or at least replace categories with tickPositions.
If you have regular interval between points, use series.pointStart and series.pointInterval (or pointIntervalUnit). If your data may be irregular, then change your data format. Currently you have data: [value, value, value]. Instead use data: [ [timestamp, value], [timestamp, value], [timestamp, value] ]
Add xAxis.tickInterval option - for example 3600 * 1000, to determine where ticks should appear.
Add xAxis.maxPadding = 0 option - so last tick won't exceed extremes.
That's all. Example with regular interval between points: https://jsfiddle.net/txuhs36t/2/

Working with JSONP Object in Highcharts

I have working JSONP being passed from my server. The JSONP (with the $.getJSON padding) looks like this:
jQuery21009647691948339343_1398527630522([
{
"name": 'World Federation of Democratic Youth',
"data": [16]
},
{
"name": 'Poqilet',
"data": [13]
},
{
"name": 'United Society',
"data": [8]
},
{
"name": 'Japvia',
"data": [589]
},
{
"name": 'the Mars',
"data": [1]
},
{
"name": 'The Americas',
"data": [913]
},
{
"name": 'High Orion Alliance',
"data": [1]
}
])
The PHP script I am using to pass this to my client is this:
header("content-type: application/json");
$array = (file_get_contents('data.json'));
echo $_GET['callback']. '('. ($array) . ')';
Now, when I get this object I want to put it into a Highcharts series
$(document).ready(function () {
var options = {
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Update Order'
},
xAxis: {
categories: ['Regions']
},
yAxis: {
min: 0,
title: {
text: 'Number of Nations'
}
},
legend: {
backgroundColor: '#FFFFFF',
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{}]
};
var url = "http://myserver.org/requestjsonp.php?callback=?";
$.getJSON(url, function (data) {
console.log(data);
options.series.data = data;
var chart = new Highcharts.Chart(options);
});
});
This is not working and I do not understand why, as I have worked through the errors I was getting before. Now I get no errors in the console, I just get nothing.
If I paste the contents of the JSON into the series, I get what I want, although I have to take out the first "{" and the last "}" character. Is this the problem? How can I remove them from an object if they are required to be in the JSON so that it can get passed to the client?
.remove() and other jquery methods I tried to trim the data once I received it didn't work.
console.log(data) now provides an array of 7 objects, which I believe is in line with data.json (seven name/data pairs).
Thank you for your consideration! :)
Your JSONP is incorrect. Without the padding it would look like:
{
name: 'World Federation of Democratic Youth',
data: [16]
},
{
name: 'Poqilet',
data: [13]
},
This is not valid JSON. It should probably look like:
[{
"name": "World Federation of Democratic Youth",
"data": [16]
},
{
"name": "Poqilet",
"data": [13]
}]
You probably also just want to do options.series = data since data will be an array.
In your JSON you have structre of series, not points. Because you use data[] paramter inside. In other words it should be:
options.series = data;
It turns out the JSONP data was not formatted correctly for Highcharts, so what I did was made it look like this (with padding):
jQuery21009184384981635958_1398737380163([{"name": "Regions","data": ["World Federation of Democratic Youth", "Poqilet", "United Society", "Japvia", "the Mars", "The Americas", "High Orion Alliance"]},{"name": "Number of Nations","data": [16, 13, 5, 566, 1, 926, 1]}])
And the Javascript to utilize it:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Update Order',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Number of Nations'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON('http://myserver.org/requestjsonp.php?callback=?', function(data) {
options.xAxis.categories = data[0]['data'];
options.series[0] = data[1];
chart = new Highcharts.Chart(options);
});
});
This works for the small JSONP excerpt that I posted, but not for my full set of data, which contains over 10,000 values and was throwing up a Highcharts Error 19 (http://www.highcharts.com/errors/19) message, so I will be trying to do a master-detail chart to deal with the large amount of data, but this should work for you if you have a small dataset.
For more on how highcharts data should be formatted, you can go here: http://www.highcharts.com/docs/chart-concepts/series/#1

Displaying array values in Bar chart of HighCharts

I am trying to display values which I am getting dynamically. In the below code I am trying to store the values in array and I am trying to use the array values in "series: data".
Nothing is getting displayed in the graph.
I know this is very simple question but I did not get any satisfactory answer when I googled it. Please help
var x = window.location.search.replace( "?", "" );
x = x.substring(3);
var array = x.split(","); // I am storing my dynamic values in this array
$(function () {
//alert(array); ----- I am able to see the values here
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Wireless Experience Meter'
},
subtitle: {
text: 'Sub - Time to Download'
},
xAxis: {
categories: ['Text'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Time (ms)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' ms'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Attempt 1',
//data: [635, 203, 200]
data : [array[0]] // I need to pass the variables here to get it displayed
}, {
name: 'Attempt 2',
//data: [133, 408, 698]
data : [array[1]]
}, {
name: 'Attempt 3',
//data: [973, 914, 4054]
data : [array[2]]
}]
});
});
You don't tell us what the variable array equals but since its generated from x.split(","), it's elements are going to be strings and not the numeric values Highcharts needs.
So convert it with parseInt or parseFloat:
var numericData = [];
for (var i = 0; i < array.length; i++){
numericData.push(parseFloat(array[i]));
}
...
series: [{
name: 'Attempt 1',
data : numericData
},
...
[array[0]] is not an array, that looks like console output not javascript. But [[0]] or [0] technically would be. However, since a call to array (array(0)) generates an array then I think you want data: array(0).
Outside shot at data : [array(0)] if you didn't show the example data correctly. I've never used HighCharts so I don't know what it's expected but I still go with data : array(0)

Highcharts column + line combination chart with multiple series. Issue aligning line over the column

I have a multi-series column chart (3 in this case). I wanted to overlay a line over the columns across all series. So i created a 3 more Line series' with the same column series data. This works perfectly when there is only one column and line series. With more than one series, the line renders at the center of the category, instead of showing up on the corresponding column (Note: left shifting the line will work, but i dont know how).
Link to JSFiddle: http://jsfiddle.net/Wm6dU/7/
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: "Column Line Combo"
},
xAxis: {
categories: [
"Cat 1",
"Cat 2",
"Cat 3"],
},
yAxis: {
title: {
text: 'USD'
}
},
series: [{
name: "Revenue",
data: [
49.9,
71.5,
106.4],
type: "column"
}, {
name: "Revenue",
data: [
49.9,
71.5,
106.4],
type: "line"
}, {
name: "Cost of goods sold",
data: [
83.6,
78.8,
98.5],
type: "column"
}, {
name: "Cost of goods sold",
data: [
83.6,
78.8,
98.5],
type: "line"
}, {
name: "Operating Expenses",
data: [
48.9,
38.8,
39.3],
type: "column"
}, {
name: "Operating Expenses",
data: [
48.9,
38.8,
39.3],
type: "line"
}]
});
});
Thanks.
What about setting the x values for those lines? http://jsfiddle.net/qPqCW/
, {
name: "Revenue",
data: [
{x:-0.2, y:49},
{x:0.8, y:71.5},
{x:1.8, y:106.4}],
type: "line"
},
, {
name: "Operating Expenses",
data: [
{x:.2,y:48.9},
{x:1.2, y:38.8},
{x:2.2, y:39.3}],
type: "line"
}
To calculate the X values, I looked to the source code. The following assumes you are using the default values of groupPadding .2, and pointPadding .1. I modified the getColumnMetrics function to get the general solution. Here's what I came up with:
var columnMetrics = [];
for (j=0;j<index;j++) {
var categoryWidth = 1,
groupPadding = categoryWidth * .2,
groupWidth = categoryWidth - 2 * groupPadding,
pointOffsetWidth = groupWidth / index,
pointPadding = pointOffsetWidth * .1,
pointWidth = pointOffsetWidth - 2 * pointPadding,
colIndex = j,
pointXOffset = pointPadding + (groupPadding + colIndex *
pointOffsetWidth - (categoryWidth / 2));
columnMetrics.push( {
width: pointWidth,
offset: pointXOffset,
center: pointXOffset + (pointWidth /2.0)
});
}
var series = [];
for(i=0;i<index;i++) {
series.push({
name: "Column" + index,
data: [
49.9,
71.5,
106.4],
type: "column"
});
series.push({
name: "Line" + index,
data: [
{x:0 + columnMetrics[i].center, y:49},
{x:1 + columnMetrics[i].center, y:71.5},
{x:2 + columnMetrics[i].center, y:106.4}],
type: "line"
});
}
This shows the results with 1 to 10 series: http://jsfiddle.net/b8gS5/

Categories

Resources