Google chart shows dots not line chart - charts
Working on my line chart and very confused why it shows dots and not lines between the dots. So hope someone can help me with my problem. Thanks!
Google chart code, I can paste the whole code with sql query and so if needed:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
Temperatur = document.getElementById('Temperatur'),
Badende_Per_Time = document.getElementById('Badende_Per_Time'),
Luft_Temperatur = document.getElementById('Luft_Temperatur');
FrittKlor = document.getElementById('FrittKlor');
BundetKlor = document.getElementById('BundetKlor');
TotalKlor = document.getElementById('TotalKlor');
PH = document.getElementById('PH');
AutoKlor = document.getElementById('AutoKlor');
AutoPh = document.getElementById('AutoPh');
AutoTemperatur = document.getElementById('AutoTemperatur');
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
Temperatur.onchange = drawChart;
Badende_Per_Time.onchange = drawChart;
Luft_Temperatur.onchange = drawChart;
FrittKlor.onchange = drawChart;
BundetKlor.onchange = drawChart;
TotalKlor.onchange = drawChart;
PH.onchange = drawChart;
AutoKlor.onchange = drawChart;
AutoPh.onchange = drawChart;
AutoTemperatur.onchange = drawChart;
function drawChart() {
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
width: 1100, height: 520,
title: 'Diagram',
curveType: 'function',
legend: { position: 'bottom' },
pointSize: 5,
vAxis: {title: "Verdi", titleTextStyle: {italic: false}},
hAxis: {title: "Tid", titleTextStyle: {italic: false}},
explorer: { actions: ['dragToZoom', 'rightClickToReset'],
axis: 'both' },
focusTarget: 'category',
};
if (!AutoTemperatur.checked) data.removeColumn(10);
if (!AutoPh.checked) data.removeColumn(9);
if (!AutoKlor.checked) data.removeColumn(8);
if (!PH.checked) data.removeColumn(7);
if (!TotalKlor.checked) data.removeColumn(6);
if (!BundetKlor.checked) data.removeColumn(5);
if (!FrittKlor.checked) data.removeColumn(4);
if (!Luft_Temperatur.checked) data.removeColumn(3);
if (!Badende_Per_Time.checked) data.removeColumn(2);
if (!Temperatur.checked) data.removeColumn(1);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
Code:
$sth = sqlsrv_query($conn,"
SELECT routines.date, routines.time,
SUM( CASE WHEN measurements.title = 'T_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Temperatur,
SUM( CASE WHEN measurements.title = 'T_Badende_per_Time' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Badende_Per_Time,
SUM( CASE WHEN measurements.title = 'T_Luft_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Luft_Temperatur,
SUM( CASE WHEN measurements.title = 'M_Fritt_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS FrittKlor,
SUM( CASE WHEN measurements.title = 'M_Bundet_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS BundetKlor,
SUM( CASE WHEN measurements.title = 'M_Total_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS TotalKlor,
SUM( CASE WHEN measurements.title = 'M_PH' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS PH,
SUM( CASE WHEN measurements.title = 'M_Auto_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoKlor,
SUM( CASE WHEN measurements.title = 'M_Auto_PH' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoPh,
SUM( CASE WHEN measurements.title = 'A_Auto_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoTemperatur
FROM routines
INNER JOIN measure_routine ON routines.id = measure_routine.routine_id
INNER JOIN measurements ON measure_routine.measure_id = measurements.id
INNER JOIN pools ON measure_routine.pool_id = pools.id
WHERE routines.date between '".$fraDato."' AND '".$tilDato."'
AND (pools.name = '".$basseng."' OR pools.name = 'Svommehall')
AND routines.time between '".$fraTid."' AND '".$tilTid."'
GROUP BY routines.date, routines.time
ORDER BY routines.date, routines.time;
;");
if( $sth === false ) {
die( print_r( sqlsrv_errors(), true));
}
$rows = array();
$flag = true;
$table = array();
$table['cols'] = array(
array('label' => 'routines.date' & 'routines.time', 'type' => 'datetime'),
array('label' => 'Temperatur', 'type' => 'number'),
array('label' => 'Badende_Per_Time', 'type' => 'number'),
array('label' => 'Luft_Temperatur', 'type' => 'number'),
array('label' => 'FrittKlor', 'type' => 'number'),
array('label' => 'BundetKlor', 'type' => 'number'),
array('label' => 'TotalKlor', 'type' => 'number'),
array('label' => 'PH', 'type' => 'number'),
array('label' => 'AutoKlor', 'type' => 'number'),
array('label' => 'AutoPh', 'type' => 'number'),
array('label' => 'AutoTemperatur', 'type' => 'number'),
);
$rows = array();
while($r = sqlsrv_fetch_array ($sth))
{
//$temp = array();
// assumes dates are in the format "yyyy-MM-dd"
$dateString = $r['date'];
$year = $dateString->format('Y');
$month = $dateString->format('m') -1;
$day = $dateString->format('d');
// assumes time is in the format "hh:mm:ss"
$timeString = $r['time'];
$hours = $timeString->format('G');
$minutes = $timeString->format('i');
$seconds = $timeString->format('s');
$temp = array();
$temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)");
$temp[] = array('v' => $r['Temperatur']);
$temp[] = array('v' => $r['Badende_Per_Time']);
$temp[] = array('v' => $r['Luft_Temperatur']);
$temp[] = array('v' => $r['FrittKlor']);
$temp[] = array('v' => $r['BundetKlor']);
$temp[] = array('v' => $r['TotalKlor']);
$temp[] = array('v' => $r['PH']);
$temp[] = array('v' => $r['AutoKlor']);
$temp[] = array('v' => $r['AutoPh']);
$temp[] = array('v' => $r['AutoTemperatur']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table, JSON_NUMERIC_CHECK);
//echo $jsonTable;
$jsonTable:
00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 6, 00, 00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 7, 58, 33)"},{"v":null},{"v":null},{"v":null},{"v":1.94},{"v":0.39},{"v":2.33},{"v":7.19},{"v":2.13},{"v":7.05},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 7, 59, 39)"},{"v":28.1},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 7, 59, 59)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 8, 01, 04)"},{"v":null},{"v":null},{"v":27.8},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 8, 02, 20)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 8, 40, 20)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 9, 30, 18)"},{"v":null},{"v":33},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 9, 59, 59)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.44}]},{"c":[{"v":"Date(2014, 4, 08, 10, 38, 34)"},{"v":null},{"v":36},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 11, 23, 02)"},{"v":null},{"v":null},{"v":null},{"v":1.94},{"v":0.39},{"v":2.33},{"v":7.21},{"v":2.15},{"v":7.08},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 11, 36, 40)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 12, 00, 00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.44}]},{"c":[{"v":"Date(2014, 4, 08, 12, 30, 40)"},{"v":null},{"v":6},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 13, 33, 47)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 22, 46)"},{"v":null},{"v":null},{"v":null},{"v":1.99},{"v":0.29},{"v":2.28},{"v":7.22},{"v":2.1},{"v":7.01},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 26, 30)"},{"v":null},{"v":3},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 39, 00)"},{"v":28.2},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 41, 53)"},{"v":null},{"v":null},{"v":26.7},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 15, 45, 49)"},{"v":null},{"v":17},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 16, 34, 38)"},{"v":null},{"v":38},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 17, 16, 13)"},{"v":null},{"v":null},{"v":null},{"v":1.89},{"v":0.44},{"v":2.33},{"v":7.17},{"v":2.08},{"v":7.08},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 17, 24, 04)"},{"v":null},{"v":62},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]}]}
From asgallant's comment:
From what I've been able to tease out of your data, your data points have null values in between them, which breaks the line in the charts by default. You can override this by setting the chart's interpolateNulls option to true.
1.You can use data.sort([{column: 0}]); for sorting it based on x-axis, Here column:0 indicatesx-axis.
google chart doc for sorting
2.If the value you are trying to pass is through some xml or json and it has null values inside, It will not plot properly and will be scattered or as dotted lines in line graph so to plot them, have a condition to remove all null values and then it will plot correctly.
Related
Start and end date of previous quarter in perl
I am new to Perl and I am trying to figure out how to get the start and end date of the previous quarter. For example: Jan 2nd, 2020 - The output should be 20191001, 20191231 July 27th, 2020 - The output should be 20200401, 20200630 Thanks in advance for all the help and guidance.
use DateTime qw( ); my $prev_quarter_start = DateTime ->now( time_zone => 'local' ) ->set_time_zone('floating') # Use this when dealing with dates. ->truncate( to => 'quarter' ) ->subtract( months => 3 ); my $prev_quarter_end = $prev_quarter_start ->clone ->add( months => 3 ) ->subtract( days => 1 ); say $prev_quarter_start ->ymd(''); say $prev_quarter_end->ymd(''); Requires DateTime 1.32.
Get last business day factoring in holidays in Powershell
I have the following Powershell script that works fine to get the last business/working days, however I am trying to factor in (US) holidays. Can that be done by improving the following script? $DateOffset = If ((get-date).dayofweek.value__ -eq 1) {-3} Else {-1}
You could do something like this: function Get-LastBusinessDay { [CmdletBinding()] param ( [Parameter(Position = 1)] [System.DateTime]$Date = [System.DateTime]::Today, [Parameter(Position = 2)] [System.DateTime[]]$Holidays ); $Weekends = #([System.DayOfWeek]::Saturday, [System.DayOfWeek]::Sunday); $LastBusinessDay = $Date.AddDays(-1); while (($LastBusinessDay.DayOfWeek -in $Weekends) -or ($LastBusinessDay.Date -in $Holidays)) { $LastBusinessDay = $LastBusinessDay.AddDays(-1); } return $LastBusinessDay; } $HolidayTable = #( # 2018 US Federal Holidays 'January 1, 2018', 'January 15, 2018', 'February 19, 2018', 'May 28, 2018', 'July 4, 2018', 'September 3, 2018', 'October 8, 2018', 'November 12, 2018', 'November 22, 2018', 'December 25, 2018' ); Get-LastBusinessDay -Date '2018-12-26' -Holidays $HolidayTable # Returns December 24 Get-LastBusinessDay -Date '2018-09-04' -Holidays $HolidayTable # Returns Aug 31 The list of holidays can come from anywhere.
Holidays can be difficult to work with when calculating workdays. I use a script from Alan Kaplan that pulls holidays from TimeAndDate.com for any year and any country as PowerShell object. With that, it should be easy to adjust the calculation as needed. #Example. Get US National Holidays for 2015, display in two columns with Holiday and Date with day. $holidays =Get-Holidays 2015 #$holidays now is an object with the holidays for 2015, which you can manipulate $holidays | where {$_.type -like "National Holiday"} | select #{Name="Holiday"; Expression = {$_.holidayName}}, #{Name="Date"; Expression = {Get-Date($_.date) -format D}} | ft -AutoSize
Perl DateTime "is_dst()" method not working correctly
I'm trying to use the is_dst() method in the DateTime module to determine whether a daylight savings transition is occurring. I started by writing a very basic example that I was sure would work, but for some reason I'm getting unexpected results. Example: #!/usr/bin/perl use strict; use warnings; use DateTime; my $dt1 = DateTime->new( 'year' => 2015, 'month' => 3 , 'day' => 8 , 'hour' => 3 , ); my $dt2 = DateTime->new( 'year' => 2015, 'month' => 3 , 'day' => 7 , 'hour' => 3 , ); print $dt1."\n"; print $dt2."\n"; print $dt1->is_dst()."\n"; print $dt2->is_dst()."\n"; I started with a date that I knew was a daylight savings transition: Sunday, March 8, 2015. I chose 3 AM because I knew that the daylight savings transition would have already occured at that point in time. Then I took a date that I knew was before the daylight savings transition: Saturday, March 7, 2015 also at 3 AM. Then I print the two dates and their corresponding DST flags. Output: 2015-03-08T03:00:00 2015-03-07T03:00:00 0 0 The two dates print exactly as expected, but for some reason even though the first date occurs during daylight savings time, and the second date occurs before daylight savings time, the DST flag is not set for both of them. Why is this not working correctly? Am I missing something?
You have to explicitly set the time zone: The default time zone for new DateTime objects, except where stated otherwise, is the "floating" time zone...A floating datetime is one which is not anchored to any particular time zone. For example: use strict; use warnings; use DateTime; my $dt1 = DateTime->new( 'year' => 2015, 'month' => 3, 'day' => 8, 'hour' => 3, 'time_zone' => 'America/New_York' ); my $dt2 = DateTime->new( 'year' => 2015, 'month' => 3, 'day' => 7, 'hour' => 3, 'time_zone' => 'America/New_York' ); print $dt1."\n"; print $dt2."\n"; print $dt1->is_dst()."\n"; print $dt2->is_dst()."\n"; Output: 2015-03-08T03:00:00 2015-03-07T03:00:00 1 0
LINQ query on timestamp between 22:30 and 1:00
I am trying to use LINQ to get a list of entities where the timestamp falls between either 22:30 - 24:00 or 00:00 - 1:00 on a saturday or sunday and I am looking to set both timeframes in the one LINQ query but I have been unable to do so and have had to break it up as follows: weekdayNight = intervalInformations.Where(ii => ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(23, 30, 0) && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday && !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString())) .OrderBy(ii => ii.IntervalPeriodTimestamp) .ToList(); weekdayNight2 = intervalInformations.Where(ii => ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(0, 0, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0) && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday && !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString())) .OrderBy(ii => ii.IntervalPeriodTimestamp) .ToList(); weekdayNight.Add(weekdayNight2); How can I write this query without needing to join two different queries
Adding an OR between the two conditions defining time intervals should do the trick: weekdayNight = intervalInformations.Where(ii => ((ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(23, 30, 0)) || (ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(0, 0, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0))) && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday && !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString()) ) .OrderBy(ii => ii.IntervalPeriodTimestamp) .ToList(); Note: Your query appears to exclude the last half-hour between 23:30 and midnight. If this is not intentional, you can simplify the query even further: weekdayNight = intervalInformations.Where(ii => (ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0) || ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0)) && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday && ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday && !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString()) ) .OrderBy(ii => ii.IntervalPeriodTimestamp) .ToList();
Datepicker minDate today and maxDate 31 Dec Next year
Try to limit the date selection between today and 31st Dec of next year. $(function() { $('.public-holiday-date-pick').datepicker({ minDate: '0', yearRange: '-0:+1', maxDate: ??? hideIfNoPrevNext: true }); }); How should I define maxDate ? tried few things like '31 12 +1', or just 'last day of next year', did not work.
1) First get today's using var today = new Date(); 2) Similarly set the lastDate as below var lastDate = new Date(today.getFullYear() +1, 11, 31); The value in lastDate will be like lastDate = 31 December, today's year +1 Finally set the lastDate as maxDate var today = new Date(); //Get today's date var lastDate = new Date(today.getFullYear() +1, 11, 31); //To get the 31st Dec of next year $(function() { $('.public-holiday-date-pick').datepicker({ minDate: '0', yearRange: '-0:+1', maxDate: lastDate, //set the lastDate as maxDate hideIfNoPrevNext: true }); }); JSFiddle