Wednesday 15 April 2015

javascript - Dynamically generated StockChart - Form -> Checkboxes = generate my chart -



javascript - Dynamically generated StockChart - Form -> Checkboxes = generate my chart -

this illustration of working multi-line stock chart. 1 little problem - date moved -1 day somehow comparing mysql result ( not point ).

i wanted create dynamic stock generator supplied form. form has checkboxes allows pick series want generated.

#questions & problems #1 php side : ok lets picked checkbox 1 , 3. need post them generator file right? within generator file there

if($_post['gen_fields'] == 1){ $return['name'] = 'zwroty'; foreach ($result $row) { $date =strtotime($row['date'])*1000; $return['data'][] = array($date, (int)$row['totalcount']); // $return[] = } }

well tried seems not been working somehow. lets move on js question.

#2 js side : javascript wise somehow hard accomplish has if statement : if checked checkbox 1 add together series. if no series selected error or add together 3.

second option saw dynamic foreach series scripts on net seems wasn't working generator because had no if $_get's

<form id="form_gen" method="post" class="bootstrap-frm" style="max-width: 100% !important;"> <label> <span>parameters</span> <input type="checkbox" name="gen_fields" value="1"> zwroty <input type="checkbox" name="gen_fields" value="2"> doręczenia <input type="checkbox" name="gen_fields" value="3"> w doręczeniu </label> <label> <span>&nbsp;</span> <input type="button" value="generate" class="add-button" onclick="form_gen()"> </label> </form>

js section

function form_gen() { $('#form_gen').form('submit', { url: 'api/stockchart.php', onsubmit: function() { }, beforesend: function() { }, success: function(result) { $.getjson('api/stockchart.php', function(json) { // create chart $('#as').highcharts('stockchart', { rangeselector: { selected: 1 }, title: { text: 'wpisów dziennie' }, yaxis: { title: { text: 'ilość' }, plotlines: [{}] }, series: [{ name: 'zwroty', color: '#4572a7', type: 'column', // yaxis: 1, data: json[1].data }, { name: 'doręczenia', color: '#45cca7', type: 'column', // yaxis: 1, data: json[2].data }, { name: 'w doręczeniu', color: '#89a54e', type: 'spline', data: json[0].data }] }); }); } }); }

the php generator

seek { $sth = $db->prepare("select date(date) date, count(number) totalcount numbers grouping date(date)"); $sth->execute(); $result = $sth->fetchall(); $sth = $db->prepare("select date(rdate) date, count(number) totalcount numbers `return` = 2 , rdate != '0000-00-00 00:00:00' grouping date(rdate)"); $sth->execute(); $returna = $sth->fetchall(); $sth = $db->prepare("select date(rdate) date, count(number) totalcount numbers `return` = 1 , rdate != '0000-00-00 00:00:00' grouping date(rdate)"); $sth->execute(); $returnb = $sth->fetchall(); /* fetch of remaining rows in result set */ // print("fetch of remaining rows in result set:\n"); } catch(pdoexception $ex){ die("failed run query: " . $ex->getmessage());} try{ $return['name'] = 'zwroty'; foreach ($result $row) { $date =strtotime($row['date'])*1000; $return['data'][] = array($date, (int)$row['totalcount']); // $return[] = } } catch(pdoexception $ex){ die("failed run query: " . $ex->getmessage());} try{ $return1['name'] = 'w doręczeniu'; foreach ($returna $row1) { $date1 =strtotime($row1['date'])*1000; $return1['data'][] = array($date1, (int)$row1['totalcount']); // $return[] = } } catch(pdoexception $ex){ die("failed run query: " . $ex->getmessage());} try{ $return2['name'] = 'doręczony'; foreach ($returnb $row2) { $date2 =strtotime($row2['date'])*1000; $return2['data'][] = array($date2, (int)$row2['totalcount']); // $return[] = } } catch(pdoexception $ex){ die("failed run query: " . $ex->getmessage());} $result = array(); array_push($result,$return); array_push($result,$return1); array_push($result,$return2); echo json_encode($result,true);

javascript php jquery mysql highcharts

No comments:

Post a Comment