bootstrap datepicker show month number insted of if month name - bootstrap-datepicker

is there any way to show the month number instead of month name in the calender grid?
because Now I can see the calncer as Jan 2014 , Feb 2014 ... etc
is there any way to show the month number like 1 2014 , 2 2014
Thanks

You can redefine this 'months' array before calling datepicker init:
$.fn.datepicker.dates['en'] = {
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
today: "Today",
clear: "Clear"
};
$('#your_datepicker_id').datetimepicker();

Related

How to avoid error "must be size" when changing month names to numbers?

I am trying to convert a character column containing month names into a numerical column containing numbers (1=January, etc.).
Example 1. This works:
df2 <- structure(list(Month = c("January", "January", "March", "March", "April")), class = "data.frame", row.names = c(NA, -5L))
df2 %>%
group_by(Month) %>%
mutate(Month = which(Month == month.name)) -> df2
Example 2. This does not work (error: "Month must be size 31 or 1, not 2."):
df <- structure(list(Month = c("August", "August", "August", "August",
"August", "August", "August", "August", "August", "August", "August",
"August", "August", "August", "August", "August", "August", "August",
"August", "August", "August", "August", "August", "August", "August",
"August", "August", "August", "August", "August", "August", "December",
"December", "December", "December")), class = "data.frame", row.names = c(NA, -35L))
df %>%
group_by(Month) %>%
mutate(Month = which(Month == month.name)) -> df
The code for converting is the same in both cases. Why doesn't it work in the second example? I can't get my head around it.

Merging separate Month and Year columns to graph in ggplot2

I've been around the forums looking for a solution to my issue but can't seem to find anything. Derivatives of my question and their answer haven't really helped either. My data has four columns, one for Year and one for Month). I've been wanting to plot the data all in one graph without using any facets for years in ggplot. This is what I've been struggling with so far with:
df<-data.frame(Month = rep(c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "February", "March"),each = 20),
Year = rep(c("2018", "2019"), times = c(220, 40)),
Type = rep(c("C", "T"), 260),
Value = runif(260, min = 10, max = 55))
df$Month<-ordered(df$Month, month.name)
df$Year<-ordered(df$Year)
ggplot(df) +
geom_boxplot(aes(x = Month, y = Value, fill = Type)) +
facet_wrap(~Year)
I'd ideally like to manage this using dplyr and lubridate. Any help would be appreciated!
One option would be to make a true date value, then you can use the date axis formatter. Something like this is a rough start
ggplot(df) +
geom_boxplot(aes(x = lubridate::mdy(paste(Month, 1, Year)), y = Value, fill = Type, group=lubridate::mdy(paste(Month, 1, Year)))) +
scale_x_date(breaks="month", date_labels = "%m")
Do you mean this?
df<-data.frame(Month = rep(c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "February", "March"),each = 20),
Year = rep(c("2018", "2019"), times = c(220, 40)),
Type = rep(c("C", "T"), 260),
Value = runif(260, min = 10, max = 55))
df$Month <- factor(df$Month,levels=c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "Dicember"), ordered = T)
df$Month<-ordered(df$Month)
df$Year<-ordered(df$Year)
df$Year_Month <- paste0(df$Month, " ", df$Year)
df$Year_Month <- factor(df$Year_Month, levels = unique(df$Year_Month))
ggplot(df) +
geom_boxplot(aes(x = Year_Month, y = Value, fill = Type))

How to order by Month? [duplicate]

I have this data frame called yy:
structure(list(Time = structure(c(1209096000, 1238731200, 1272600000,
1301666400, 1335794400, 1364835600, 1218772800, 1250222400, 1280808000,
1314028800, 1346421600, 1377835200, 1229317200, 1262235600, 1291352400,
1324047600, 1355497200, 1385960400, 1204261200, 1235710800, 1265950800,
1298646000, 1328281200, 1360940400, 1199250000, 1232082000, 1263186000,
1295017200, 1326466800, 1357149600), class = c("POSIXct", "POSIXt"
), tzone = ""), Peak_Logons = c(472452L, 398061L, 655849L, 881689L,
873720L, 1278295L, 340464L, 520943L, 1995150L, 883184L, 931721L,
1098553L, 405193L, 638301L, 734635L, 1254951L, 962391L, 1126432L,
316200L, 477407L, 674884L, 812793L, 898550L, 1541478L, 291564L,
394967L, 902076L, 916832L, 878264L, 918102L), Year = c("2008",
"2009", "2010", "2011", "2012", "2013", "2008", "2009", "2010",
"2011", "2012", "2013", "2008", "2009", "2010", "2011", "2012",
"2013", "2008", "2009", "2010", "2011", "2012", "2013", "2008",
"2009", "2010", "2011", "2012", "2013"), Month = c("April", "April",
"April", "April", "April", "April", "August", "August", "August",
"August", "August", "August", "December", "December", "December",
"December", "December", "December", "February", "February", "February",
"February", "February", "February", "January", "January", "January",
"January", "January", "January")), .Names = c("Time", "Peak_Logons",
"Year", "Month"), row.names = c(35479L, 30535L, 23645L, 15248L,
49696L, 8077L, 24651L, 13098L, 20204L, 47450L, 41228L, 20740L,
28049L, 9739L, 2636L, 50230L, 43746L, 3435L, 38091L, 28351L,
7382L, 3343L, 47824L, 45481L, 23951L, 29664L, 10024L, 4545L,
38808L, 44205L), class = "data.frame")
What I would like to do is create a heat map, Year on the y-axis and Month on the x-axis.
I am doing this:
ggplot(yy ,aes(Month, Year, fill=Peak_Logons)) +
geom_tile() +
theme_bw() +
guides(fill = guide_legend(keywidth = 5, keyheight = 1)) +
theme(axis.text.x = element_text(size=10, angle=45, hjust=1))
This kinda works but Months on x-axis are not order from January, February, March, April ... December.
They are order aphabetically from April, August etc.
How would I order the x-axis from January to December?
Is there a way to change the default colors, it looks like it is using blue shades?
Can I isert text the the geom_tiles? I would like to insert Time and Peak_Logons inside the tiles.
I would really appreciate any insight.
Use reorder to arrange your axis labels. I create a new column with month index.
geom_text to add text. Maybe you should play with text size.
scale_fill_gradientn to change fill color. See also scale_fill_gradientn
dat.m <- data.frame(Month=months(seq(as.Date("2000/1/1"),
by = "month", length.out = 12)),month.id = 1:12)
yy <- merge(yy,dat.m)
library(ggplot2)
ggplot(yy ,aes(reorder(Month,month.id), Year, fill=Peak_Logons)) +
geom_tile() +
theme_bw() +
guides(fill = guide_legend(keywidth = 5, keyheight = 1)) +
theme(axis.text.x = element_text(size=10, angle=45, hjust=1)) +
geom_text(aes(label=paste(Peak_Logons,format(Time,"%H"),sep='-'))) +
scale_fill_gradient(low = "yellow", high = "red")
You seem to consider months an ordered factor. You should make it one in R:
Month = c("April", "April",
"April", "April", "April", "April", "August", "August", "August",
"August", "August", "August", "December", "December", "December",
"December", "December", "December", "February", "February", "February",
"February", "February", "February", "January", "January", "January",
"January", "January", "January")
Month.ordered <- ordered(Month, month.name)
#[1] April April April April April April August August August August August August December December December December
#[17] December December February February February February February February January January January January January January
#Levels: January < February < March < April < May < June < July < August < September < October < November < December

How to change Month name in Bootstrap Datepicker calendar?

I am using bootstrap datepicker in my code but the calendar which appears have months like "March","July" etc. Is there any wayto change months full name to "MAR","JUL".
Thanks in advance
See the image
In this I want August to be AUG
Translate to whatever you want:
...simply add a key to $.fn.datepicker.dates,
before calling .datepicker() docs
$.fn.datepicker.dates['en'] = {
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
today: "Today",
clear: "Clear",
format: "mm/dd/yyyy",
titleFormat: "MM yyyy", /* Leverages same syntax as 'format' */
weekStart: 0
};
http://bootstrap-datepicker.readthedocs.io/en/latest/i18n.html
change language:
$('.datepicker').datepicker({
language: "pt-BR"
});
Since you stated in the comments that you are using eonasdan datetimepicker, you can simply use dayViewHeaderFormat option.
Here a working example.
$('#datetimepicker1').datetimepicker({
format: 'L',
dayViewHeaderFormat: 'MMM YYYY'
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment-with-locales.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>

Flex: Display month name in DateField control

I'm using the MX DateField control in Flex and want to display the date as 01 Jul 2011 or 01 July 2011. Does anyone know how to do this? I tried setting the formatString to "DD MMM YYYY" but it didn't work.
This works:
<fx:Declarations>
<mx:DateFormatter id="myDf" formatString="DD MMM YYYY"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
private function formatDate(date:Date):String{
return myDf.format(date);
}
]]>
</fx:Script>
<mx:DateField id="dateField" labelFunction="formatDate" />
Found it in the LiveDocs at http://livedocs.adobe.com/flex/3/html/help.html?content=controls_12.html
However this does not explain why the formatString property on the component does not work properly.
I can confirm that it does not work as expected.
Cheers
I would use something like this:
<mx DateField id = "dateField"
dayNames ="["S", "M", "T", "W", "T", "F", "S"]"
monthNames="["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"]" />
Since you mentioned 3 character month names, this is a good example. If you don't need the day names, of course, remove that line.
<mx DateField id = "dateField"
dayNames ="["S", "M", "T", "W", "T", "F", "S"]"
monthNames="["Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec"]"
formatString = "DD MMM YYY" />
Hope this helps.

Resources