Changing Chart Number Labels to Text not working (iOS Charts) - ios

I'm plotting sunrise/sunset against time, so time goes along the X axis with iOS Charts (Daniel Gindi).
If I display the x labels as numbers they manifest correctly: If I swap them over to text (Jan - Dec) only Jan shows up???
Associated iOS Chart code:
// Setup X Axis
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true
If I swap it over to literals then I only get Jan. All the values are populated. Any ideas?
Code: (n.b. putting labelCount before IndexAxisValueFormatter(values:months) makes no difference.)
// Setup X Axis
let months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"]
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true

Related

How to assign one conditional label per stacked bar (not per stack) on time series ggplot in facet grid

I would love to have your input how to solve this issues.
I have a time series (x=date) ggplot with bars (y=cmass1), and my bars are on position="stack" using a factor (polymer) to display polymer types for each sample.
Each bar represents another sampling station (factor sample), and I would like to identify which bar is which station (factor "sample" in my data frame) and add the label above each bar.
I've come so far that I can show the "sample" labels, but then there appear multiple replicated labels (one for each data point in the stacked parts of the bar). But I need only one per bar!
Can someone help, how I can create one label per bar (above each bar) that identifies which sample it is (without manual annotation)?
Additional date display problem:
Also, on one date (11 November) I have two samples, and in this plot they are cumulated, but I would need them next to each - so two as stacked bars on one date (like with besides=TRUE, but that doesn't seem to work with stacked bars). Any help here?
I hope it is clear, and thanks so much for any help!
Cleo
The plot, where S1, S2 etc should be above each bar as a label
Dataframe view_partial
ggplot(Merg1[!(is.na(Merg1$campaign)),] ,
aes(date,y=cmass1,group_by(sample1), fill=polymer))+
geom_col(show.legend = T, alpha = 0.8, position="stack",
stat="identity")+
xlab("July 2021 November 2021 February 2022 July 2022") +
facet_grid(.~campaign, scales = "free_x",space = "free_x" )+
geom_point(aes(y=montsouris_mm*20 ),color="#A3009F",size=2.5, position="dodge")+
geom_point(aes(y=melun_mm*20 ),color="#558C8C",size=2.5, position="dodge")+
geom_point(aes(y=fauville_mm*20 ),color="#E8DB7D",size=2.5, position="dodge")+
scale_y_continuous(expand = c(0,0),limits=c(0, 1000), breaks = seq(0, 1000, by = 100),
sec.axis = sec_axis(~./20, name = "Precipitation (mm)",
breaks = seq(0, 50, by = 10))) +
scale_x_date(date_breaks = "1 day", labels = date_format("%d"))+
ylab(expression(bold(paste(~C[mass]~ (µg ~L^{-1}))))) +
theme(axis.text.x=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.text.y=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.ticks.x=element_blank(),
axis.title.x = element_text(size = 12,
color = "black",
face = "bold"),
strip.background = element_rect(color="white", fill="white", size=0.5,
linetype="solid"),
legend.text = element_text(color = "black",size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(size = 0.5,colour="#D4CDCB",
fill="white" ,linetype = 'solid'),
legend.key.height= unit(0.2, 'cm'),
legend.key.width= unit(0.4, 'cm'))+
scale_fill_manual(name = "", values = MPcol, breaks = c("abs","acrylic", "acrylic paints", "alkyd","epoxy", "pa", "pan_acrylic fibre", "pe", "polyester", "pp", "ps", "pu", "pvac", "pvc", "sbr", "vinyl copolymer"),
labels=c("Acrylonitrile butadiene styrene (ABS)","Acrylic", "Acrylic paint", "Alkyd", "Epoxy", "Polyamide (PA)", "Pan acrylic fibre", "Polyethylene (PE)", "Polyester (PET)", "Polypropylene (PP)", "Polystyrene (PS)", "Polyurethane (PU)", "Polyvinyl acetate (PVAC)", "Poly vinyl chloride (PVC)", "Styrene butadiene rubber (SBR)", "Vinyl copolymere"))+
theme(legend.position = "bottom",
legend.background = element_rect(fill = "#FFFCFB", # Background
colour = 1),
legend.title = element_text(family = "sans",
color = "black",
size = 10,
face = 2)) +
theme(panel.grid.minor = element_line(color = "#D4CDCB",
size = 0.15,
linetype = 2))+
theme(strip.text.x = element_text(size=14, face="bold",
vjust = 2, color="black")) +
#geom_text( label = label1, vjust = -1, position = position_dodge(0.90), size = 3, hjust=-0.5)+
labs(title = "Microplastics",
subtitle = "Mass Concentrations by Polymer Types",
caption = "Still missing S4 repeated samples and M1 in Campaign D. S4 in Campaign C cumulated repetaed samples. MPs >300µm are excluded, also natural particles are excluded.",
tag = "Fig. 5-1") +
theme(plot.title = element_text(family = "serif", # Font family
face = "bold", # Font face
color = 1, # Font color
size = 16, # Font size
hjust = 1, # Horizontal adjustment
vjust = 1, # Vertical adjustment
angle = 0, # Font angle
lineheight = 1, # Line spacing
margin = margin(5, 0, 0, 0)), # Margins (t, r, b, l)
plot.subtitle = element_text(family = "serif",
hjust = 1, size=14), # Subtitle customization
plot.caption = element_text(hjust = 0.25, size =11,
family = "serif",face = "italic"), # Caption customization
plot.tag = element_text(face = "italic"), # Tag customization
plot.title.position = "plot", # Title and subtitle position ("plot" or "panel")
plot.caption.position = "panel", # Caption position ("plot" or "panel")
plot.tag.position = "top") # Tag position

how to show all x label charts ios?

I make a custom numbering label, everything works great. the problem is when the number of entries is less than X-axis maximum, the chart doesn't show any lines.
lineChart.data = data
let leftAxis = lineChart.leftAxis
//set constant label range
leftAxis.forceLabelsEnabled = true
leftAxis.labelCount = 4
leftAxis.axisMinimum = 0
leftAxis.axisMaximum = 4.5
leftAxis.granularity = 1
leftAxis.axisLineWidth = 0
leftAxis.valueFormatter = YAxisData()
//x axis label
let bottomAxis = lineChart.xAxis
bottomAxis.axisMinimum = 1
bottomAxis.axisMaximum = 7.0
bottomAxis.labelCount = 7
bottomAxis.forceLabelsEnabled = true
bottomAxis.granularity = 1
bottomAxis.axisLineWidth = 0
bottomAxis.valueFormatter = XAxisData()
bottomAxis.labelHeight = 30
if I changed the number of entries to 7, it works fine.
I want a way to show all x labels even if the number of entries is less than 7!

Set tickInterval in format HH:mm am/pm of a HIChart's Line chart using Swift 5.0

I want to set intervals as per the below image. I have tried to set using it below code.
let xAxis = HIXAxis()
xAxis.type = "datetime"
xAxis.dateTimeLabelFormats = HIDateTimeLabelFormats()
xAxis.dateTimeLabelFormats.day = HIDay()
xAxis.dateTimeLabelFormats.day.main = "%l:%M"
xAxis.min = NSNumber(value: ConverteddateFrom ) //Millisecond 12 AM midnight from starting of the day
xAxis.max = NSNumber(value: ConverteddateEnd) //Millisecond 12 AM to end of the day
xAxis.tickInterval = NSNumber(value: 4 * 3600 * 1000 )
xAxis.categories = DateList
options.xAxis = [xAxis]
let plotoptions = HIPlotOptions()
plotoptions.series = HISeries()
plotoptions.series.label = HILabel()
plotoptions.series.label.connectorAllowed = NSNumber(value: false)
// plotoptions.series.pointStart = 12
// plotoptions.series.pointInterval = NSNumber(value: 4)
// plotoptions.series.pointIntervalUnit = "AM"
options.plotOptions = plotoptions
let line1 = HILine()
line1.name = "Phase B"
line1.data = PhaseBList
let line2 = HILine()
line2.name = "Phase R"
line2.data = PhaseRList
let line3 = HILine()
line3.name = "Phase Y"
line3.data = PhaseYList
options.series = [line1, line2, line3]
options.responsive = responsive
options.colors = ["#7CB5EC","#F94F6C", "#FFB647"]
inputVoltage.options = options
but I didn't get proper x-axis with intervals. can anybody help me on this?
I am getting on x-axis points something like starting point as 20:00 to 16:00 with interval of 4 hours. I am expecting it from 12Am to 12Am. Also I can't see the data on graph.
You have 4 hour tick interval, so probably you need to change dateTimeLabelFormats from day to hour:
xAxis.dateTimeLabelFormats = HIDateTimeLabelFormats()
xAxis.dateTimeLabelFormats.hour = HIHour()
xAxis.dateTimeLabelFormats.hour.main = "%l %P"
xAxis.dateTimeLabelFormats.day = HIDay()
xAxis.dateTimeLabelFormats.day.main = "%l %P"
API Reference: https://api.highcharts.com/ios/highcharts/
I have got the solution -
1 - The problem was with the data presenting. Initially I was added the data array only whereas we have to add data along with its correspondence date. So it becomes array of array like this -
line1.data = [
[1562106600000, 0],
[1562121000000, 0.25]
]
2 - x axis time from 20:00 to 16:00 is because of UTC time. Solution is :
options.time = HITime()
options.time.useUTC = false
//options.time.timezone = "Asia/Kolkata" // If you want to set timezon you can
3 - converting the date into AM/PM in 12 hrs format.
xAxis.type = "datetime"
xAxis.dateTimeLabelFormats = HIDateTimeLabelFormats()
xAxis.dateTimeLabelFormats.hour = HIHour()
xAxis.dateTimeLabelFormats.hour.main = "%l %P"
xAxis.dateTimeLabelFormats.day = HIDay()
xAxis.dateTimeLabelFormats.day.main = "%l %P"
xAxis.min = NSNumber(value: ConverteddateFrom ) //Millisecond 12 AM midnight from starting of the day
xAxis.max = NSNumber(value: ConverteddateEnd) //Millisecond 12 AM midnight from ending of the day
xAxis.tickInterval = NSNumber(value: 4 * 3600 * 1000 )
options.xAxis = [xAxis]
This is how my graph is looking now -

Identical constraints on identical images, different behaviour?

I'm using the same image inside different imageviews, with the same constraints, yet somehow, last 2 images don't keep aspect ratios, despite constraints.
Here's the constraint code.
PS: all of them have the following 2 lines. (I just removed those lines from each group to avoid wall of code).
.contentMode = .scaleAspectFit
.translatesAutoresizingMaskIntoConstraints = false
ImageLineEvents.topAnchor.constraint(equalTo: LabelTitleEvents.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineEvents.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineEvents.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineEvents.widthAnchor.constraint(equalTo: ImageLineEvents.heightAnchor, multiplier: (ImageLineEvents.image?.size.width)! / (ImageLineEvents.image?.size.height)!).isActive = true
ImageLineUpdates.topAnchor.constraint(equalTo: LabelTitleUpdates.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineUpdates.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineUpdates.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineUpdates.widthAnchor.constraint(equalTo: ImageLineUpdates.heightAnchor, multiplier: (ImageLineUpdates.image?.size.width)! / (ImageLineUpdates.image?.size.height)!).isActive = true
ImageLineSoon.topAnchor.constraint(equalTo: LabelTitleSoon.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineSoon.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineSoon.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineSoon.widthAnchor.constraint(equalTo: ImageLineSoon.heightAnchor, multiplier: (ImageLineSoon.image?.size.width)! / (ImageLineSoon.image?.size.height)!).isActive = true
ImageLineToday.topAnchor.constraint(equalTo: LabelTitleToday.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineToday.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineToday.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineToday.widthAnchor.constraint(equalTo: ImageLineToday.heightAnchor, multiplier: (ImageLineToday.image?.size.width)! / (ImageLineToday.image?.size.height)!).isActive = true
Everything is fine in portait mode, but when I turn to landscape, somehow last 2 images do not keep aspect ratios. I have logs from each orientation.
print("ar = \(Float((ImageLineEvents.image?.size.width)!) / Float((ImageLineEvents.image?.size.height)!))")
print("ar = \(Float((ImageLineUpdates.image?.size.width)!) / Float((ImageLineUpdates.image?.size.height)!))")
print("ar = \(Float((ImageLineSoon.image?.size.width)!) / Float((ImageLineSoon.image?.size.height)!))")
print("ar = \(Float((ImageLineToday.image?.size.width)!) / Float((ImageLineToday.image?.size.height)!))")
print("w = \(ImageLineEvents.frame.width)")
print("w = \(ImageLineUpdates.frame.width)")
print("w = \(ImageLineSoon.frame.width)")
print("w = \(ImageLineToday.frame.width)")
print("h = \(ImageLineEvents.frame.height)")
print("h = \(ImageLineUpdates.frame.height)")
print("h = \(ImageLineSoon.frame.height)")
print("h = \(ImageLineToday.frame.height)")
These are from portrait and everything is as expected.
ar = 162.5
ar = 162.5
ar = 162.5
ar = 162.5
w = 335.0
w = 335.0
w = 335.0
w = 335.0
h = 2.0
h = 2.0
h = 2.0
h = 2.0
Yet if I turn to landscape, last 2 have different results.
ar = 162.5
ar = 162.5
ar = 162.5
ar = 162.5
w = 684.0
w = 684.0
w = 684.0
w = 684.0
h = 4.33333333333333
h = 4.33333333333333
h = 4.0 (Why is this not 4.33 ???)
h = 4.0 (Why is this not 4.33 ???)
I looked millions of times but I still can't figure out what's wrong with this. There are no constraint errors. Visually, last 2 images do not go all over the edges, because they keep aspect ratios, yet somehow the height is lower. They are all inside a ScrollView, but I don't see how that can matter. Any help ?
EDIT:
I've added the visual result. First 2 constraints are the first image, last 2 are the last image. As you can see, their widths are not the same in landscape. The image in question is the line just below the title and it should spread from title leading to dot image trailing. All of them behave well on portrait, yet on landscape, last 2 behave differently.
Correct Behaviour
Wrong Behaviour

Axibase startime and endtime not working

Trying to make a portal that only shows 20 min of an outage time. Can't get startime to work. Tried 2 different formats. Always starting from Jan 1 1970. Please advise.
[configuration]
title = ECP_PROD_PEAKVIEW
width-units = 6
height-units = 8
offset-right = 50
update-interval = 15
display-date = true
startime = 2017-12-21 09:20:00
endtime = 2017-12-21 09:45:00
auto-scale = true
auto-period = true
entity = dnvrco-ecp01
endtime = now
alert-style = fill: red; stroke: red
and
[configuration]
title = ECP_PROD_PEAKVIEW
width-units = 6
height-units = 8
offset-right = 50
update-interval = 15
display-date = true
startime = 2017-12-21T09:20:00Z
endtime = 2017-12-21T09:45:00Z
auto-scale = true
auto-period = true
entity = dnvrco-ecp01
endtime = now
alert-style = fill: red; stroke: red
Looks like the startime setting is missing a t.
starttime = 2017-12-21 09:20:00
You can add dash symbols to make parameters more reedable:
start-time = 2017-12-21 09:20:00
end-time = 2017-12-21 09:45:00
Example: https://apps.axibase.com/chartlab/47fbef76
I would also remove the duplicate endtime setting in the [configuration] section.
In case you need to show the most recent 20 minutes, just specify the timespan and remove start-time and end-time altogether.
Both start-time and end-time settings accept calendar expressions.
start-time = previous_hour
end-time = current_hour
Or, alternatively:
timespan = 1 hour
end-time = current_hour

Resources