Commit Latest
This commit is contained in:
21
PortfolioManager/ViewModels/PlotterWorkspaceViewModel.cs
Normal file
21
PortfolioManager/ViewModels/PlotterWorkspaceViewModel.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using ScottPlot.Avalonia;
|
||||||
|
|
||||||
|
namespace PortfolioManager.ViewModels
|
||||||
|
{
|
||||||
|
public class PlotterLoadedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public AvaPlot AvaPlot { get; set; } = default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class PlotterWorkspaceViewModel : WorkspaceViewModel
|
||||||
|
{
|
||||||
|
public EventHandler<PlotterLoadedEventArgs> OnPlotterLoadedEventHandler;
|
||||||
|
|
||||||
|
public void OnPlotterLoaded(AvaPlot avaPlot)
|
||||||
|
{
|
||||||
|
EventHandler<PlotterLoadedEventArgs> handler = this.OnPlotterLoadedEventHandler;
|
||||||
|
if (null != handler) handler(this, new PlotterLoadedEventArgs() { AvaPlot = avaPlot });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using MarketData.DataAccess;
|
||||||
|
using MarketData.MarketDataModel;
|
||||||
using ScottPlot.Avalonia;
|
using ScottPlot.Avalonia;
|
||||||
|
using ScottPlot.Plottables;
|
||||||
|
using ShimSkiaSharp;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace PortfolioManager.ViewModels
|
namespace PortfolioManager.ViewModels
|
||||||
{
|
{
|
||||||
public partial class ScottPlotViewModel : WorkspaceViewModel
|
|
||||||
|
|
||||||
|
|
||||||
|
public partial class ScottPlotViewModel : PlotterWorkspaceViewModel
|
||||||
{
|
{
|
||||||
|
private AvaPlot plotter = default;
|
||||||
public ScottPlotViewModel()
|
public ScottPlotViewModel()
|
||||||
{
|
{
|
||||||
double[] dataX = { 1, 2, 3, 4, 5 };
|
OnPlotterLoadedEventHandler += PlotterLoadedEvent;
|
||||||
double[] dataY = { 1, 4, 9, 16, 25 };
|
}
|
||||||
|
|
||||||
// AvaPlot avaPlot = this.Find<AvaPlot>("AvaPlot");
|
public void PlotterLoadedEvent(object sender, PlotterLoadedEventArgs e)
|
||||||
// ((ScottPlotViewModel)DataContext).Plotter = avaPlot;
|
|
||||||
|
|
||||||
|
|
||||||
if (Plotter != null)
|
|
||||||
{
|
{
|
||||||
Plotter.Plot.Add.Scatter(dataX, dataY);
|
Prices prices = PricingDA.GetPrices("SPY", 180);
|
||||||
Plotter.Refresh();
|
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 *************************
|
// ********************************************** P E R S I S T E N C E *************************
|
||||||
public override bool CanPersist()
|
public override bool CanPersist()
|
||||||
{
|
{
|
||||||
@@ -35,10 +56,5 @@ namespace PortfolioManager.ViewModels
|
|||||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// **********************************************************************************************
|
|
||||||
|
|
||||||
public AvaPlot Plotter { get; set; } = default;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,5 +11,5 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:DataType="vm:ScottPlotViewModel"
|
x:DataType="vm:ScottPlotViewModel"
|
||||||
x:Class="PortfolioManager.Views.ScottPlotView">
|
x:Class="PortfolioManager.Views.ScottPlotView">
|
||||||
<ScottPlot:AvaPlot Name="AvaPlot"/>
|
<ScottPlot:AvaPlot Name="AvaPlot" Loaded="AvaPlot_Loaded"/>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -10,16 +10,22 @@ namespace PortfolioManager.Views;
|
|||||||
|
|
||||||
public partial class ScottPlotView : UserControl
|
public partial class ScottPlotView : UserControl
|
||||||
{
|
{
|
||||||
|
private AvaPlot avaPlot = default;
|
||||||
public ScottPlotView()
|
public ScottPlotView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
AvaPlot avaPlot = this.Find<AvaPlot>("AvaPlot");
|
|
||||||
avaPlot.Loaded += OnLoadedEvent(this, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnLoadedEvent(object sender, EventArgs args)
|
private void AvaPlot_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// if (null == tabControl) return;
|
// This code will execute when the AvaPlot is loaded
|
||||||
// tabControl.SelectedIndex = args.Index;
|
if (sender is ScottPlot.Avalonia.AvaPlot)
|
||||||
|
{
|
||||||
|
if (default == avaPlot)
|
||||||
|
{
|
||||||
|
PlotterWorkspaceViewModel viewModel = (DataContext as PlotterWorkspaceViewModel);
|
||||||
|
viewModel.OnPlotterLoaded(this.Find<AvaPlot>("AvaPlot"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user