Swift Charts Library, when first Loaded, highlighted value already - ios

enter link description here
I used Charts/danielgindi..
When a graph is selected, the highlight works properly. But what I want is to highlight the center graph on the first screen when no graph is selected.
chartView.highlightValue(x: 3, dataSetIndex: 3, dataIndex: 3)
chartView.highlightValue(Highlight(x: 3, dataSetIndex: 3, stackIndex: 3))
I wrote the code in the same way as above, but it failed.

solution
let midPoint = CGPoint(x: chartView.bounds.midX, y: chartView.bounds.midY)
let h = chartView.getHighlightByTouchPoint(midPoint)
chartView.highlightValue(h, callDelegate: true)

Related

How to draw a line in line chart for single value in Charts(IOS)

I need to draw a single value in line chart. Currently i am using ios-charts library for line graph purpose.
The data will be varied some times i'll get the single data inside the data set at that time i need to draw the single value in the line chart.
What i am getting:
What i required:
The library cannot do this automatically, but there is the following option.
You check if your data contains exactly one point. If yes, then you add a so called LimitLine.
For example:
let limitLine = ChartLimitLine(
limit: value,
label: labelText)
limitLine.lineColor = .blue
limitLine.labelPosition = .topLeft
limitLine.valueFont = UIFont.systemFont(ofSize: 14)
chartView.leftAxis.addLimitLine(limitLine)
For Swift Charts (Xcode 14 Beta)
Should someone decide to do something similar with Apple's Swift Charts, RuleMark() can be used to draw the line and PointMark() for a point like this:
Chart() {
RuleMark(
xStart: .value("Start", 0),
xEnd: .value("End", 20),
y: .value("Value", 125)
)
PointMark(
x: .value("X Value", 10),
y: .value("Y Value", 125)
)
}
Example Output:

Zoom in to specific coordinates in PDFKit using swift

I am using pdfkit to open pdf file in my app.
I want to zoom in to specific coordinates.
Let say Following is my pdf page and I want to zoom in to specific coordinates when user will click on pencil button.
After clicking on pencil button it should be look like following image.
I've searched a lot but couldn't find any proper solution for that. I don't want to use third party libraries to do that.
I solved this problem by using following code.
let documents = pdfView.document
if let page = documents?.page(at: 0) {
pdfView.scaleFactor = pdfView.scaleFactorForSizeToFit * 2
pdfView.go(to: CGRect(x: 0, y: 0, width: 300, height: 300), on: page)
}
This is the zoom in code to specific coordinates.
There is one more thing that needs attention. You need to turn off
pagination pdfView.usePageViewController(false).

Shonobi Data Grid scroll to a specific row

I have two grid let say grid a and grid b. Value of grid a is (1, 2, 3, 4, 5, ... 50) and in grid b (3, 5, 10, 25) .
I need when I click row with value 10 in grid b, then grid a will automatically scroll to row with value 10 too. Below code I have been try :
gridRoomStatus?.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true)
self.gridRoomStatus?.reloadColumns(self.gridRoomStatus?.columns)
I have that code to make grid a go to the top when grid b is clicking. But it's still not solving my problem. I can't get a specific point for row with specific value. In UITableView there are tableView.rectForRow(at: indexPath) but I can't find similar function with that in Shinobi data Grid. How to do that?
Here I solved this problem, example :
let rowHeight = 50
let rowIndexToSnapTo = 20
grid.setContentOffset(CGPoint(x: 0, y: rowHeight * rowIndexToSnapTo))

Troubleshooting UIKit display issues

I have a very strange issue where a chart (SwiftChart) is not being displayed (is not visible/rendered) when the project is built and run.
Some background:
XCode 8 (project was originally and XCode 7 project)
Objective C project/ViewControllers
A swift file to render the chart (have tried calling this from viewDidLoad & viewDidLayoutSubviews)
Storyboard containing all ui elements
Using CocoaPods
The 'print' code you see in Swift outputs 'null'
The UIView where the chart is to be rendered exists within the storyboard and is setup as follows
The code being called is:
let chart = Chart()
print(chart.window?.frame.width)
print(chart.window?.frame.height)
let data = [(x: 0.0, y: 0), (x: 3, y: 2.5), (x: 4, y: 2), (x: 5, y: 2.3), (x: 7, y: 3), (x: 8, y: 2.2), (x: 9, y: 2.5)]
let series = ChartSeries(data: data)
series.area = true
chart.xLabels = [0, 3, 6, 9, 12, 15, 18, 21, 24]
chart.xLabelsFormatter = { String(Int(round($1))) + "h" }
chart.add(series)
Visually I see nothing. I'm struggling to figure out where the problem might be so any pointers greatly appreciated
You uave to initialize it with a frame when creating it programmatically since it's a UIControl subclass. It appears their first code example is wrong but they explain it correctly in the next. All on-screen views need a frame at a minimum.
But if you already have a view of this class in your storyboard you need an outlet to point to it. Your first line of code creates a new one, so you're not talking to the one you set up, but an improperly created off-screen one.
So add an outlet and connect it to your view so you can talk to it.

highcharts column graph with dynamic data- column alignment off

i'm hoping that this quick description and image will ring a bell with someone who has had a similar issue and therefore a suggestion/fix.
i have a column graph that i am adding data to dynamically (via jQuery parsing an XML file).
for some reason, after the data is added, the alignment of the different series gets a little off. the issue fixes itself after i toggle one of the series by being visible/invisible (by clicking the series in the legend).
when i add the data via hardcoding the numbers, just to ensure it works, it works great.
here is the image:
the yellow series is the last series added to the chart, the red and purple series line up ok after toggling the visibility of one of the 5 series.
any help would be greatly appreciated!
UPDATE with info on the data:
i have 5 series of data and 10 x-axis categories
i am building a multidimensional array of data as i parse the XML file
the array length is 5, with each of those 5 index's containing an array of length 10
this is what the array looks like after it has been populated with data:
index#: 0 value: 0,0,0,0,0,0,0,0,0,0
index#: 1 value: 180,210,0,0,0,0,0,0,180,210
index#: 2 value: 22,4,0,0,0,0,0,0,22,4
index#: 3 value: 0,0,0,0,0,0,0,0,0,0
index#: 4 value: 200,30,0,0,0,0,0,0,4,0
i am adding the data to the chart with the following JS code:
for (var c_ary_bs = 0; c_ary_bs < ary_bs_schedule_orig.length; c_ary_bs++) {
chart.series[c_ary_bs].setData(ary_bs_schedule_orig[c_ary_bs]);
}
hopefully that will help, thank you!
UPDATE 2, some more info
i've hard coded the data being added to the array, to help pinpoint the issue:
chart.series[0].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
chart.series[1].setData([180, 210, 0, 0, 0, 0, 0, 0, 180, 210]);
chart.series[2].setData([22, 4, 0, 0, 0, 0, 0, 0, 22, 4]);
chart.series[3].setData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
chart.series[4].setData([200, 30, 0, 0, 0, 0, 0, 0, 4, 0]);
alert('done')
when the alert fires, the graph columns are aligned properly, after I click "ok" to dismiss the alert, the alignment issue happens, as the previous image depicts.
I found an imperfect fix:
-setting the marginLeft of the chart to 70 alleviates the issue with the columns not aligning
-for some reason the y-axis title text is displaying over the y-axis ticks, so i am using the following to make it visible:
yAxis: {
title: {
x:-20,
text: 'Schedule Days'
}
}
(note the x: -20)
Whats's odd is that when I toggle one of the series (by clicking it in the legend) the yAxis title text reverts to where it should be (which is now 20px off because of the above fix).
The perfect fix would put the yAxis text where it is after I toggle one of the series, but at least this way it is now visible regardless of whether or not the user toggles the series.

Resources