reset the zoom to the initial in chart.js? - chart.js

I'm new to chartjs. I applied the extension of this library to enable the zoom. At first it looks great, but as I zoom, I am unable to return to the original point where my bar chart is at the start.
Does anyone know why this happens to me or how can I fix it? thank you very much.
var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am","08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am"],
datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]
},
options: {
legend: {
position: 'top',
},
scales: {
xAxes: [{
ticks: {
autoSkip: true,
maxRotation: 0,
minRotation: 0
}
}]
},
pan: {
enabled: false,
mode: 'xy' // is panning about the y axis neccessary for bar charts?
},
zoom: {
sensitivity:0.5, drag: false, enabled: true, mode: 'x'
}
}
});
this is my code working:
https://jsfiddle.net/ogq5uex6/2/

#yavg Please check bellow screenshot. many labels are duplicated. don't add duplicate label like this. try to add 24 hours time as my answer
I think you expected like this.
var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels:
["08 Aug 2018 14:42","09 Aug 2018 11:24","04 Sep 2018 13:23","04 Sep 2018 13:26","04 Sep 2018 13:31","04 Sep 2018 13:33","04 Sep 2018 13:35","04 Sep 2018 13:36","04 Sep 2018 13:38","04 Sep 2018 13:39","04 Sep 2018 13:40","04 Sep 2018 13:45","04 Sep 2018 13:46","04 Sep 2018 13:49","04 Sep 2018 13:50","04 Sep 2018 13:51","04 Sep 2018 13:53","04 Sep 2018 14:07","04 Sep 2018 14:19","04 Sep 2018 14:20","04 Sep 2018 14:21","04 Sep 2018 14:30","04 Sep 2018 14:31","04 Sep 2018 14:33","05 Sep 2018 09:30","05 Sep 2018 09:31","08 Aug 2018 14:43","09 Aug 2018 11:25","04 Sep 2018 13:22","04 Sep 2018 13:27","04 Sep 2018 13:32","04 Sep 2018 13:34","04 Sep 2018 13:37","04 Sep 2018 13:41","04 Sep 2018 01:40","04 Sep 2018 01:41","04 Sep 2018 01:42","04 Sep 2018 01:45","04 Sep 2018 01:46","04 Sep 2018 01:49","04 Sep 2018 01:50","04 Sep 2018 01:51","04 Sep 2018 01:53","04 Sep 2018 02:07","04 Sep 2018 02:19","04 Sep 2018 02:20","04 Sep 2018 02:22","04 Sep 2018 02:36","04 Sep 2018 02:32","04 Sep 2018 02:35","05 Sep 2018 10:31","05 Sep 2018 10:32"],
datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]
},
options: {
legend: {
position: 'top',
},
scales: {
xAxes: [{
ticks: {
autoSkip: true,
maxRotation: 0,
minRotation: 0
}
}]
},
pan: {
enabled: false,
mode: 'xy' // is panning about the y axis neccessary for bar charts?
},
zoom: {
sensitivity:0.5, drag: false, enabled: true, mode: 'x'
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://npmcdn.com/Chart.Zoom.js#0.3.0/Chart.Zoom.min.js"></script>
<canvas id="canvas" height="180"></canvas>
My Codepen Example here

Related

AWS cron expression to run every other Monday

I want to schedule a CloudWatch event to run every other Monday and have started with this command:
0 14 ? * 2 *
Currently with the above command, I get a weekly schedule of Monday executions:
Mon, 27 Jul 2020 14:00:00 GMT
Mon, 03 Aug 2020 14:00:00 GMT
Mon, 10 Aug 2020 14:00:00 GMT
Mon, 17 Aug 2020 14:00:00 GMT
Mon, 24 Aug 2020 14:00:00 GMT
Mon, 31 Aug 2020 14:00:00 GMT
Mon, 07 Sep 2020 14:00:00 GMT
Mon, 14 Sep 2020 14:00:00 GMT
Mon, 21 Sep 2020 14:00:00 GMT
Mon, 28 Sep 2020 14:00:00 GMT
However, I would like the schedule to be set to every other Monday, e.g.
Mon, 27 Jul 2020 14:00:00 GMT
Mon, 10 Aug 2020 14:00:00 GMT
Mon, 24 Aug 2020 14:00:00 GMT
Mon, 07 Sep 2020 14:00:00 GMT
Mon, 21 Sep 2020 14:00:00 GMT
I have seen examples with exp and # being used, but I don't think AWS CloudWatch events accept these sort of parameters.
Chris' answer is correct. Currently, there is no way that I could think of to express this as part of CloudWatch Scheduled Events.
However, a workaround could be to set it to every Monday (0 14 ? * 2 *) and trigger a Lambda function that checks whether it's in the on-week or the off-week before triggering the actual target.
Even though this adds some complexity, it would be a viable solution.
You won't be able to do any of the fancier commands (especially those using variables from the command line).
You could do this very basically but would require 2 separate events in order to carry it out:
0 14 ? * 2#1 * - Run on the first Monday of the month.
0 14 ? * 2#3 * - Run on the third Monday of the month.
Unfortunately there is no compatible syntax for scheduled expressions that would allow the concept of every other week, so the above commands occasionally could lead to a 3 week gap.
If you don't care about the Monday you could of course use 0 14 1,15 * * to run on the 1st and 15th of each month (roughly every 2 weeks).
The final option would be to run every Monday, but have the script exit if it is not the every other week, the expression would then just be 0 14 ? * 2 *.
More information about the syntax is available on the Cron Expressions section of the Scheduled Events page.

Create a custom indicator using DAX on power BI

FOR ALL POWER BI USERS
I have created a table visual name from table "Example" given below as raw data (similar to result table except Ind column). I want to create an indicator which will be based on the column total using DAX.
Company | Rev 2018 | Rev 2019 | Rev YoY(%) |
-----------------------------------------------------------
A | 440,980,812 | 321,015,626 | -27.20% |
B | 587,171,150 | 248,150,205 | -57.74% |
C | 693,692,632 | 255,633,145 | -63.15% |
D | 753,951,313 | 266,033,862 | -64.71% |
E | 387,652,076 | 393,439,270 | 1.49% |
Total | 2,863,447,983 | 1,484,272,108 | -48.16% |
My current measure calculation is given below
Rev 2018 = CALCULATE(sum(Example[Rev]),Example[Year]=2018)
Rev 2019 = CALCULATE(sum(Example[Rev]),Example[Year]=2019)
Rev YoY(%) = ([Rev 2019]-[Rev 2018])/[Rev 2018]
I want to create an indicator (Ind) which will show 1 if Rev YoY(%)(-27.20% for company A) for the company is greater than equal to (>=) overall/total Rev YoY(%)(-48.16% of total), else it will show 0. And it will changes based on slicer selections(if Jan is selected, the updated values should changes based on Jan and similarly for other selections such as Feb , Mar etc).
As of now, the value is based on YTD values.Based on the Jan , Feb etc month , the values will be updated for revenue and YoY, simultaneously Indicator measure should also get updated.
Final result will look like below
Company | Rev 2018 | Rev 2019 | Rev YoY(%) | Ind
-----------------------------------------------------------
A | 440,980,812 | 321,015,626 | -27.20% | 1
B | 587,171,150 | 248,150,205 | -57.74% | 0
C | 693,692,632 | 255,633,145 | -63.15% | 0
D | 753,951,313 | 266,033,862 | -64.71% | 0
E | 387,652,076 | 393,439,270 | 1.49% | 1
Total | 2,863,447,983 | 1,484,272,108 | -48.16% | 1
Please help in case you have the solution.
I tried to used filer(allcrossfiler) but it makes the field constant which does not change with slicers
Rev_total% =
CALCULATE(
[Rev YoY(%)],
ALLCROSSFILTERED(Example)
)
Base Raw data
Company Year Month Rev
A 2018 Jan 3715518
A 2018 Feb 62195456
A 2018 Mar 47896563
A 2018 Apr 30397293
A 2018 May 13316124
A 2018 Jun 54702783
A 2018 Jul 23559246
A 2018 Aug 56357008
A 2018 Sep 91266366
A 2018 Oct 7826397
A 2018 Nov 30081453
A 2018 Dec 19666605
A 2019 Jan 20525691
A 2019 Feb 55636582
A 2019 Mar 70832178
A 2019 Apr 51101460
A 2019 May 71658353
A 2019 Jun 51261362
B 2018 Jan 70866878
B 2018 Feb 16605125
B 2018 Mar 77399457
B 2018 Apr 93675100
B 2018 May 24187836
B 2018 Jun 17141132
B 2018 Jul 23189326
B 2018 Aug 1228527
B 2018 Sep 77025448
B 2018 Oct 69069603
B 2018 Nov 61201073
B 2018 Dec 55581645
B 2019 Jan 49529171
B 2019 Feb 30268530
B 2019 Mar 58895051
B 2019 Apr 16378441
B 2019 May 63289350
B 2019 Jun 29789662
C 2018 Jan 28386565
C 2018 Feb 55081195
C 2018 Mar 98650639
C 2018 Apr 13600972
C 2018 May 79286377
C 2018 Jun 97910757
C 2018 Jul 59601906
C 2018 Aug 60499979
C 2018 Sep 10555754
C 2018 Oct 21239252
C 2018 Nov 79278588
C 2018 Dec 89600648
C 2019 Jan 27489712
C 2019 Feb 8085774
C 2019 Mar 33489287
C 2019 Apr 52598275
C 2019 May 50816690
C 2019 Jun 83153407
D 2018 Jan 69955023
D 2018 Feb 1684049
D 2018 Mar 44503967
D 2018 Apr 91505045
D 2018 May 74480545
D 2018 Jun 70038948
D 2018 Jul 28811752
D 2018 Aug 82052925
D 2018 Sep 97215945
D 2018 Oct 48093159
D 2018 Nov 96939697
D 2018 Dec 48670258
D 2019 Jan 68414609
D 2019 Feb 34593576
D 2019 Mar 28277668
D 2019 Apr 46146140
D 2019 May 83794133
D 2019 Jun 4807736
E 2018 Jan 21180873
E 2018 Feb 14552267
E 2018 Mar 27409537
E 2018 Apr 68894164
E 2018 May 24608038
E 2018 Jun 12774844
E 2018 Jul 13193433
E 2018 Aug 89921780
E 2018 Sep 34581806
E 2018 Oct 52068148
E 2018 Nov 11374013
E 2018 Dec 17093173
E 2019 Jan 21748970
E 2019 Feb 95983245
E 2019 Mar 49661560
E 2019 Apr 90056699
E 2019 May 72277971
E 2019 Jun 63710825
You can use the fllowing:
Indicator = if(Example[Rev YoY(%)] > CALCULATE(Example[Rev YoY(%)];ALL(Example[Company]));1;0)
The ALL is doing the trick, it tells pickup all companies data but still keep all other filters.
Some advice:
I would work with real dates and combine the year and month column,
this makes it much easier to work with future data.
You are having now 2018 and 2019, what if your data grows? more years to come.. It is better to talk about PrevYear/NextYear. What you can do is add a column to your data RevNextYear, based on this your reports will always work:
RevNextYear = CALCULATE(sum(RawRevenue[Rev]);
FILTER(RawRevenue;RawRevenue[Company] = EARLIER(RawRevenue[Company]) &&
RawRevenue[Month] = EARLIER(RawRevenue[Month]) &&
RawRevenue[Year] = EARLIER(RawRevenue[Year]) + 1)
)

after HTTP request via Groovy i have list of maps I need to add a new list to each element

After one HTTP Get on some request I create a list of maps with ids which looks like this
for (i=0; i<response.data.size(); i++){
def tempMap = [:];
tempMap['id'] = response.id[i];
tempMap['name'] = response.name[i];
listOfMaps.add(tempMap);
}
listOfMaps=[[id:1, name:123], [id:2, name:456]]
Then I do a GET HTTP request using that id to get list of versions like this:
def myVerList = parser.parseText(response)
println(myVerList);
[[version:1.0.0, createdAt:Mon Jul 15 2019 15:51:48 GMT+0200], [version:2.0.1, createdAt:Mon Jul 15 2019 15:25:48 GMT+0200], [version:2.0.0, createdAt:Mon Jul 15 2019 14:51:48 GMT+0200], [version:1.3.0, createdAt:Mon Jul 15 2019 13:51:48 GMT+0200], [version:1.1.0, createdAt:Mon Jul 8 2019 18:22:48 GMT+0200]]
I need to add this new list to the given id above.
final result should look like this:
[
[id:1, name:123], [[version:1.0.0, createdAt:Mon Jul 15 2019 15:51:48 GMT+0200], [version:2.0.1, createdAt:Mon Jul 15 2019 15:25:48 GMT+0200], [version:2.0.0, createdAt:Mon Jul 15 2019 14:51:48 GMT+0200], [version:1.3.0, createdAt:Mon Jul 15 2019 13:51:48 GMT+0200], [version:1.1.0, createdAt:Mon Jul 8 2019 18:22:48 GMT+0200]]],
[id:2, name:456], [[version:2.0.0, createdAt:Mon Jul 15 2019 15:51:48 GMT+0200], [version:2.0.1, createdAt:Mon Jul 15 2019 15:25:48 GMT+0200], [version:2.0.0, createdAt:Mon Jul 15 2019 14:51:48 GMT+0200], [version:1.3.0, createdAt:Mon Jul 15 2019 13:51:48 GMT+0200], [version:1.1.0, createdAt:Mon Jul 8 2019 18:22:48 GMT+0200]]
]
How do I problematically in Groovy inside my JSR232 post processor?
I tried this it works but it has duplicate data
def response = prev.getResponseDataAsString();
def myJson = parser.parseText(response)
for(item in listOfMaps){
if (item["id"] == vars.get("thatId")) { item["versions"]=myJson; }
newList.add(item)
}
vars.putObject("newList",newList);
The only thing is newList has two sets of entries
You need to compare integers:
if (item["id"] == Integer.parseInt(vars.get("thatId"))) {

RegEx: Match Within Bounded Groups

I need to match carriage-returns in blocks of text between a pre-determined tag and an indeterminate tag.
In this case, the bounding tags are:
Pre-determined: X-Gmail-Labels:
Indeterminate: (?:^[\w\-]+:) eg: Delivered-To: or ABC123:
Thanks to Wiktor Stribiżew for his answer to this thread, I have a rough idea of the solution I should pursue.
I am unsure of how to apply what I believe is needed: an uncaptured lookahead group for the bounding indeterminate tag.
Plainly stated, I'd like to delete all the carriage-returns in the text associated with the X-Gmail-Labels:. If I can match them, I can delete them!
Initial attempted regex:
(?:\bX-Gmail-Labels:|(?!^)\G)[^\r]*\K\r
Sample data:
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived thing,Unread
Delivered-To: joe.schmoe#gmail.com
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Also Archived
Day-of-week: Tuesday
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
thing,
Unread
Favorite-fruit: bananas
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
,Read
ABC123: DoReMe
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
From 1604610346950104244#xxx Fri Jun 29 12:34:35 +0000 2018
X-GM-THRID: 1604610346950104244
X-Gmail-Labels: Archived
thing,Unread
emais
Received: by 2002:a9f:3005:0:0:0:0:0 with SMTP id h5-v6csp731836uab;
Fri, 29 Jun 2018 05:34:36 -0700 (PDT)
(?:^[\w\-]+:)
Above regex applied to data showing indeterminate tag pattern.
(?:\bX-Gmail-Labels:\G)[^\r]*\K\r
Above regex applied to data showing un-end-bounded matches.
Thanks!
-Fitz

Boost::gregorian and leap years

I'm writing a code where I use only boost libraries as prerequisites.
I need a class to handle datetime values and operations (add and subtract years, months, hours, etc.), so I picked the gregorian date as an option.
But, when I handle days in leap years, some surprises appear. There is a piece of an example code:
int main()
{
boost::gregorian::date d1(2000,1,1);
boost::gregorian::days ds(118);
boost::gregorian::date d2 = d1 + ds;
std::cout << boost::gregorian::to_iso_extended_string(d1) << std::endl;
std::cout << boost::gregorian::to_iso_extended_string(d2) << std::endl;
return 0;
}
Output:
2000-01-01
2000-04-28 (should be 2000-04-27)
Is there an option for this issue? In the manual page, the boost warning about "lead to unexpected results..."
I think it's correct as it is:
for a in {1..118}; do echo -n "+$a days: "; date --rfc-2822 -d"2000-01-01 +$a days"; done
prints
shows I see no anomalies around the leap date:
+1 days: Sun, 02 Jan 2000 00:00:00 +0100
+2 days: Mon, 03 Jan 2000 00:00:00 +0100
...
+57 days: Sun, 27 Feb 2000 00:00:00 +0100
+58 days: Mon, 28 Feb 2000 00:00:00 +0100
+59 days: Tue, 29 Feb 2000 00:00:00 +0100
+60 days: Wed, 01 Mar 2000 00:00:00 +0100
...
+116 days: Wed, 26 Apr 2000 00:00:00 +0200
+117 days: Thu, 27 Apr 2000 00:00:00 +0200
+118 days: Fri, 28 Apr 2000 00:00:00 +0200