Monday 15 February 2010

php - Highstock - Two data series from mysql query -


I created a mysql query that outputs two sets of statistics for "visits" and visitors "

?  & lt; php $ thief = mysql_connect ("localhost", "name", "pass"); if ($ thief!) {Dead ('could not connect:' mysql_error (). );} mysql_select_db ( "fandang_gvmaster", $ con); select $ sth = mysql_query ( "visit the Unixdate, WebWeekly where (` Unixdate` & gt; 1299456000000) and ( `Unixdate` or & lt 1000 * UNIX_TIMESTAMP (NOW {$ R = mysql_fetch_array ($ sth)) {$ line ['data'] [] = $ ($) $ '$' ['name'] = 'visit'; $ lines $ Array [] '$' R ['vis K '];} Select $ sth = mysql_query ( "Unixdate, visitors WebWeekly where (` Unixdate` & gt; 1299456000000) and ( `Unixdate` or & lt 1000 * UNIX_TIMESTAMP (NOW ()));"); $ Rowsl = array (); $ rows1 [ 'name'] = 'visitors' while ($ r = mysql_fetch_assoc ($ sth)) {$ rows1 [ 'data'] [] = $ r [ 'visitors'] ;} $ Result = array (); array_push ($ result, $ rows); Array_push ($ result, $ line1); Print Jason_ANDD ($ Consequence, JSONAAAFACK); Mysql_close ($ cum n); ? & Gt;   

This gives me the following output:

[{"name": "visit", "data": [29, 3, 31, 287]}, "<"> "Data": "Visitor", "Data": [157,167,157]}]

I then set a Highstock graph to read data :

  $ (function () {var seriesOptions = [], yAxisOptions = [], series count = 0, name = [ 'visits', 'visitor'] color = Highcharts.getOptions (). Colors; $ .each, function (i, name) {$ .getJSON ( 'calc_tables / Allyears_calc.php', function (data) {seriesOptions [i] = {name: name, data data}; // As we do the data incomprehensible Loading from, we do not know which order it will reach, so // we keep a counter and create charts when all the data is loaded. SeriesCounter ++; if (chain count == names.length) { createChart ();}});}); // chart when all the data is loaded function createChart () {$ ( '# graphcontainerslide') make Highcharts ( 'StockChart', {chart :. {}, rangeSelector: { Selected: 4}, yAxis: {Label: {Formatter: function () {Return (ths Is.value & gt; 0? '+': '') + This.value + '%'; }}, Plotlines: [{value: 0, width: 2, color: 'silver'}}}, plot option: {series: {comparison: 'percent'}}, tooltip: {pointFormat: '& lt; Span style = "color: {series.color}" & gt; {Series.name} & lt; / Span & gt;: & lt; B & gt; {Point.y} & lt; / B & gt; ({Point.change}%) & lt; Br / & gt; ', PriceDiskimals: 2}, Series: Series Option}); }}); I am actually learning because I go along with me, but I can not get it to do this work - I know that I am feeding this information wrongly. Can someone give me an indicator?   

This is incorrect, because in your data, you get the chain structure (it is clear), There is no data but you run the

  chain option [i] = {name: name, data: data};   

So that you try to set chain objects to chain composition, which you have defined. As a result you can get:

  chainoption [i] = {name: name, data: [{":": "visit", "data": [29, 3, 31 , 287]}, {"name": "visitor", "data": [157,167,157]}]}};   

Try to use data in the chain object such as:

  chain: data    

No comments:

Post a Comment