I am using Google Charts for line graphs and tables in my application. I have my data in UTC format however while displaying I want to change the timezone to the user's choice of timezone.
For the tables, I tried using the timezone attribute for the date formatter. However it is not giving proper results. Hence I am planning to use moment.js to format the data in specific timezone. Can I use a custom formatter with data tables. The examples in the documentation do not have any details. Similarly can I format the data displayed on the x-axis of my line graph using a custom formatter. Any example would really help.
You can format the data in the DataTable by calling the setFormattedValue method of the DataTable: data.setFormattedValue(row, column, 'string formatted value');. You cannot use the format property of the axis option to change the timezone, but you can use the ticks property of the axis option to set which dates and associated labels to use:
hAxis: {
ticks: [{v: new Date(2014, 2, 1, 10), f: '03/01/2014 5AM EST'}, {v: new Date(2014, 2, 2, 17), f: '03/02/2014 12PM EST'}, {v: new Date(2014, 2, 3, 6), f: '03/03/2014 1AM EST'}]
}
It might be easier to adjust your data rather than to reformat things. As an example, to change dates in column 1 of data from GMT by offset hours, you could use this:
for (var i = 0; i < data.getNumberOfRows(); i++) {
var d = data.getValue(i, 0);
d.setHours(d.getHours + offset);
data.setValue(i, 0, d);
}
Related
I have a model that I run a daterange query over. For business reasons, I annotate a field in my results that represent CST timezone (data is stored in UTC by default).
The query below returns an empty queryset even though there are entries by the date range mentioned below.
MyModel.objects.annotate(cst_created_at=ExpressionWrapper(F('created_at')-timezone.timedelta(hours=6, minutes=0), output_field=DateTimeField())).filter(cst_created_at__date__range=["2022-09-01", "2022-09-01"])
If I get the values of cst_created_at (that I annotated) and created_at, which is a auto_now_add=True field, they're both the same.
result = MyModel.objects.annotate(cst_created_at=ExpressionWrapper(F(field)-timezone.timedelta(hours=6, minutes=0), output_field=DateTimeField())).first()
cst = result.cst_created_at
ca = result.created_at
print(cst)
>>>datetime.datetime(2022, 9, 1, 0, 51, 2, 310752, tzinfo=<UTC>)
print(ca)
>>>datetime.datetime(2022, 9, 1, 6, 51, 2, 310752, tzinfo=<UTC>)
cst.date() == ca.date()
>>>True
At the same time, if I query cst_created_at with yesterday's date (2022-08-31) it returns the objects created on 2022-09-01. Also, if I query created_at__date for 2022-09-01 it works as well.
I wanna know if both the dates are same why doesn't the query work properly?
I am working with a bot, and I need to sort the event by a datetime column, when I import the column from my database I have this format:
2017-10-19T14:26:57.2349278Z
after importing in power BI and changing the data type to date time I get this:
10/19/2017 02:26:57 PM
all the trailing milliseconds are truncated, but I need them to sort correctly the events, because some events occurs in the same second.
Any body any idea?
Thanks!
Starting with a sample table of dates in your format, when loaded into Power BI, this is the result.
Click on the Navigation step and then click on Add Column -> Custom Column. A prompt will pop up asking if you want to insert a step, click Insert.
In the prompt, enter the following formula.
Text.Start([#"Timestamp"], 4) &
Text.Middle([#"Timestamp"], 5, 2) &
Text.Middle([#"Timestamp"], 8, 2) &
Text.Middle([#"Timestamp"], 11, 2) &
Text.Middle([#"Timestamp"], 14, 2) &
Text.Middle([#"Timestamp"], 17, 2) &
Text.Middle([#"Timestamp"], 20, 7)
This gives you a column that can be used to sort the items in the table by a precise datetime. Note that the custom column formula requires the raw date string to be in the exact same format as in your question.
I am using a bootstrap table where I can choose the page size by the
pageSize: 10,
pageList: [5, 10, 20, 50, 100, 200],
parameters.
What I would like to do is to get the pages not of a fixed size, but dividing all the row by the values of one column. So for example if I have a column for salaries and 13 people have a salary 3500€ and 8 people have a salary 4000€, then I'd like to have the 13 entries on 1 table-page and the other 8 entries on the other table-page. I would like to make this work particularly for dates or date ranges.
What I've understood from the documentation, is that this feature does not exist, but I hope to get some alternative solutions for my Django-run page.
I am handling a similar situation, but not with paging. I have select2 dropbox boxes where the user select the parameter(s) and then I populate the grid with those choice(s). https://select2.github.io/examples.html
Here is a sample of the code I am using the pass parameters to the server application.
$('#comptable1').bootstrapTable({
url: 'urlhere.php',
pagination: true,
sidePagination: 'server',
uniqueId: 'id',
selectItemName: 'chkID',
columns:[
{
...
}
],
queryParams: function(params){
//add paramaters to the params array as needed
params['field']=$('#findfield').val();
return params;
}
});
I am working on an application in Python and Flask where I am creating a query from a database of 50 rows of content that I would like to use to build an HTML table on render. I will be dealing with 50 rows and 8 fields per row. What would be the best way to package this up and then render it our in the template. A sample of a row is below.
(49L, 1L, 1L, datetime.datetime(2013, 9, 25, 19, 32, 34), 996L, u'on', 78.0, 80.0, 48.0)
i'll be manipulating the datatime for a better display, but most of the other fields will come through basically unchanged.
Thanks!
I have a line chart where we plot some numbers against a datetime value on x-axis. Since, using datetime value on column type renders it a continuous axis, the column labels are auto generated.
We get only the time component as the column labels but not the date. Is there anything I can do to get the entire date time as the label?
(NOTE: I do not want to change the data type to string as I do not want even spacing in data points.)
Yes. You need to look at formatters which use a subset of the ICU SimpleDateFormat.
Here is an example of how they work:
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addRows([
[new Date(2012,1,5)],
[new Date(2012,2,10)],
[new Date(2012,3,15)],
[new Date(2012,4,20)]
]);
alert(data.getFormattedValue(3,0));
var formatter1 = new google.visualization.DateFormat({pattern: 'yyyy, MMM'});
formatter1.format(data,0);
alert(data.getFormattedValue(3,0));
}
Adjust to fit your data and needs, and presto! You have it working.