Create a x-y graph with Xamarin.Mac
How do I plot a simple x-y plot with xamarin.mac? I searched the entire internet and all I could find that supports this framework is Microcharts which is very primitive and has none of the operations I want (scaling, interactivity, literally just have a y and x axis). Has anyone ever done this with xamarin.mac?
Edit: I used NSBezierPath by creating a custom view (called SpectraView) inside a view controller and connecting the custom view as an outlet and defining it as follows:
using System;
using Foundation;
using AppKit;
using CoreGraphics;
namespace HSIViewer
{
public partial class SpectraView : NSView
{
private const bool useBezeirPath = true;
public SpectraView (IntPtr handle) : base (handle)
{
Initialize();
}
// Called when created directly from a XIB file
[Export("initWithCoder:")]
public SpectraView(NSCoder coder) : base(coder)
{
Initialize();
}
public SpectraView(CGRect rect) : base(rect)
{
}
// Shared initialization code
void Initialize()
{
}
public override void DrawRect(CGRect dirtyRect)
{
if (useBezeirPath)
{
NSColor.Red.Set();
NSBezierPath.StrokeLine(new CGPoint(10, 10), new CGPoint(100, 100));
}
else
{
var context = NSGraphicsContext.CurrentContext.CGContext;
context.SetStrokeColor(NSColor.Black.CGColor);
context.SetLineWidth(1);
var rectangleCGPath = CGPath.FromRoundedRect(new CGRect(10, 10, 100, 100), 4, 4);
context.AddPath(rectangleCGPath);
context.StrokePath();
}
}
}
}
When I run the code nothing shows up in the view controller. Is there another thing I should be doing to display the graph?