i am currently working on an app that involves a pie chart. And i am struggling to figure out how to make the segments of the pie graph behave as UIButtons. I have found how to do what i am looking for on bar graphs, but it doesnt seem to be the same with pie graphs.
I am using IOSCharts, I have added ChartViewDelegate to the class header, pieView.delegate = self is in the viewDidLoad().
This is the current function i am using to try and use the touchevents
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: Highlight) {
print("Triangle")
}
I replicated your scene of the problem with the new function:
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
print("Triangle")
}
And it is working as expected, so I'm guessing your problem is not in the code.
Be sure to check for typos or that your pieView is linked correctly.
Apologies for the late answer.
Related
I am using an MKMapView wrapped in UIVIewRepresentable under SwiftUI to display various locations on the map. The data is fetched from a Google Firestore collection and annotations added to the map view when the app loads - no problem there. Locations are also loaded into a lazy grid for display - also no problems.
The issue arises if a new location is added to the Firestore set no corresponding annotation(s) will be added to the map view. They will be aded to the lazy grid however.
Locations in Firestore can be deleted and the annotations on the map will be removed, data can be edited (like text values for display) and these will update on the map.
I'm not sure where to go from here to solve the issue ...
the updateUIView code > 'siteData' is a simple array of site structs and populated from Firestore.
func updateUIView(_ uiView: MKMapView, context: Context) {
if siteData.count != uiView.annotations.count {
uiView.removeAnnotations(uiView.annotations)
for points in siteData {
let annotation = SiteAnnotation(title: points.name, subtitle: points.shortDescription, site: points, coordinate: points.locationCoordinate)
uiView.addAnnotation(annotation)
}
}
uiView.showsUserLocation = true
}
}
What am I missing in this?
Came back to this this morning and realized that the uiView.annotations.count is including the pin for the user's location marked on the map. So when if siteData.count != uiView.annotations.count {, the siteData.count and uiView.annotations.count are actually equal.
Guess it's the little things that can really trip us up.
I am using ios-charts in swift language. I'm wanting to show more data about each node when they are selected. A marker wouldn't have enough space for all the info I am wanting to display so I am wanting to display it all in a dedicated label on the ViewController itself. Is there any way to do this?
I got the chartValueSelected method working but am not sure how to utilize it for this.
Included ChartViewDelegate
&
chtChart.delegate = self
I have an array called textNotes thats corresponds to each data entry in the array and made a label called infoLabelChart
func chartValueSelected(_ chartView: ChartViewBase, entry:
ChartDataEntry, highlight: Highlight) {
let pos = NSInteger(entry.x)
infoLabelChart.text = "\(textNotes[pos])"
}
I want to make a link reference within the same file in Swift kind of like the way you can in JavaDoc, but I can't seem to find documentation describing how to do this. You can only reference external URLS. I want to be able to do something like this:
class myClass : UIView {
/// The label that displays the scale of this view
/// - seealso: [showScaleView](showScaleView())
private lazy var scaleView: UIView = UIView()
/// Shows the scale view
/// - seealso: [scaleView](scaleView)
private func showScaleView() {
...
}
}
This known issue in Xcode since Jan 2018... :(
Here is radar: https://github.com/lionheart/openradar-mirror/issues/19263
I want to only highlight a data point when the finger is on the chart, as soon as it lifts off the screen I want to call, or simple deselect the highlight.
func chartValueNothingSelected(chartView: ChartViewBase) {
print("Nothing Selected")
markerView.hidden = true
}
I've tried to override the touch ended but haven't gotten it to work.
You can turn off highlighting any bars/data all together using the highlightEnabled property.
Example of this is:
barChartView.data?.highlightEnabled = false
If you still want to be able to highlight values, but want them to automatically deselect after the touch has ended, I also found another function highlightValues(highs: [ChartHighlight]?) which says in the documentation..
Provide null or an empty array to undo all highlighting.
Call this when you want to deselect all the values and I believe this will work. Example of this could be:
let emptyVals = [ChartHighlight]()
barChartView.highlightValues(emptyVals)
Ref:
Charts Docs: highlightValues documentation
If you don't have to do anything with the tapped data you can use:
barChartView.data?.highlightEnabled = false
If you want to use the tapped data point without displaying the highlight lines, you can use the selection delegate (don't forget to add ChartViewDelegate to your class):
yourChartView.delegate = self // setup the delegate
Add delegate function:
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
// do something with the selected data entry here
yourChartView.highlightValue(nil) // deselect selected data point
}
I have made printing functionality for custom NSView of NSPopover by the assigning the following action to button for this NSView in mainController:
#IBOutlet var plasmidMapIBOutlet: PlasmidMapView!
#IBAction func actionPrintfMap(sender: AnyObject)
{
plasmidMapIBOutlet.print(sender)
}
It is working, but the print window has no option for Paper Size and Orientation, see screenshot below.
What should I do to get these options in the print window?
And, how to make the NSView fitting to the printable area? Now it is not fitting.
I have figured out some moments, but not completely. So, I can setup the printing by the following code
#IBAction func actionPrintMap(sender: AnyObject)
{
let printInfo = NSPrintInfo.sharedPrintInfo()
let operation: NSPrintOperation = NSPrintOperation(view: plasmidMapIBOutlet, printInfo: printInfo)
operation.printPanel.options = NSPrintPanelOptions.ShowsPaperSize
operation.printPanel.options = NSPrintPanelOptions.ShowsOrientation
operation.runOperation()
//plasmidMapIBOutlet.print(sender)
}
But, I still have problem. From the code above I can get only orientation (the last, ShowsOrientation), but not both PaperSize and Orientation. How can I manage both ShowsPaperSize and ShowsOrientation?
Finally I have found the answer which is simple to write but it is not really obvious from apple documentation.
operation.printPanel.options.insert(NSPrintPanelOptions.showsPaperSize)
operation.printPanel.options.insert(NSPrintPanelOptions.showsOrientation)
The problem in the code originally posted is that options is being assigned twice, so the first value assigned, ShowsPaperSize is overwritten by the value ShowsOrientation. That's why you only see the ShowsOrientation option in the dialog.
By using multiple insert operations, you are adding options rather than overwriting each time. You can also do it this way which I think reads better:
operation.printPanel.options.insert([.showsPaperSize, .showsOrientation])
And finally, it also works to "set" the options, and by supplying the existing options as the first array value, you achieve the affect of appending:
operation.printPanel.options = [
operation.printPanel.options,
.showsPaperSize,
.showsOrientation
]
(The first array element operation.printPanel.options means that the old options are supplied in the list of new options.)