Sankey Diagram unable to deliver using the json output - highcharts

Using data from database I am trying to simulate the sankey diagram working JSFiddle.
I am assembling my data using the below code
// sdata.php
<?php
$con = sqlsrv_connect($server, $options);
if (!$con){die('Could not connect: ' . sqlsrv_error());}
$sql_query = "select * from test_data";
$result = sqlsrv_query($con, $sql_query);
$series = array();
$series['type'] = 'sankey';
$series['name'] = 'Gendata';
$series['keys'] = '[\'from\',\'to\',\'weight\']';
while($r = sqlsrv_fetch_array($result))
{
$series1 = array();
$series1[] = $r['PARENT'];
$series1[] = $r['CHILD'];
$series1[] = $r['DGEN'];
$series['data'][] = $series1;
}
$result = array();
array_push($result,$series);
print json_encode($result, JSON_NUMERIC_CHECK);
sqlsrv_close($con);
?>
My JSON looks like
[{
"type":"sankey",
"name":"Gendata",
"keys":"['from','to','weight']",
"data":[
["GROUP","COAL",24.46], ["GROUP","GAS",11.96],["GROUP","HYDRO",19.36],
["HYDRO","HYD",19.36], ["COAL","ER2",22.4],["GAS","NR",19]
]
}]
My Chart rending code looks like
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
showAxes: true
},
yAxis: [{
lineWidth: 1,
tickPositions: [0, 1, 2, 3]
}],
title: {
text: 'Sankey Diagram'
},
series: []
}
$.getJSON("sdata.php", function(resp) {
console.log(resp);
options.series[0] = resp[1]; //option 1 to assign the data in series
//options.series.push.resp; //option 2 to push the data in series
chart = new Highcharts.Chart(options);
});
});
but I am failing. I am unable to find the error I am missing
Kindly help me.
Let me know if I can be of any further information.

From the code you have posted here, the error is your keys assignment.
You have:
"keys":"['from','to','weight']",
But it needs to be:
"keys": ['from','to','weight'],
That is, the array should not be surrounded by quotes, because then it will be interpreted as a string.
In your PHP that would mean:
$series['keys'] = '[\'from\',\'to\',\'weight\']';
Needs to be:
$series['keys'] = ['from', 'to', 'weight'];
Working example: https://jsfiddle.net/ewolden/aeh02djx/

Related

Highcharts - Indicator's data not showing in line chart

I am fetching data from an endpoint
I display the data in a highchart
There are several indicators that can be selected. For each of them another yAxis is added below the main one.
My series data are of this format :
series: [
{
data: [],
id: 'prices',
step: this.hasStep,
name: this.$props.title,
fillColor: 'rgba(127,183,240,0.2)',
},
{
visible: false,
type: 'column',
id: 'volume',
name: 'Volume_hardcoded',
//linkedTo: 'prices',
data: this.volumeSeries,
},
],
I save the data in the following way (don't pay attention in the logic, it works fine):
if (this.selectedTimeSpan.tickInterval === 1) {
for (let i = 0; i < prices.length; i++) {
let xData = null;
this.selectedTimeSpan.getIntradayData
? (xData = Math.floor(new Date(prices[i].time).getTime()))
: (xData = Math.floor(new Date(prices[i].date).getTime()));
priceSeries[i] = {
x: xData,
open: prices[i].first,
high: prices[i].high,
low: prices[i].low,
close: prices[i].last,
y: prices[i].last,
volume: prices[i].tradingVolume,
};
this.volumeSeries[i] = {
x: xData,
y: prices[i].tradingVolume,
};
}
} else {
let j = 0;
for (
let i = 4;
i < prices.length;
i += this.selectedTimeSpan.tickInterval
) {
priceSeries[j] = {
x: Math.floor(new Date(prices[i].date).getTime()),
open: prices[i].first,
high: prices[i].high,
low: prices[i].low,
close: prices[i].last,
y: prices[i].last,
volume: prices[i].tradingVolume,
};
this.volumeSeries[j] = {
x: Math.floor(new Date(prices[i].date).getTime()),
y: prices[i].tradingVolume,
};
j++;
}
}
When I select these indicators (they are based on the volume), I am getting this result.(You can see a blank space below the main chart.) Instead when i swap to OHLC or candlestick my main series (series[0]) it looks works fine and it looks like this. Any idea why is that happening? I haven't touched the tooltip settings at all (in case it was there a problem). I am struggling 2 days now with it can't really figure it out. Any help would be appreciated a lot. If you need more information feel free to comment so I can provide. Thanks in advance. Chris.
Fixed, there's a flag that can be used called usedOhlcData in series object. (series[0] in my case]. We just set it to true.
series:[{
data:[],
useOhlcData:true,
...}
,{
...
}]

Highcharts does not load my data properly

I've tried several types of outputs. What I already have is:
JSON Output:
["[Date.UTC(2015,6,13,16,41,05), 3]","[Date.UTC(2015,7,15,16,41,05), 1]","[Date.UTC(2015,8,18,16,41,05), 4]","[Date.UTC(2015,9,28,16,41,05), 3]","[Date.UTC(2015,10,20,16,41,05), 1]","[Date.UTC(2015,10,28,16,41,05), 5]","[Date.UTC(2015,11,13,16,41,05), 1]","[Date.UTC(2015,11,21,16,41,05), 2]","[Date.UTC(2015,11,24,16,41,05), 1]","[Date.UTC(2015,11,25,16,41,05), 2]","[Date.UTC(2015,11,28,16,41,05), 1]","[Date.UTC(2016,0,03,16,41,05), 2]","[Date.UTC(2016,0,09,16,41,05), 4]","[Date.UTC(2016,0,14,16,41,05), 6]","[Date.UTC(2016,0,17,16,41,05), 3]","[Date.UTC(2016,0,18,16,41,05), 3]","[Date.UTC(2016,0,20,16,41,05), 2]","[Date.UTC(2016,0,21,16,41,05), 2]","[Date.UTC(2016,0,22,16,41,05), 2]","[Date.UTC(2016,0,23,16,41,05), 1]","[Date.UTC(2016,0,24,16,41,05), 5]","[Date.UTC(2016,0,25,13,41,05), 1]","[Date.UTC(2016,0,25,16,41,00), 1]","[Date.UTC(2016,0,25,16,41,05), 1]","[Date.UTC(2016,0,27,16,41,05), 1]","[Date.UTC(2016,0,28,16,41,05), 1]","[Date.UTC(2016,0,29,16,41,05), 1]","[Date.UTC(2016,1,09,16,41,05), 1]","[Date.UTC(2016,1,10,16,41,05), 2]","[Date.UTC(2016,1,11,16,41,05), 3]","[Date.UTC(2016,1,15,16,41,05), 2]","[Date.UTC(2016,1,18,16,41,05), 1]","[Date.UTC(2016,1,21,16,41,05), 1]","[Date.UTC(2016,1,23,16,41,05), 1]","[Date.UTC(2016,1,24,16,41,05), 1]","[Date.UTC(2016,1,25,16,41,05), 1]","[Date.UTC(2016,1,26,16,41,05), 1]","[Date.UTC(2016,1,28,16,41,05), 1]","[Date.UTC(2016,2,01,16,41,05), 1]","[Date.UTC(2016,2,02,16,41,05), 1]","[Date.UTC(2016,2,05,16,41,05), 1]","[Date.UTC(2016,2,12,16,41,05), 1]","[Date.UTC(2016,2,21,16,41,05), 1]","[Date.UTC(2016,3,25,16,41,05), 1]","[Date.UTC(2016,4,05,16,41,05), 2]","[Date.UTC(2016,4,11,16,41,05), 1]","[Date.UTC(2016,4,12,16,41,05), 1]","[Date.UTC(2016,4,24,16,41,05), 1]","[Date.UTC(2016,4,25,16,41,05), 1]","[Date.UTC(2016,5,01,16,41,05), 1]","[Date.UTC(2016,5,12,16,41,05), 1]","[Date.UTC(2016,5,25,10,41,05), 1]","[Date.UTC(2016,5,25,16,41,05), 1]","[Date.UTC(2016,6,01,10,41,05), 1]","[Date.UTC(2016,6,01,16,41,05), 1]","[Date.UTC(2016,6,02,16,41,05), 1]","[Date.UTC(2016,6,25,16,21,05), 1]","[Date.UTC(2016,6,25,16,41,05), 1]","[Date.UTC(2016,7,13,16,41,05), 1]","[Date.UTC(2016,7,28,16,41,05), 1]","[Date.UTC(2016,8,20,16,41,05), 3]","[Date.UTC(2016,8,29,16,41,05), 2]","[Date.UTC(2016,9,01,14,20,18), 1]","[Date.UTC(2016,9,09,14,20,18), 1]","[Date.UTC(2016,9,10,14,20,18), 1]","[Date.UTC(2016,9,28,14,20,18), 2]","[Date.UTC(2016,9,30,14,20,18), 2]","[Date.UTC(2016,10,01,13,44,29), 1]","[Date.UTC(2016,10,06,08,26,18), 2]","[Date.UTC(2016,10,10,13,44,29), 1]","[Date.UTC(2016,10,13,13,44,29), 2]","[Date.UTC(2016,10,14,19,13,42), 4]","[Date.UTC(2016,10,15,23,27,39), 3]","[Date.UTC(2016,11,06,19,04,06), 3]","[Date.UTC(2016,11,08,10,49,28), 3]","[Date.UTC(2016,11,10,23,01,44), 1]","[Date.UTC(2016,11,14,21,27,44), 1]","[Date.UTC(2016,11,15,23,27,44), 2]","[Date.UTC(2016,11,15,23,27,53), 3]","[Date.UTC(2016,11,18,18,06,28), 1]","[Date.UTC(2016,11,21,20,06,28), 3]","[Date.UTC(2016,11,23,20,06,20), 5]","[Date.UTC(2016,11,29,20,18,18), 3]","[Date.UTC(2017,0,03,20,06,32), 3]"]
That looks OK!
The works I've done on PHP is:
header("Content-type: text/json");
if($callback == 'cart-filling') {
// Count cart rows
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName('#__product_shoppingcart'))
->where($db->quoteName('date') . $scope);
$db->setQuery($query);
$results = $db->loadObjectList();
$ret = array();
foreach($results as $result) {
//$x = date_format($date, 'Y-m-d H:i:s');
$date = new DateTime($result->date);
$month = date_format($date, 'm');
$monthInt = (int) $month-1;
$date_part1 = date_format($date, 'Y');
$date_part2 = $monthInt;
$date_part3 = date_format($date, 'd');
$date_part4 = date_format($date, 'H');
$date_part5 = date_format($date, 'i');
$date_part6 = date_format($date, 's');
$formatted_date = (int) $date_part1 . ',' . (int) $date_part2 . ',' . (int) $date_part3 . ',' . (int) $date_part4 . ',' . (int) $date_part5 . ',' . (int) $date_part6;
/*
$date = new DateTime($result->date);
$x = date_format($date, "Y-m-d H:i:s");
*/
$x = $formatted_date;
$y = $result->qty;
//array_push($ret, array($x, $y));
//extract $row;
//$x = 'Date.UTC(' . $x . ')'; // convert from Unix timestamp to JavaScript time
$data[] = "[Date.UTC($x), $y]";
}
}
// Returning JSON string regarding the given callback and dtae
echo json_encode($data);
My AJAX call says:
function cartFilling() {
var url = 'components/com_product/views/reports/callback.php?callback=cart-filling&date='+date_scope;
jQuery.getJSON(url, function (data) {
Highcharts.chart('cartFilling', {
chart: {
zoomType: 'x'
},
title: {
text: 'Shopping Cart Filling Actions'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'Carts Filled'
},
type: 'number'
},
legend: {
enabled: false
},
plotOptions: {
area: {
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')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'area',
name: 'Cart Filling',
data: data
}]
});
});
}
So, "data" already is:
[Date.UTC(2015,6,13,16,41,5), 3],[Date.UTC(2015,7,15,16,41,5), 1],[Date.UTC(2015,8,18,16,41,5), 4],[Date.UTC(2015,9,28,16,41,5), 3],[Date.UTC(2015,10,20,16,41,5), 1],[Date.UTC(2015,10,28,16,41,5), 5],[Date.UTC(2015,11,13,16,41,5), 1],[Date.UTC(2015,11,21,16,41,5), 2],[Date.UTC(2015,11,24,16,41,5), 1],[Date.UTC(2015,11,25,16,41,5), 2],[Date.UTC(2015,11,28,16,41,5), 1],[Date.UTC(2016,0,3,16,41,5), 2],[Date.UTC(2016,0,9,16,41,5), 4],[Date.UTC(2016,0,14,16,41,5), 6],[Date.UTC(2016,0,17,16,41,5), 3],[Date.UTC(2016,0,18,16,41,5), 3],[Date.UTC(2016,0,20,16,41,5), 2],[Date.UTC(2016,0,21,16,41,5), 2],[Date.UTC(2016,0,22,16,41,5), 2],[Date.UTC(2016,0,23,16,41,5), 1],[Date.UTC(2016,0,24,16,41,5), 5],[Date.UTC(2016,0,25,13,41,5), 1],[Date.UTC(2016,0,25,16,41,0), 1],[Date.UTC(2016,0,25,16,41,5), 1],[Date.UTC(2016,0,27,16,41,5), 1],[Date.UTC(2016,0,28,16,41,5), 1],[Date.UTC(2016,0,29,16,41,5), 1],[Date.UTC(2016,1,9,16,41,5), 1],[Date.UTC(2016,1,10,16,41,5), 2],[Date.UTC(2016,1,11,16,41,5), 3],[Date.UTC(2016,1,15,16,41,5), 2],[Date.UTC(2016,1,18,16,41,5), 1],[Date.UTC(2016,1,21,16,41,5), 1],[Date.UTC(2016,1,23,16,41,5), 1],[Date.UTC(2016,1,24,16,41,5), 1],[Date.UTC(2016,1,25,16,41,5), 1],[Date.UTC(2016,1,26,16,41,5), 1],[Date.UTC(2016,1,28,16,41,5), 1],[Date.UTC(2016,2,1,16,41,5), 1],[Date.UTC(2016,2,2,16,41,5), 1],[Date.UTC(2016,2,5,16,41,5), 1],[Date.UTC(2016,2,12,16,41,5), 1],[Date.UTC(2016,2,21,16,41,5), 1],[Date.UTC(2016,3,25,16,41,5), 1],[Date.UTC(2016,4,5,16,41,5), 2],[Date.UTC(2016,4,11,16,41,5), 1],[Date.UTC(2016,4,12,16,41,5), 1],[Date.UTC(2016,4,24,16,41,5), 1],[Date.UTC(2016,4,25,16,41,5), 1],[Date.UTC(2016,5,1,16,41,5), 1],[Date.UTC(2016,5,12,16,41,5), 1],[Date.UTC(2016,5,25,10,41,5), 1],[Date.UTC(2016,5,25,16,41,5), 1],[Date.UTC(2016,6,1,10,41,5), 1],[Date.UTC(2016,6,1,16,41,5), 1],[Date.UTC(2016,6,2,16,41,5), 1],[Date.UTC(2016,6,25,16,21,5), 1],[Date.UTC(2016,6,25,16,41,5), 1],[Date.UTC(2016,7,13,16,41,5), 1],[Date.UTC(2016,7,28,16,41,5), 1],[Date.UTC(2016,8,20,16,41,5), 3],[Date.UTC(2016,8,29,16,41,5), 2],[Date.UTC(2016,9,1,14,20,18), 1],[Date.UTC(2016,9,9,14,20,18), 1],[Date.UTC(2016,9,10,14,20,18), 1],[Date.UTC(2016,9,28,14,20,18), 2],[Date.UTC(2016,9,30,14,20,18), 2],[Date.UTC(2016,10,1,13,44,29), 1],[Date.UTC(2016,10,6,8,26,18), 2],[Date.UTC(2016,10,10,13,44,29), 1],[Date.UTC(2016,10,13,13,44,29), 2],[Date.UTC(2016,10,14,19,13,42), 4],[Date.UTC(2016,10,15,23,27,39), 3],[Date.UTC(2016,11,6,19,4,6), 3],[Date.UTC(2016,11,8,10,49,28), 3],[Date.UTC(2016,11,10,23,1,44), 1],[Date.UTC(2016,11,14,21,27,44), 1],[Date.UTC(2016,11,15,23,27,44), 2],[Date.UTC(2016,11,15,23,27,53), 3],[Date.UTC(2016,11,18,18,6,28), 1],[Date.UTC(2016,11,21,20,6,28), 3],[Date.UTC(2016,11,23,20,6,20), 5],[Date.UTC(2016,11,29,20,18,18), 3],[Date.UTC(2017,0,3,20,6,32), 3]
In addition,
I've tried serialize these ways as well:
data: [data]
and
data: ([data])
The most funny part is, when I insert the generated data manually for "data:" it works. But when I call its var it does nothing. Wasted 4 days of mine!
What's wring with me? What's going on here? I'm tired of waiting, asking wrong questions, getting wrong answers and receiving negative points for my questions :( Please somebody expert in Highcharts respond otherwise I do something so bad with this Laptop!
Thank you

How to display tooltip only for last point?

I am using live random data in my chart . Here i want to display current feed value in right side of chart which will travel along with chart's last point.
I am trying to display tootip in last point which series will added dynamically. But i am unable to add tootip to last point alone.
Can anyone help me to achieve this.
Here is jsfiddle and what i am trying is
To show a tooltip you could use toolip.refresh(point).
Example: http://jsfiddle.net/a6pshutt/7/
...
setInterval(function () {
var x = (new Date()).getTime(),
y = Math.random();
len = series.data.length;
series.addPoint([x,y], false, true);
series2.data[0].update([x,y]);
tooltip.refresh(series2.data[0]); // <----------here
}, 1000);
...
To show a dataLabel you could enable it for the scatter point in your scatter series.
Example: http://jsfiddle.net/83kp2d4t/
...
events: {
load: function () {
var tooltip = this.tooltip,
series = this.series[0],
len = series.data.length;
this.addSeries({
id: 'end point',
type: 'scatter',
marker: {
enabled:true,
symbol:'circle',
radius:4,
fillColor:'white',
lineColor: 'black',
lineWidth:2
},
dataLabels:{
enabled: true // <----------here
},
data: [[
series.data[len - 1].x,
series.data[len - 1].y
]]
});
...

highcharts converting area range to multiple lines on plot

Need a hand deciphering the Highcharts methodology please.
I have input data that is a lot of records with three fields (timestamp, min, max) that I'd like to generate a plot from. Goal is to have two lines, one with max-vs-time and the other with min-vs.time, both on that one plot.
I got an arearange to work (fiddle here) but if I change the plot type to spline, I just get one line graph with min vs. time (i.e., it ignores the last data parameter).
Same thing happens when I mess with the Highcharts arearange example, so I'm guessing that my series is not defined correctly, but I'm not deciphering the right terminology to figure out how to ask the question yet I guess. Any help appreciated....
// data is timestamp,min,max for the day
// - this currently plots only the min for each day
// - intent is two lines, one for min and one for max
var data = [
[1186124400000, 57.2, 75.6],
[1186210800000, 51.8, 74.7],
[1186297200000, 53.8, 74.8],
[1186383600000, 56.7, 72.7],
[1186470000000, 59.0, 76.1]
];
var options = {
chart: {
renderTo: 'container',
type: 'arearange'
},
title: {
text: 'historical temperatures'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'outsideTemp (F)'
}
},
legend: {
enabled: false
},
series: [{
legend: {
enabled: false
},
data: data
}]
};
$(document).ready(function () {
var chart1 = new Highcharts.Chart(options)
});
You need to create two separate series.
So this:
var data = [
[1186124400000, 57.2, 75.6],
[1186210800000, 51.8, 74.7],
[1186297200000, 53.8, 74.8],
[1186383600000, 56.7, 72.7],
[1186470000000, 59.0, 76.1]
];
Will need to be two separate arrays, each with a single y value, and the same x values:
var data1 = [
[1186124400000, 57.2],
[1186210800000, 51.8],
[1186297200000, 53.8],
[1186383600000, 56.7],
[1186470000000, 59.0]
];
var data2 = [
[1186124400000, 75.6],
[1186210800000, 74.7],
[1186297200000, 74.8],
[1186383600000, 72.7],
[1186470000000, 76.1]
];
Updated Fiddle:
http://jsfiddle.net/jlbriggs/5q5HJ/12/
If your x values are at consistent intervals, you can use the pointStart and pointInterval properties and skip specifying the x values
http://api.highcharts.com/highcharts#plotOptions.series.pointStart
http://api.highcharts.com/highcharts#plotOptions.series.pointInterval

highcharts not plotting json string containing x,y pairs (string, float). how to fix?

I just switch from jqplot to highcharts, because i couldn't find an answer for my problem with jqplot.
My problem:
I want to plot the following result from a json string. this string contains out of datapairs in the following format: yyyy00kw (year with 4digits, 00 for padding, weeknumber 2digits) and a value (could be formated to float).
because the x value of the pair could change to yyyymmdd (year month day) or yyyywwdd (year week day) it has to be a string.
My json string contains the following:
[
[
["20050043",12.800000190735],
["20050044",17.39999961853],
["20050045",10.10000038147],
["20050046",5.9000000953674],
["20050048",4.6999998092651],
["20050049",9.8999996185303],
["20050050",9.1999998092651],
["20050051",8.3999996185303],
["20050052",2.0999999046326],
["20060001",2.7000000476837],
["20060002",-1.1000000238419],
["20060004",2],
["20060005",4.9000000953674],
["20060006",6.8000001907349],
["20060007",6.0999999046326],
["20060009",4.3000001907349],
["20060010",3.4000000953674],
["20060011",8.1999998092651],
["20060012",7],
["20060017",11.60000038147],
["20060018",21.60000038147],
["20060019",24.799999237061],
["20060020",16.700000762939],
["20060021",0],
["20060022",0],
["20060024",0],
["20060025",18.10000038147],
["20060026",20.200000762939],
["20060052",2.9000000953674],
["20070001",0],
["20070019",0],
["20070020",0],
["20070024",0],
["20070025",0],
["20070026",0],
["20070027",0],
["20070028",0],
["20070029",0],
["20070030",0],
["20070031",0],
["20070032",0],
["20070033",0],
["20070034",0],
["20070035",0],
["20070036",0],
["20070037",0],
["20070038",0],
["20070039",0],
["20070040",0],
["20070041",0],
["20070042",0],
["20070043",0],
["20070044",0],
["20070045",0],
["20070046",0],
["20070047",0],
["20070048",0],
["20070049",0],
["20070050",0],
["20070051",0],
["20070052",0],
["20080001",0],
["20080002",0],
["20080003",0],
["20080004",0],
["20080005",0],
["20080006",0],
["20080007",0],
["20080008",0],
["20080009",0],
["20080010",0],
["20080012",0],
["20080013",0],
["20080017",0],
["20080018",0],
["20080019",0],
["20080020",0],
["20080021",0],
["20080022",0],
["20080023",0],
["20080024",0],
["20080025",0],
["20080026",0],
["20080027",0],
["20080028",0],
["20080029",0],
["20080030",0],
["20080031",0],
["20080034",0],
["20080035",0],
["20080036",0],
["20080037",0],
["20080038",0],
["20080039",0],
["20080040",0],
["20080041",0],
["20080042",0],
["20080043",0],
["20080044",0],
["20080045",0],
["20080046",0],
["20080047",0],
["20080048",0],
["20080049",0],
["20080050",0],
["20080051",0],
["20080052",0],
["20090001",0],
["20090002",0],
["20090003",0],
["20090004",0],
["20090005",0],
["20090006",0],
["20090024",0],
["20090025",0],
["20090026",0],
["20090028",0],
["20090029",0],
["20090030",0],
["20090031",0],
["20090032",0],
["20090033",0],
["20090034",0],
["20090035",0],
["20090036",0],
["20090037",0],
["20090038",0],
["20090039",0],
["20090040",0],
["20090041",0],
["20090042",0],
["20090043",0],
["20090044",0],
["20090045",0],
["20090046",0],
["20090047",0],
["20090048",0],
["20090049",0],
["20090050",0],
["20090051",0],
["20090052",0],
["20090053",0],
["20100001",0],
["20100002",0],
["20100003",0],
["20100004",0],
["20100005",0],
["20100006",0],
["20100007",0],
["20100008",0],
["20100009",0],
["20100010",0],
["20100011",0],
["20100012",0],
["20100013",0],
["20100014",0],
["20100015",0],
["20100016",0],
["20100017",0],
["20100018",0],
["20100019",0],
["20100020",0],
["20100021",0],
["20100022",0],
["20100023",0],
["20100024",0],
["20100025",0],
["20100026",0],
["20100027",0],
["20100028",0],
["20100029",0],
["20100030",0],
["20100031",0],
["20100032",0],
["20100033",0],
["20100034",0],
["20100035",0],
["20100036",0],
["20100037",0],
["20100038",0],
["20100039",0],
["20100040",0],
["20100041",0],
["20100042",0],
["20100043",0],
["20100044",0],
["20100045",0],
["20100046",0],
["20100047",0],
["20100048",0],
["20100049",0],
["20100050",0],
["20100051",0],
["20100052",0],
["20100053",0],
["20110001",0],
["20110002",0],
["20110003",0],
["20110004",0],
["20110005",0],
["20110006",0],
["20110007",0],
["20110008",0],
["20110009",0],
["20110010",0],
["20110014",0],
["20110015",0],
["20110016",0],
["20110017",0],
["20110018",0],
["20110019",0],
["20110020",0],
["20110021",0],
["20110022",0],
["20110023",0],
["20110024",0],
["20110025",0],
["20110026",0],
["20110027",0],
["20110028",0],
["20110029",0],
["20110030",0],
["20110031",0],
["20110032",0],
["20110033",0],
["20110034",0],
["20110035",0],
["20110036",0],
["20110039",0],
["20110043",0],
["20110044",0],
["20110045",0],
["20110046",0],
["20110047",0],
["20110048",0],
["20110049",0],
["20110052",0],
["20120001",0],
["20120002",0],
["20120003",0],
["20120004",0],
["20120005",0],
["20120006",0],
["20120007",0],
["20120009",0],
["20120010",0],
["20120013",0],
["20120014",0],
["20120015",0],
["20120016",0],
["20120017",0]
]
]
Here is my javascript code:
<script class="code" type="text/javascript">
var data = [];
var chart;
$(document).ready(function() {
//hier geht es los
$.getJSON("120925_sql_bauen.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'chart1',
type: 'line'
},
title: {
text: 'Wetterdatenprojekt'
},
xAxis: {
//categories: []
},
yAxis: {
title: {
text: 'aktuelle Wetterwerte'
},
plotLines: [{
value: 0,
width: 1
}]
},
series: json
});
});
});
</script>
Unfortunately highcharts shows no plot.
I hope, that highcharts doesn't have the same problem with strings then jqplot :-(
The problem is that you try to use your reply directly. You need to "remove" one layer of arrays. That is data should be json[0]
I updated my example: http://jsfiddle.net/GgNmY/2/
Regarding previous note that values should be numeric is only true for Y-axis (at least in earlier versions of Highcharts).
Edit: Here is to extract the data point (the values) and the categories.
var data = [];
var cats = [];
json[0].forEach(function(point){
data.push(point[1]);
cats.push(point[0]);
});
Here is an running example: http://jsfiddle.net/GgNmY/3/
In Highchart, you can set your series : data object in the form of the JSON input.
In such a case, if the JSON input is in the form:
[
[1,12],
[2,5],
[3,18],
....
[10,22]
]
Then the following attribute can be added in the chart definition:
series:[{
data: json
}]
Here is the running JSFiddle example

Resources