wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Dynamic graph link firebase data display (ios swift)

Dear Developer,

Thanks for the great work you've done with the Highcharts library.


I'm trying to use the demo you posted on iOS Dynamic Charts: https://www.highcharts.com/demo/dynamic-update

I want to customize some code:
The Firebase new data graph is updated every second.


Are these things possible?

thank you for your help.

Sincerely, :)
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hello,
Welcome to our forum and thanks for contacting us with your question!

I'm not sure what you mean because the question is not very clear.

The demo you linked shows how to update the data. How to get this data from the server (firebase) in Swift is a more general question, not related to Highcharts and I suggest you ask them, for example, on StackOverflow or look in the Swift documentation

Let me know if you have any further questions!
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

How to create a diagram in a link?
I can't find the "swift" code on your official website
https://www.highcharts.com/demo/dynamic-update
Thank you very much for your assistance
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

I found the code, but after running the emulator it is blank, what is the problem? Thank you very much for your assistance
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

import Highcharts
import UIKit

class HighliveViewController: UIViewController {

var chartView: HIChartView!

override func viewDidLoad() {
super.viewDidLoad()

chartView = HIChartView(frame: CGRect(x: view.bounds.origin.x,
y: view.bounds.origin.y + 20,
width: view.bounds.size.width,
height: 300))


let chartView = HIChartView(frame: view.bounds)
chartView.theme = "sand-signika"

let options = HIOptions()

let chart = HIChart()
chart.type = "spline"
chart.marginRight = 10
chart.events = HIEvents()
chart.events.load = HIFunction(jsFunction: "function () { var series = this.series[0]; setInterval(function () { var x = (new Date()).getTime(), // current time y = Math.random(); series.addPoint([x, y], true, true); }, 1000); }")
options.chart = chart

let time = HITime()
time.useUTC = true
options.time = time

let title = HITitle()
title.text = "Live random data"
options.title = title

let accessibility = HIAccessibility()
accessibility.announceNewData = HIAnnounceNewData()
accessibility.announceNewData.enabled = true
accessibility.announceNewData.minAnnounceInterval = 15000
accessibility.announceNewData.announcementFormatter = HIFunction(jsFunction: "function (allSeries, newSeries, newPoint) { if (newPoint) { return 'New point added. Value: ' + newPoint.y; } return false; }")
options.accessibility = accessibility

let xAxis = HIXAxis()
xAxis.type = "datetime"
xAxis.tickPixelInterval = 150
options.xAxis = [xAxis]

let yAxis = HIYAxis()
yAxis.title = HITitle()
yAxis.title.text = "Value"
let plotLines = HIPlotLines()
plotLines.value = 0
plotLines.width = 1
plotLines.color = HIColor(hexValue: "808080")
yAxis.plotLines = [plotLines]
options.yAxis = [yAxis]

let tooltip = HITooltip()
tooltip.headerFormat = "<b>{series.name}</b><br/>"
tooltip.pointFormat = "{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}"
options.tooltip = tooltip

let legend = HILegend()
legend.enabled = false
options.legend = legend

let exporting = HIExporting()
exporting.enabled = false
options.exporting = exporting

let spline = HISpline()
spline.name = "Random data"
spline.data = [
[ "x": 1506522303996, "y": 0.9008867958057089 ],
[ "x": 1506522304996, "y": 0.8231864980698256 ],
[ "x": 1506522305996, "y": 0.9825011509882808 ],
[ "x": 1506522306996, "y": 0.003652610490540442 ],
[ "x": 1506522307996, "y": 0.002609150181310582 ],
[ "x": 1506522308996, "y": 0.01461317357831804 ],
[ "x": 1506522309996, "y": 0.8999787609990089 ],
[ "x": 1506522310996, "y": 0.14058473457764165 ],
[ "x": 1506522311996, "y": 0.34443475714783733 ],
[ "x": 1506522312996, "y": 0.5556814038393371 ],
[ "x": 1506522313996, "y": 0.6196520717912178 ],
[ "x": 1506522314996, "y": 0.03434593570780475 ],
[ "x": 1506522315996, "y": 0.2980087069912135 ],
[ "x": 1506522316996, "y": 0.7572371332071955 ],
[ "x": 1506522317996, "y": 0.6794544224961554 ],
[ "x": 1506522318996, "y": 0.07563910614922953 ],
[ "x": 1506522319996, "y": 0.049179773664749016 ],
[ "x": 1506522320996, "y": 0.6572695585799792 ],
[ "x": 1506522321996, "y": 0.3828701378166286 ],
[ "x": 1506522322996, "y": 0.2583323455534311 ]
]
options.series = [spline]

chartView.options = options

self.view.addSubview(chartView)
}

}
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hi,

Can you try removing the "// current time" comment from the chart.events.load function? This should help.

Code: Select all

chart.events.load = HIFunction(jsFunction: "function () { var series = this.series[0]; setInterval(function () { var x = (new Date()).getTime(), // current time y = Math.random(); series.addPoint([x, y], true, true); }, 1000); }")
options.chart = chart

Let me know if this works.
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

The chart displays normally, but doesn't update immediately. I am here in Taiwan time. May I ask what code should I add to make it work?

Thank you very much for your patient guidance
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

Hello,
How can I solve this problem, can you give me some help? Thanks a lot
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hello,

What do you mean by:
but doesn't update immediately
because I don't fully understand.

Regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

This is the effect I want

https://www.highcharts.com/demo/dynamic-update

After removing the function of time, the graph does not run

Code: Select all

chart.events.load = HIFunction(jsFunction: "function () { var series = this.series[0]; setInterval(function () { var x = (new Date()).getTime(), // current time y = Math.random(); series.addPoint([x, y], true, true); }, 1000); }")
options.chart = chart

please what should i do :(
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hi,

As I wrote above, remove only this "// current time" comment from the chart.events.load function, not the whole one.

Regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

chart.events.load = HIFunction(jsFunction: "function () { var series = this.series[0]; setInterval(function () { var x = (new Date()).getTime(), time y = Math.random(); series.addPoint([x, y], true, true); }, 1000); }")

I removed "// current" and can't display the chart, like this code right?

Thank you for your patience
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hello,

The question is whether you can update the chart in the chart.events.load () callback function at all.

Can you use this feature in textual form and tell if the title has updated?

Code: Select all

chart.events.load = HIFunction(jsFunction: "function () { this.update({ title: { text: 'Updated text' } }) }")

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
wisdwins
Posts: 20
Joined: Sun Sep 04, 2022 3:20 am

Re: Dynamic graph link firebase data display (ios swift)

After adding the code you mentioned and adding the title, the chart is displayed but not updated every second. What is the reason?
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic graph link firebase data display (ios swift)

Hi,

The function I sent is responsible for the currency of the title, not the dynamic adding of points every second. As I wrote above, I would like you to check if it will execute correctly and the title will be changed to test if charts.events.load is executing at all

Regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/

Return to “Highcharts Usage”