Eto , Windows chart or oxyplot?

Yes i did

import clr
clr.AddReferenceByName("Eto.OxyPlot")
clr.AddReferenceByName("Eto.OxyPlot.Wpf")
clr.AddReferenceByName("OxyPlot")

but i think the method is complicated or something wrong, for example when i use this
Eto.OxyPlot.Plot()
i got this error

Runtime error (ArgumentOutOfRangeException): Specified argument was out of the range of valid values.
Parameter name: Type for 'Eto.OxyPlot.Plot' could not be found in this platform

Traceback:
  line 13, in script

I will try to find a way to make windows chart work with eto form, i don’t think oxyplot work with ironpython

IronPython is just C# with Python syntax. Again, you can try to directly use WPF. That definitely works. I think its just that you are missing some reference. Do you see any dll I mentioned? They are about 600kb in total

The dll’s created with Visual studio, i added Eto.Form, and Eto.oxyplot and Eto.oxyplot.wpf to the project than i copied them all to Rhino folder.

This created with windows form, but Eto looks better and many examples and tutorials available in Rhino website, also windows form loaded very slowly when i open the gh file.

I was looking at the Github repro. Maybe you should try: just Eto.OxyPlot.Plot() to initialize. It seems it will automatically initialize the view.
I found this Oxyplot for Eto.Mac · Issue #3 · LorenVS/Eto.OxyPlot · GitHub

But they also said, Mac is not supported. Which makes it pointless to use this Eto wrapper within the Rhino environment…

As i mentioned before Eto.OxyPlot.Plot() give an error , that why i think maybe it can’t work with Ghpython

Yeah maybe I show you later on how to do this with WPF/C# in Rhino. Should be easy. Don’t have access to Rhino currently

Thank you , i use python , c# is very complicated
I tried to design windows form in visual studio and than use the code with Ghpython , i hope Rhino developers add a tool to create design forms like in visual studio

Ok here it is:

This is how you run a Wpf window with Python

import clr

basePath = "c:\\path\\to\\your\\lib\\folder\\"


clr.AddReferenceToFileAndPath(basePath + "OxyPlot.dll")
clr.AddReferenceToFileAndPath(basePath + "OxyPlot.Wpf.dll")
clr.AddReferenceToFileAndPath(basePath + "OxyPlotExample.exe")

from OxyPlotExample import MainWindow
import System.Windows as sw
import Rhino
import OxyPlot as oxy
import System
from System.Collections.Generic import List

exWnd = MainWindow(); 
# Populate with example points
exWnd.DrawExample(50)

# Create a series from Rhino and pass it over
list = List[oxy.DataPoint]()
list.Add(oxy.DataPoint(1,5))
list.Add(oxy.DataPoint(1,6))
list.Add(oxy.DataPoint(1,7))
list.Add(oxy.DataPoint(1,8))
exWnd.Draw(list)  

exWnd.ShowDialog()

In Visual Studio create a WPF Application targeting Net Framework 4.5 (not Core!!!).
Get the nuget package OxyPlot.Wpf (downloads OxyPlot.Core).

Modify the MainWindow.xaml

<Window x:Class="OxyPlotExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OxyPlotExample"
        xmlns:oxy="http://oxyplot.org/wpf"
        mc:Ignorable="d"
        Title="Oxy Plot Example" Height="450" Width="800">
    <Grid>
        <oxy:PlotView x:Name="_plotView"></oxy:PlotView>
    </Grid>
</Window>

And in the codebehind MainWindow.cs

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OxyPlotExample
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private PlotModel _model;

        public MainWindow()
        {
            InitializeComponent();
            InitOxy();
            //DrawExample(30);
        }
        /// <summary>
        /// Initializes Oxyplot (Non-MVVM)
        /// </summary>
        private void InitOxy()
        {           
            _model = new OxyPlot.PlotModel();
            _model.Axes.Add(new LinearAxis() { Title = "X", Minimum = 0.0, Maximum = 10.0 });
            _model.Axes.Add(new LinearAxis() { Title = "Y", Minimum = 0.0, Maximum = 10.0 });              
            _plotView.Model = _model;
            DrawExample(50);
        }

        public void Draw(IEnumerable<DataPoint> points)
        {
            var series = new LineSeries(); // cache it if frequently changed
            series.Points.AddRange(points);
            _model.Series.Add(series);
            _model.InvalidatePlot(true); // Redraw
        }

        public void DrawExample(int n)
        {
            DataPoint[] points = new DataPoint[n];
            Random rnd = new Random(42);
            for (int i = 0; i < n; i++)
            {
                points[i] = new DataPoint(i*0.1, rnd.NextDouble() * 10);
            }
            Draw(points);

        }

    }
}

And compile… Don’t forget to reference the path to these files in the Python script.
If you don’t want to do the VS part, take the following example compilation:

example_bins.zip (382.0 KB)

2 Likes

Thank you very much Tom, excellent work
I will check it