May be really basic question:
I'm playing with highcharts with two series, one represented with line and other with column, data is loaded using json, the problem is in how to tell highcharts one serie should be represented with line and the other with column type, like this
The problem (for me) comes when Series options in json mode of highcharts are only like this:
},
series: json
});
whilst in "normal mode" you can set for example:
series: [{
**type: 'column',**
name: 'Name',
data: [],
},{
type: 'spline',
name: 'Max Pax',
data: [],
draggableY: true,
dragMinY: 0,
dragMaxY: 200,
.......
Am I missing something?
php code that retrives data from db:
$con = mysql_connect("localhost", "*******","*******");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wordpress_8", $con);
$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';
while($r = mysql_fetch_array($sth)) {
$rows['data'][] = $r['a1300'];
$rows['data'][] = $r['a1315'];
$rows['data'][] = $r['a1330'];
$rows['data'][] = $r['a1345'];
}
$sth = mysql_query("SELECT overhead FROM projections_sample");
$rows1 = array();
$rows1['name'] = 'Overhead';
while($rr = mysql_fetch_assoc($sth)) {
$rows1['data'][] = $rr['overhead'];
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
print json_encode($result, JSON_NUMERIC_CHECK);
Output looks like:
[{"name":"MaxPax","data":[40,19,40,21]},{"name":"Overhead","data": [21990,22365,21987,22369,22558,22987,23521,23003,22756,23112,22987,22897]}]
You need to define this parameter in JSON, or parse your json after receive, and set this paraemter, then use in Highcharts.
EDIT:
You can replace this lines
$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';
with
$sth = mysql_query("SELECT * FROM wp_maxpax_A where fecha='12/11/2013' ");
$rows = array();
$rows['name'] = 'MaxPax';
$rows['type'] = 'line';
Similar in next series.
Second solution is push type after getting json like:
$getJSON('path/to/json',function(data){
data[0].type='column';
data[1].type='line';
var options = {
// your options
series: data
};
$('#container').highcharts(options);
});
Related
Pimcore has powerfull plugin DataDirector for import automation.
It proposes manual configuration of fields to import and their mapping to Pimcore fields https://www.youtube.com/watch?v=nyhKJTzTq-4&list=PL4-QRNfdsdKIfzQIP-c9hRruXf0r48fjt
It works fine if you have 10-50 fields.
How to import that configuration from some csv file whan you have 700+ fields?
There is no ability to import using interface of commandline DataDirector API.
I tried to request such functionality creation from vendor -- it costs.
I tried to edit it in MySQL but it is strictly coupled to other data, see: SELECT sourceconfig FROM plugin_pim_dataport;
Solution:
Each dataport can be exported and imported to JSON. This is our chance.
create sample dataport using your source XML
export it to sample.json
unserialize $json_a['plugin_pim_dataport']['sourceconfig'] and $json_a['plugin_pim_rawitemField'] containers
$string = file_get_contents(
"sample.json"
);
$json_a = json_decode($string, true);
$sourceConfig = $json_a['plugin_pim_dataport']['sourceconfig'];
$sourceConfig = unserialize($sourceConfig, ['allowed_classes' => false]);
$fieldsConfig = $json_a['plugin_pim_rawitemField'];
add new fields to them from any source e.g. CSV
while (($data = fgetcsv($handle, 1000, ",")) !== false) {
$row++;
$id = $max + 1 + $row;
$data = $this->addField($id, $data[0], $data[1]);
$sourceConfig['fields']['field_' . ($id + 1)] = $data['sourceConfig'];
$fieldsConfig[$id] = $data['fieldsConfig'];
}
public function addField(
$id,
$name = 'ObjectBrick/Field',
$xpath = '//*[.//MainContainer = "systeme"]//*[.//Description = "SomeAttribute"]/anyPath/SampleContainer'
) {
$res = [];
$res['fieldsConfig'] = [
"dataportId" => "1",
"fieldNo" => $id + 1,
"name" => $name,
"priority" => $id
];
$res['sourceConfig'] = [
'xpath' => $xpath,
'multiValues' => false,
];
return $res;
}
serialize, save to JSON, import to your dataport.
How can i get rank or position base highest ' gpa' and 'total' into database rows data in codeigniter?
public function fetchData() {
$data = array();
$data['fetch_data'] = $this->excel_data_insert_model->fetch_data();
$result = $data['fetch_data']->result();
foreach ($result as $row) {
//echo $row.'<br/>';
$id = $row->id;
$p_student_id = $row->stu_id;
$p_section = $row->section;
$p_gpa = $row->gpa;
$p_total = $row->total;
$x = 0;
}
}
My Answer to your raw query could be this:
Select column_name1, column_name2, MAX(gpa),MAX(total) from tbl_v1 ORDER by gpa, total desc
Also for CI
$query=$this->db->select('column_name1, column_name2, MAX(gpa),MAX(total)')->order_by('gpa,total','desc')->get('tbl_v1');
return $query;
I would like to ask how to add the customized line into chart by using jpgraph. For example, to identify SUNDAY on date which selecting from database, the jpgraph will draw a straight line with red color on each Sunday which will be showed on x-axis.
Does anyone meet the related issue and has been solved? Please tell me, thank you.
The code of my situation:
`
$dateLocale = new DateLocale();
$dateLocale->Set('');
$file_date = date("Ymd");
$dateArray = array();
$dataSuccessful = array(); //get from db
$dataUser_not_found = array();
$dataAcc_not_activated = array();
$dataUnsuccess_others = array();
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "example";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$dateArray[] = date("d/m/Y (D)", strtotime($row["date"]));
$dataSuccessful[] = $row["login_success_count"];
$dataUser_not_found[] = $row["unsuccess_not_found"];
$dataAcc_not_activated[] = $row["unsuccess_not_activated"];
$dataUnsuccess_others[] = $row["unsuccess_others"];
}
} else {
echo "No results in this table";
}
function strBefore($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, 0, $pos));
}
}
function strAfter($string, $substring) {
$pos = strpos($string, $substring);
if($pos === false){
return $string;
}else{
return(substr($string, $pos+strlen($substring)));
}
}
JpgraphError::SetImageFlag(false);
JpGraphError::SetLogFile('syslog');
// Create the graph.
$graph = new Graph(2560, 1320);
//initialization of the default theme
$graph->ClearTheme();
//$graph->SetScale('datlin',0,$x_max);
$graph->SetScale('datlin');
$graph->img->SetMargin(60,150,50,60);
$graph->SetShadow();
// Create the linear plot (SUCCESSFUL)
$l1plot=new LinePlot($dataSuccessful);
$l1plot->SetColor('lightblue:0.4');
$l1plot->SetFillColor("lightblue:0.7");
$l1plot->SetWeight(2);
$l1plot->SetLegend('The total number of visit (SUCCESSFUL)');
// Create the linear plot (UNSUCCESSFUL)
$user_not_found_plot = new LinePlot($dataUser_not_found);
$user_not_found_plot->SetColor('orange:1.2');
$user_not_found_plot->SetFillColor('orange#0.2');
$user_not_found_plot->SetLegend('(UNSUCCESSFUL) User not found');
$acc_not_activated_plot = new LinePlot($dataAcc_not_activated);
$acc_not_activated_plot->SetColor('green:0.8');
$acc_not_activated_plot->SetFillColor('green#0.4');
$acc_not_activated_plot->SetLegend('(UNSUCCESSFUL) Account not activated');
$others_plot = new LinePlot($dataUnsuccess_others);
$others_plot->SetColor('lightred:1.2');
$others_plot->SetFillColor('lightred#0.4');
$others_plot->SetLegend('(UNSUCCESSFUL) Others');
$graph->title->Set('log report');
$graph->xaxis->title->Set('Last 30 days');
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->setYScale(0, 'lin', 0, 2000);
/* Add the plots to the graph */
//SUCCESSFUL numbers
$graph->Add($l1plot);
//UNSUCCESSFUL numbers
$graph->AddY(0,$user_not_found_plot);
$graph->AddY(0,$acc_not_activated_plot);
$graph->AddY(0,$others_plot);
$graph->ynaxis[0]->SetColor('red');
$graph->ynaxis[0]->title->Set('The number of visit (UNSUCCESSFUL)');
$graph->ynaxis[0]->scale->SetGrace(80);
//As demo, set the specific date on x-axis
$graph->xaxis->SetLabelFormatString('d/m/Y',true);
$graph->xaxis->setTickLabels($dateArray);
// Display the graph
// Get the handler to prevent the library from sending the image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Default is PNG so use ".png" as suffix
$fileName = "pic/oul207_log_".$file_date.".png";
$graph->img->Stream($fileName);
?>`
I guess you don't want a tick, so here's how to add a red vertical line:
require_once ('jpgraph/jpgraph_plotline.php');
$v_plot = new PlotLine();
$v_plot->SetDirection(VERTICAL);
$v_plot->SetColor('red');
$v_plot->SetPosition(2);
$graph->AddLine($v_plot);
Of course you'd need to calculate your sunday(s) relative to the x-axis and set the position(s) accordingly.
Let's say I am building a search that finds all the teacher and got an input where the user can put in the search term. I tried reading the phalcon documentation but I only see things like binding parameters. I read the other thread about needing prepare statements do I need that in Phalcon as well?
And my function in the model would be something like this:
public function findTeachers($q, $userId, $isUser, $page, $limit, $sort)
{
$sql = 'SELECT id FROM tags WHERE name LIKE "%' . $q . '%"';
$result = new Resultset(null, $this,
$this->getReadConnection()->query($sql, array()));
$tagResult = $result->toArray();
$tagList = array();
foreach ($tagResult as $key => $value) {
$tagList[] = $value['id'];
....
}
}
My question is for the Phalcon framework is there any settings or formats I should code for this line $sql = 'SELECT id FROM tags WHERE name LIKE "%' . $q . '%"';
And also any general recommendation for preventing SQL Injection in PhalconPHP controllers and index would be appreciated.
For reference:
My controller:
public function searchAction()
{
$this->view->disable();
$q = $this->request->get("q");
$sort = $this->request->get("sort");
$searchUserModel = new SearchUsers();
$loginUser = $this->component->user->getSessionUser();
if (!$loginUser) {
$loginUser = new stdClass;
$loginUser->id = '';
}
$page = $this->request->get("page");
$limit = 2;
if (!$page){
$page = 1;
}
$list = $searchUserModel->findTeachers($q, $loginUser->id, ($loginUser->id)?true:false, $page, $limit, $sort);
if ($list){
$list['status'] = true;
}
echo json_encode($list);
}
My Ajax:
function(cb){
$.ajax({
url: '/search/search?q=' + mapObject.q + '&sort=<?php echo $sort;?>' + '&page=' + mapObject.page,
data:{},
success: function(res) {
//console.log(res);
var result = JSON.parse(res);
if (!result.status){
return cb(null, result.list);
}else{
return cb(null, []);
}
},
error: function(xhr, ajaxOptions, thrownError) {
cb(null, []);
}
});
with q being the user's search term.
You should bind the query parameter to avoid an SQL injection. From what I can remember Phalcon can be a bit funny with putting the '%' wildcard in the conditions value so I put them in the bind.
This would be better than just filtering the query.
$tags = Tags::find([
'conditions' => 'name LIKE :name:',
'bind' => [
'name' => "%" . $q . "%"
]
])
Phalcon\Filter is helpful when interacting with the database.
In your controller you can say, remove everything except letters and numbers from $q.
$q = $this->request->get("q");
$q = $this->filter->sanitize($q, 'alphanum');
The shortest way for requests:
$q = $this->request->get('q', 'alphanum');
I've a little problem, I need to do a curve with on y axis numbers and x axis dates.. but I can't display some dates...
My code :
<script type="text/javascript">
$(function () {
<?php
echo " var data = [";
$cpt="0";
include ('../connect.php');
// Requete SQL
$req = 'select "SPP_NB_IND" from "STAT_PERPHY" where "SPP_SAGES" = \''.$sages.'\' AND "SPP_DATE" between \''.$jourtableau.' 00:00:00\' and \''.$jourfinw.' 23:59:59\'';
$res = pg_query($req);
$reqd = 'select "SPP_DATE" from "STAT_PERPHY" where "SPP_SAGES" = \''.$sages.'\' AND "SPP_DATE" between \''.$jourtableau.' 00:00:00\' and \''.$jourfinw.' 23:59:59\' AND "SPP_NB_IND" IS NOT NULL ';
$resd = pg_query($reqd);
// On met les valeurs obtenues dans un tableau
while ( $row = pg_fetch_assoc ($res) )
{
//echo $row['SPP_NB_IND']."<br>";
$var=$row['SPP_NB_IND'];
while ( $roww = pg_fetch_assoc ($resd) )
{
$abscisse=date('d-m', strtotime($roww['SPP_DATE']));
}
echo "[$abscisse, $var],";
$cpt++;
}
echo "];";
?>
var options = {
lines: {
show: true
},
points: { show: true
},
xaxis: {
mode: "time",
timeformat : "%d/%m"
}
};
<?php
echo "$.plot($(\"#graph1\"), [ data ], options);";
?>
});
</script>
[/CODE]
When I put $abscisse, my curve is vertical and if I put $cpt, I have a "normal" curve... but I want to see dates corresponding with numbers..
Freindly,
Tanaes.
See the documentation:
You have to give flot timestamps, not already formated dates. For PHP use something like
$abscisse = strtotime($roww['SPP_DATE']) * 1000;