These are chat archives for oxyplot/oxyplot

24th
Apr 2016
CharlesMcBaker
@CharlesMcBaker
Apr 24 2016 00:58

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;

namespace motor_characteristics_V1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        //graph1();
    }


    //Declaration of variables
    int st = 600;           //Stall Torque g*cm
    int nl = 3000;         // NoLoad Speed rpm
    int stc = 15;          // stall current   
    int nlc = 1;          // NoLoad current




    public void graph1()
    {
        var plotModel1 = new PlotModel();
        plotModel1.Subtitle = "Test";
        plotModel1.Title = "Test2";

        ///////////////////////////////////////////////////////////////////////////////////////// X AXIS////////////////////
        //Add X Axis/////////////////////////////
        var linearAxisX = new LinearAxis();
        linearAxisX.AbsoluteMaximum = st;
        linearAxisX.AbsoluteMinimum = 0;
        linearAxisX.Maximum = st;
        linearAxisX.Minimum = 0;
        ////////////OfSet X
        linearAxisX.AxisDistance = 20;
        linearAxisX.AxislineStyle = LineStyle.Solid;
        linearAxisX.Position = AxisPosition.Bottom;
        plotModel1.Axes.Add(linearAxisX);
        //////////// Major & Minor Gridlines X
        linearAxisX.MajorGridlineStyle = LineStyle.Solid;
        linearAxisX.MinorGridlineStyle = LineStyle.Solid;
        ///////////////////////////////////////////////////////////////////////////////////////// Y AXIS////////////////////
        //Add Y Axis/////////////////////////////
        var linearAxisY = new LinearAxis();
        linearAxisY.AbsoluteMaximum = nl;
        linearAxisY.AbsoluteMinimum = 0;
        linearAxisY.Maximum = nl;
        linearAxisY.Minimum = 0;
        ////////////OfSet Y 
        linearAxisY.AxisDistance = 20;
        linearAxisY.AxislineStyle = LineStyle.Solid;
        plotModel1.Axes.Add(linearAxisY);
        //////////// Major & Minor Gridlines Y
        linearAxisY.MajorGridlineStyle = LineStyle.Solid;
        linearAxisY.MinorGridlineStyle = LineStyle.Solid;



        plot.Model = plotModel1;
        plot.Model.Series.Add(GetFunction());

    }




    private void button1_Click(object sender, EventArgs e)
    {
        graph1();
    }


    public FunctionSeries GetFunction()
    {
        int nx = 600;
        int ny = 1;

        FunctionSeries serie = new FunctionSeries();
        for (int x = 0; x < nx; x++)
        {
            for (int y = 0; y < ny; y++)
            {
                //adding the points based x,y
                DataPoint data = new DataPoint(x, getValue(x, y));

                //adding the point to the serie
                serie.Points.Add(data);
            }
        }
        //returning the serie
        return serie;
    }



    private double getValue(int x, int y)

    {
        int nlv = nl;
        int stv = st;
        return (nl-((nl/ st)*x));
    }




    //y=  nl - ((nl/st)*x)



}

}

CharlesMcBaker
@CharlesMcBaker
Apr 24 2016 03:10
Well i kinda figured it all out however i its seems very simple for 1 x-axis and 1 y-axis.
But with multiple Y-Axis that is populated by indirectly related data points such as as Torque on the main X-Axis and Speed (0-2000 Nm) Y-axis 1 and Efficiency(0-100%) on the Y-Axis 2 the documentation seems really vague. Anyone can help me to assign different datapoints to different Y-Axis.
Gor Rustamyan
@Soarc
Apr 24 2016 08:38
Each Axis had Key property
On Series, there is XAxisKey and YAxisKey
Using this properties, you can "say" series, with which axis's it should plot.
Gor Rustamyan
@Soarc
Apr 24 2016 13:05
This message was deleted
CharlesMcBaker
@CharlesMcBaker
Apr 24 2016 17:15
@Soarc could you give me an example :) ?
Gor Rustamyan
@Soarc
Apr 24 2016 18:34
Something like this
var xKey = "XAxis";
var y1Key = "YAxis1";
var y2Key = "YAxis2";
        var model = new PlotModel();
        var xAxis = new LinearAxis
        {

            Key = xKey,



        };
        var yAxis1 = new LinearAxis
        {
            Key=y1Key,
            StartPosition=0,
            EndPosition=0.5
        };

        var yAxis2 = new LinearAxis
        {
            Key = y2Key,
            StartPosition = 0.5,
            EndPosition = 1
        };


        var series1 = new FunctionSeries(Math.Sin, 0, 2 * Math.PI, 0.1);
        series1.XAxisKey = xKey;
        series1.YAxisKey = y1Key;

        series1.Color = OxyColors.Green;

        var series2 = new FunctionSeries(Math.Cos, 0, 2 * Math.PI, 0.1);
        series2.XAxisKey = xKey;
        series2.YAxisKey = y2Key;

        series2.Color = OxyColors.Red;


        model.Axes.Add(xAxis);
        model.Axes.Add(yAxis1);
        model.Axes.Add(yAxis2);

        model.Series.Add(series1);
        model.Series.Add(series2);
CharlesMcBaker
@CharlesMcBaker
Apr 24 2016 19:52
thanx let me look into this :)
CharlesMcBaker
@CharlesMcBaker
Apr 24 2016 21:59
It seems to be working with some tweaks
    public void graph2() //2Axis Scaling with different datapoints
    {
        var y1Key = "YAxis1";
        var y2Key = "YAxis2";

        var model = new PlotModel();
        var yAxis1 = new LinearAxis
        {
            Key = y1Key,
        };

        var yAxis2 = new LinearAxis
        {
            Key = y2Key,
        };

        yAxis2.Position = AxisPosition.Right;
        yAxis2.AxisDistance = 80;
        yAxis1.Position = AxisPosition.Left;
        yAxis1.AxisDistance = 40;


        var series1 = new FunctionSeries(Math.Sin, 0, 2 * Math.PI, 0.1);

        series1.YAxisKey = y1Key;
        series1.Color = OxyColors.Green;

        var series2 = new FunctionSeries(Math.Cos, 0, 2 * Math.PI, 0.1);

        series2.YAxisKey = y2Key;
        series2.Color = OxyColors.Red;

        model.Axes.Add(yAxis1);
        model.Axes.Add(yAxis2);

        model.Series.Add(series1);
        model.Series.Add(series2);

        aaaa.Model = model; //aaa is the oxyplot control in Win Form App

    }

    private void button1_Click(object sender, EventArgs e)
    {
        graph2();
    }
It seems to be working with some tweaks
test.png
Now I'm wondering how i Scale the Left-Y-Axis, and apply the same scale to the Right-Y-Axis simultaneously.