Is it possible to have labels on datetime xAxis that correspond to dataGrouping?
For example I have dataGrouping such that data are grouped into days / weeks / months / year:
dataGrouping : {
groupPixelWidth: 250,
units : [
['day', [1]], ['week', [1]], ['month', [1]], ['year', [1]]
]
}
http://jsfiddle.net/CHR7F/2/
There is plenty of options in the highcharts api, but no one seems to achieve the same result as dataGrouping.
The most promising was:
xAxis: {
labels: {
step: 1
}
}
but still there are two weeks between ticks while data is grouped by months.
I found a solution with tickPositioner. It is still a workaround, but at least it works.
xAxis: {
tickPositioner: function(){
ticks = this.series[0].processedXData;
ticks.info = this.series[0].currentDataGrouping;
return ticks;
}
}
http://jsfiddle.net/CHR7F/3/
On thesame level as setting units you cna set datetimeLebelFormats, see: http://api.highcharts.com/highstock#plotOptions.area.dataGrouping.dateTimeLabelFormats
Related
This question already has answers here:
Function not returning the output in R
(3 answers)
Closed 1 year ago.
I was going through an R Function exercise, in this exercise we are required to create a function called bar_count that returns the least amount of aluminum bars required to fulfill an order, there are only two types of bars, 5kg bars and 1kg bars. The function should return F if the order has decimal it can only be exact numbers.
Here is what I came up with:
bar_count <- function(kg){
num.of.five <- 0
num.of.one <- 0
five.kg <- kg/5
if (kg%%5 == 0){
num.of.five <-num.of.five + five.kg
} else if(kg%%5 != trunc(kg%%5)){
return(F)
}else if (kg%%5 >= 1) {
num.of.five <- num.of.five + trunc(five.kg)
num.of.one <- num.of.one + ((kg%%5))
}
num.of.bars <- num.of.five + num.of.one
return (num.of.bars)
return(paste('qty of 5kg bars is:', num.of.five))
return(paste('qty of 1kg bars is:',num.of.one))
}
The problem I am having is with the two last commands where I ask R to return(paste()) the quantity of aluminum bars for the 5kg lot and the 1 kg lot, however it does not return any of those two,it only returns the total amount, I have tried with print() but it hasn't work either.
Thank you for taking the time to answer
Once you return from an R function, no code beyond the return statement will execute. Presumably you want to print before you return, so try using this version:
bar_count <- function(kg) {
// ...
print(paste('qty of 5kg bars is:', num.of.five))
print(paste('qty of 1kg bars is:', num.of.one))
return(num.of.bars)
}
im trying to follow this guide on plotting a time series chart but ive run into a small issue. is there any way to change the bottom label to only show the current time (H:M:S) instead of the current date? ive been trying for a while now to find a way to do this but it still havent been able to. im following the code in the guide so this is the code im working with:
use plotters::prelude::*;
use chrono::{Utc, TimeZone};
fn main() {
let root_area = BitMapBackend::new("images/2.11.png", (600, 400))
.into_drawing_area();
root_area.fill(&WHITE).unwrap();
let start_date = Utc.ymd(2019, 10, 1);
let end_date = Utc.ymd(2019, 10, 18);
let mut ctx = ChartBuilder::on(&root_area)
.set_label_area_size(LabelAreaPosition::Left, 40)
.set_label_area_size(LabelAreaPosition::Bottom, 40)
.caption("MSFT daily close price", ("sans-serif", 40))
.build_cartesian_2d(start_date..end_date, 130.0..145.0)
.unwrap();
ctx.configure_mesh().draw().unwrap();
ctx.draw_series(
LineSeries::new(
(0..).zip(DATA.iter()).map(|(idx, price)| {
let day = (idx / 5) * 7 + idx % 5 + 1;
let date = Utc.ymd(2019,10, day);
(date, *price)
}),
&BLUE,
)
).unwrap();
}
const DATA: [f64; 14] = [ 137.24, 136.37, 138.43, 137.41, 139.69, 140.41, 141.58, 139.55, 139.68, 139.10, 138.24, 135.67, 137.12, 138.12];
ive tried using chrono's NaiveTime but it doesnt seem to be supported, DateTime causes the entire date and time to be printed instead of just the time, and ive also tried creating my own element series but i cant figure out how to get that working. anyone have any ideas?
You can add this line, or something like it to the ChartBuilder:
.x_label_formatter(&|x| format!("{:02}:{:02}", x.hour(), x.minute()))
where x is a DateTime struct. You can use other DateTime functions to get different parts of the time, as required.
I'm trying to do a Highcharts chart using the datetime x-axis label to have my main labels at 1 month intervals. I would then like to use a minorTick on the week intervals. My data is 1 point per day. The problem I'm facing is my minorTicks are appearing as grid lines on the chart instead of as sub-ticks. I'd like them to be outside, or at least very small. How can I actually have these minor ticks as ticks, and not grid lines? I otherwise do not want any grid lines at all.
http://jsfiddle.net/590ktt7j/
$('#container').highcharts({
yAxis: {
gridLineWidth:0
},
xAxis: {
minorTickInterval: 7 * 24 * 3600 * 1000,
minorTickPosition:'outside',
minorTickLength:10,
type:'datetime',
min: Date.UTC(2014, 0, 1),
max: Date.UTC(2014, 11, 31),
labels: {
step: 1,
},
dateTimeLabelFormats: {
month: '%b',
year: '%Y'
}
},
// sample data, in reality goes 365 days of year
series: [{
data: [[1388984399000,100], [1388973600000,200],[1389060000000,300],[1389146400000,400],[1389232800000,500],[1389319200000,400],[1389405600000,200]]
}]
});
The grid lines are independent of the ticks. Add these 2 options to your xAxis config:
xAxis: {
minorTickWidth: 1, // this is by default 0 and is why you don't see ticks
minorGridLineWidth: 0, // this disables the grid lines
Fixed fiddle.
I am writing a code to generate four stimulations and then generate graphs. My code works, but I want instead of generating four graphs I want to combine them all in one graph. How can I do that?
My code:
queueSimulation <- function(arriverate, servrate, endtime) {
queue = numeric(0)
arrivetimes = rexp(10000, arriverate)
servtimes = rexp(10000, servrate)
clock = 0.0
clist=c()
qlist=c()
while(clock <= endtime) {
if(length(queue) > 0 && queue[1] < arrivetimes[1]) {
clock = clock + queue[1]
queue = queue[-1]
}
else {
clock = clock + arrivetimes[1]
queue[length(queue) + 1] = servtimes[1]
arrivetimes = arrivetimes[-1]
servtimes = servtimes[-1]
}
#queue_size= length(round(clock, 2))
clist = c(clist , clock)
qlist = c(qlist , length(queue))
}
a<-data.frame(time=clist , qsize=qlist)
print(a)
mean1<-mean(qlist)
cat("Average :", mean1, "\n")
plot(a)
}
and calling the function:
queueSimulation(1.0, 5.0, 100)
queueSimulation(2.0, 4.0, 100)
queueSimulation(2.3, 3.5, 100)
queueSimulation(4.0, 5.0, 100)
There might be a better solution to this, but how about slightly changing your approach.
1- In your function, add two variables, one for color (cl) and one to tell your function if your plotting the main plot or just adding lines (pl). 1 for main and 0 for lines.
function(arriverate, servrate, endtime,cl,pl) {
2- call your plot with an if statement, and fix your y axis to range from 0 to 200.
if(pl==1){plot(a,col=cl,ylim=c(0,200),type="l")} else{lines(a,col=cl)}}
and then, call your function with theses two variables (cl and pl) :
queueSimulation(1.0, 5.0, 100,"red",1)
queueSimulation(2.0, 4.0, 100,"blue",0)
queueSimulation(2.3, 3.5, 100,"green",0)
queueSimulation(4.0, 5.0, 100,"black",0)
The problem I see with this is that your simulations can get values way over 200 for the y axis, maybe try to find a way to get max y values in one of your call.
Take a look at layout, specifically put layout(matrix(1:4,nrow=2)) (or a variant) before you call your plotting functions.
I'm developing a stocks evolution chart with Microsoft Chart Controls and I need to show the initial and final dates on the AxisX labels but I can't do it.
I google and found many solutions like set the properties:
Chart1.ChartAreas[0].AxisX.Minimum = InitialDate.ToOADate();
Chart1.ChartAreas[0].AxisX.Maximum = FinalDate.ToOADate();
Chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = true;
Nothing made same differnce. I need a help !
On the sample below the initial date was Jul 26, 2007 and the final was Jul 26, 2010, this is what I need to show on the chart labels, the others dates don't make difference and can be showed in any interval.
alt text http://img826.imageshack.us/img826/6518/evolucaoinvestimento.png
LCharts(iChart).Chart.ChartAreas(0).AxisX.Minimum = MinDate.ToOADate
LCharts(iChart).Chart.ChartAreas(0).AxisX.Maximum = MaxDate.ToOADate
LCharts(iChart).Chart.ChartAreas(0).AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount
'LCharts(iChart).Chart.ChartAreas(0).AxisX.IsMarginVisible = True
LCharts(iChart).Chart.ChartAreas(0).AxisX.LabelStyle.IsEndLabelVisible = True
I get a way:
// get the interval in days
double days = (double)((TimeSpan)(FinalDate - InitialDate)).Days;
// the number os labels
double labels = 10.0;
// check if the number of days is bigger than labels
if (days > labels)
{
// calculate the interval
double interval = days / labels;
Chart1.ChartAreas[0].AxisX.Interval = interval;
}
else
{
// set the interval of 1 day
Chart1.ChartAreas[0].AxisX.Interval = 1;
}
Here is the result:
chart http://img691.imageshack.us/img691/7796/chartimgca42ufcm.png