60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System;
|
|
using MarketData.DataAccess;
|
|
using MarketData.MarketDataModel;
|
|
using ScottPlot.Avalonia;
|
|
using ScottPlot.Plottables;
|
|
using ShimSkiaSharp;
|
|
using SkiaSharp;
|
|
|
|
namespace PortfolioManager.ViewModels
|
|
{
|
|
|
|
|
|
|
|
public partial class ScottPlotViewModel : PlotterWorkspaceViewModel
|
|
{
|
|
private AvaPlot plotter = default;
|
|
public ScottPlotViewModel()
|
|
{
|
|
OnPlotterLoadedEventHandler += PlotterLoadedEvent;
|
|
}
|
|
|
|
public void PlotterLoadedEvent(object sender, PlotterLoadedEventArgs e)
|
|
{
|
|
Prices prices = PricingDA.GetPrices("SPY", 180);
|
|
DateTime[] dates = new DateTime[prices.Count];
|
|
double[] closes = new double[prices.Count];
|
|
|
|
for (int index = 0; index < prices.Count; index++)
|
|
{
|
|
dates[index] = prices[index].Date;
|
|
closes[index] = prices[index].Close;
|
|
}
|
|
|
|
|
|
plotter = e.AvaPlot;
|
|
// double[] dataX = { 1, 2, 3, 4, 5 };
|
|
// double[] dataY = { 1, 4, 9, 16, 25 };
|
|
// plotter.Plot.Add.Scatter(dataX, dataY);
|
|
Scatter closeScatter = plotter.Plot.Add.ScatterLine(dates, closes, ScottPlot.Color.FromSKColor(SKColors.Red));
|
|
closeScatter.LegendText = "Close";
|
|
closeScatter.LineWidth = 3;
|
|
plotter.Plot.Axes.AutoScale();
|
|
plotter.Refresh();
|
|
}
|
|
// ********************************************** P E R S I S T E N C E *************************
|
|
public override bool CanPersist()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override SaveParameters GetSaveParameters()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public override void SetSaveParameters(SaveParameters saveParameters)
|
|
{
|
|
}
|
|
}
|
|
} |