multiple charts in the same page php - php

I'm trying to draw two charts in the same page php using highcharts.But, just the first one was displayed.The $data1,$data2,$data3,$data4,$data5 are values returned by some functions.
page.php:
<div>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<div id="containerone" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<?php
include 'data.php';
$data1=data::amountUSD($res['id']);
$data2=data::amountEUR($res['id']);
$data3=data::Month($res['id']);
$data5=data::Totalminutejour($res['id']);
$data4=data::Day($res['id']);
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'USD VS EUR'
},
xAxis: {
categories: [<?php echo join(',', $data3); ?>]
},
yAxis: {
title: {
text: 'Amount'
},
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: [ {
name: 'EUR',
data: [<?php echo join(',', $data2); ?>],
},
{
name: 'USD',
data: [<?php echo join(',', $data1); ?>],
},
]
});
});
$(function() {
var chartone = new Highcharts.Chart({
chart: {
renderTo: 'containerone',
type: 'column',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Range Total Minutes every day',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: [<?php echo join(',', $data4); ?>]
},
yAxis: {
title: {
text: 'Total Minutes'
},
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: [{
name: 'TotalMinuteDay',
data: [<?php echo join(',', $data5); ?>],
},
]
});
});
</script>
</div>
That's what print_r returns:
print_r($data1); // Array ( [0] => 8.800000190734863 [1] => 20 )
print_r($data2); // Array ( [0] => 8.800000190734863 [1] => 2 )
print_r($data3); // Array ( [0] => 5 [1] => 5 [2] => 4 [3] => 4 )
print_r($data4); //Array ( [0] => a [1] => d )
print_r($data5); // Array ( [0] => 0.2 [1] => 0.2 )

Related

Cannot Use Two Splines in Highchart

I am trying to use two spline into my graph created from highcharts. My first Spline is displyed in center and second is displayed correctly . My output look like below,
Am trying the following code,
<script type="text/javascript">
var categories = [];
$(document).ready(function () {
var left = [ 5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5];
var right = [-5, -0, -0, -0, -0, -3, -0, -0, -0, -0, -5];
Highcharts.chart('container', {
chart: {
type: 'bar'
},
tooltip: { enabled: false },
xAxis: [{
categories: categories,
reversed: false,
}, {
opposite: true,
reversed: false,
categories: categories,
linkedTo: 0,
}],
yAxis: {
title: {
text: null
},
},
plotOptions: {
series: {
pointWidth: 2,
stacking: 'normal'
}
},
exporting: { enabled: false },
credits: {enabled: false},
series: [{
showInLegend: false,
data: right
}, {
showInLegend: false,
data: left
}
,{
showInLegend: false,
type: 'spline',
name:'test1',
marker:'disabled',
color:'black',
data: [-5,-4,-3,-3,-3,-3,-3,-3,-3,-4,-5],
pointPlacement: -.15
},
{
showInLegend: false,
type: 'spline',
name:'test2',
marker:'disabled',
color:'black',
data: [5,4,3,3,3,3,3,3,3,4,5]
}
]
});
});
And My Excepted Output is ,
Please help me to solve this issues.
For Solving this Issues just change the first spline data value into double .
<!DOCTYPE html>
<html>
<head>
<title>Test Graph</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
</body>
</html>
<script type="text/javascript">
var categories = [];
$(document).ready(function () {
var left = [ 5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5];
var right = [-5, -0, -0, -0, -0, -3, -0, -0, -0, -0, -5];
Highcharts.chart('container', {
chart: {
type: 'bar'
},
tooltip: { enabled: false },
xAxis: [{
categories: categories,
reversed: false,
}, {
opposite: true,
reversed: false,
categories: categories,
linkedTo: 0,
}],
yAxis: {
title: {
text: null
},
},
plotOptions: {
series: {
pointWidth: 0,
stacking: 'normal'
}
},
exporting: { enabled: false },
credits: {enabled: false},
series: [{
showInLegend: false,
data: right
},
{
showInLegend: false,
data: left
},
{
showInLegend: false,
type: 'spline',
marker:'disabled',
color:'black',
data: [-10,-8,-6,-6,-6,-6,-6,-6,-6,-8,-10]
},
{
showInLegend: false,
type: 'spline',
marker:'disabled',
color:'black',
data: [5,4,3,3,3,3,3,3,3,4,5]
}]
});
});
</script>

Highcharts with multiple dataLabels

I am using Highcharts to display transaction status for different months. The chart is displaying fine. To show the number of transactions for each month, I have placed a datalabel on top of each column. The code is given below:
$(function () {
$('#hc').highcharts({
chart: {
renderTo: 'container',
type: <?php echo $type ; ?>,
marginRight: 130,
marginBottom: 35
},
title: {
text: 'Transaction Status',
x: -20
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: <?php echo $monnth_series ?>
},
yAxis: {
title: {
text: 'Transactions'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
color: '#fff',
style: {fontWeight: 'bold'},
formatter: function() {return this.y},
y: -5,
rotation: 360
},
column: {
pointPadding: .2,
groupPadding: 0,
borderWidth: 1
}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +': '+ this.y; +'</b>'
}
},
credits: { enabled: false },
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -6,
y: 90,
borderWidth: 0
},
series: <?php echo $series_data ?>
});
});
Now I want to place another datalabel on the body of the column which will show the type of the transaction.
If I try
formatter: function() {return this.series.name},
inside: true,
then the datalabel shows correctly but the datalabel on top of the column does not show up.
Any idea on how to do this ?

High charts using candlestick,vloum and MACD

I am new to highcharts and i am using hightcharts graph but volume not showing.When i remove MACD then volume show i don't understand why i am getting this issue!. my code are
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
var ohlc = [],
volume = [],
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
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([
data[i][0], // the date
data[i][5] // the volume
])
}
// set the allowed units for data grouping
var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
$(function() {
$('#container').highcharts('StockChart', {
title : {
text : 'MACD of AAPL stock price'
},
subtitle: {
text: 'From may 15, 2006 to May 10, 2013'
},
yAxis: [{
title: {
text: 'Price'
},
height: 200,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
}, {
title: {
text: 'MACD'
},
top: 320,
height: 100,
offset: 0,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 500,
height: 60,
offset: 0,
lineWidth: 2
}],
tooltip: {
crosshairs: true,
shared: true
},
rangeSelector : {
selected : 1
},
legend: {
enabled: true,
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
plotOptions: {
series: {
marker: {
enabled: false,
}
}
},
series : [{
name: 'AAPL Stock Price',
type : 'line',
id: 'primary',
data : data
}, {
name : 'MACD',
linkedTo: 'primary',
yAxis: 1,
showInLegend: true,
type: 'trendline',
algorithm: 'MACD'
}, {
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
linkedTo: 'primary',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}, {
name: 'Histogram',
linkedTo: 'primary',
yAxis: 1,
showInLegend: true,
type: 'histogram'
}]
});
});
});
Why volume is not showing?
Thanks in advance!
You have three yAxis, but in each serie (except first) you use yAxis:1 which means that series is displayed on that axis. So you need to modify axis index to display on the "last" yAxis.

how to place same highcharts series beside each other

i am using highcharts for drawing column charts
i have a column chart with multiple series like this
and this is my code :
$(function () {
var chart;
$(document).ready(function() {
// Radialize the colors
Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
return {
radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
stops: [
[0, color],
[1, Highcharts.Color(color).brighten(-0.2).get("rgb")]
]
};
});
chart = new Highcharts.Chart({
chart: {
renderTo: "container"
},
title: {
text: "نمودار کلی عملکرد داوطلب",
style:
{
direction: "rtl",
fontSize: "16px"
}
},
yAxis: {
min: -33.3,
max: 100,
startOnTick: false,
title: {
enabled: true,
text: "درصد"
}
},
xAxis: {
categories: [' . implode(",", $chartCats) . ']
},
tooltip: {
formatter: function() {
return this.series.name+"<br/>% "+this.point.y+"<br/>";
}
},
plotOptions: {
column: {
dataLabels: {
enabled: true
},
pointWidth: 20
},
series: {
animation: {
duration: 3000
}
}
},
credits: {
enabled: false
},
series:
[' . $chartData . ']
});
});
});
how can i place all columns with same color beside each other?
for example : all blue columns beside each other then all red column beside each other
In general something like this is not supported, however you can split data into different arrays, as each column will be one series, just linked to 'master' one, see: http://jsfiddle.net/CVvjZ/
Of course this has limitations, since you need to pre calculate values for for x:
xAxis: {
min: 0,
startOnTick: true,
max: 1,
endOnTick: true,
categories: ['Jan', 'Feb', 'Mar']
},
plotOptions: {
column: {
grouping: false,
pointWidth: 20
}
},
series: [{
color: colors[0],
name: 'Tokyo',
id: 'tokyo',
data: [[0.3, 15]]
}, {
color: colors[0],
name: 'Tokyo',
linkedTo: 'tokyo',
data: [[0, 10]]
}, {
color: colors[0],
name: 'Tokyo',
linkedTo: 'tokyo',
data: [[-0.3, 10]]
},{
color: colors[1],
name: 'Osaka',
id: 'osaka',
data: [[1.3, 15]]
}, {
color: colors[1],
name: 'Osaka',
linkedTo: 'osaka',
data: [[1, 10]]
}, {
color: colors[1],
name: 'Osaka',
linkedTo: 'osaka',
data: [[0.7, 10]]
}]
There is also second solution, a little easier is to use stacking options instead of calculating values: http://jsfiddle.net/CVvjZ/1/
And code:
xAxis: {
categories: ['Jan', 'Feb', 'Mar']
},
plotOptions: {
column: {
stacking: 'normal'
}
},
series: [{
color: colors[0],
stack: 1,
name: 'Tokyo',
id: 'tokyo',
data: [15]
}, {
color: colors[0],
stack: 2,
name: 'Tokyo',
linkedTo: 'tokyo',
data: [15]
}, {
color: colors[0],
stack: 3,
name: 'Tokyo',
linkedTo: 'tokyo',
data: [11]
},{
color: colors[1],
stack: 1,
name: 'Osaka',
id: 'osaka',
data: [[1,12]]
}, {
color: colors[1],
stack: 2,
name: 'Osaka',
linkedTo: 'osaka',
data: [[1,13]]
}, {
color: colors[1],
stack: 3,
name: 'Osaka',
linkedTo: 'osaka',
data: [[1,14]]
}]

Highchart shows only 12 categories

Hi guys I'm having a trouble working with Highchart. I think my error is when the category is more than 12. here's my code:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['ARC', 'CLM', 'COLREP', 'CUI', 'FB', 'IOH', 'IST', 'LCV', 'LCWSLC', 'LOGDFR', 'LOGDRT', 'LOGGLE',
'LOGGT', 'LOGSR', 'LOGVL', 'LST', 'OARD', 'OARP', 'OARPPP', 'POR', 'PRIN', 'SLRD', 'SLRS', 'SLRSUP', 'SVTCBR',
'SVTSP', 'SVTST', 'TKD', 'TR', 'USO']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y +'°C';
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [400.6, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 100.9]
}]
});
});
});​
I already try to put the categories in array variable but same result show.
x-axis only show 12 categories. the example on there site is good for 12 categories. Is anyone know how to fix this problem or configure anything in the plugin?
here's there demo page http://www.highcharts.com/demo/line-basic
thanks in advance!
The problem is that you have series with only 12 Values within each array ,so if there's only 12 Values it will pick up first 12 Categories .
High chart's wont show Categories without data related to them using Series ,just put 18 next 0 Values at Series Array and it will show those Categories .

Categories