Trendline with Snap to Point & Semi log Aware Trendline

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Thu Sep 03, 2015 11:06 am

Hello,
Quant wrote: *Line is converted to log curve *
http://www.youtube.com/watch?v=y55VmSIMBjE

for mathematical formula use below link
https://en.wikipedia.org/wiki/Semi-log_plot
Thank you.

Semi-log plots are perfectly feasible in TeeChart, e.g.

Code: Select all

    Line series;
    
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series = new Line(tChart1.Chart);
      series.Add(9, 25112);
      series.Add(12, 12223);
      series.Add(14, 9216);
      series.Add(16, 7488);
      series.Add(21, 4889);

      tChart1.Axes.Left.Logarithmic = true;
      tChart1.Axes.Left.Increment = 5000;
      tChart1.Axes.Left.SetMinMax(2000, 40000);
      tChart1.Axes.Bottom.SetMinMax(5, 25);
    }
Trendlines and other TeeChart functions can also be used in semi-log plots, e.g.

Code: Select all

    Line series, func;
    
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series = new Line(tChart1.Chart);
      series.Add(9, 25112);
      series.Add(12, 12223);
      series.Add(14, 9216);
      series.Add(16, 7488);
      series.Add(21, 4889);

      tChart1.Axes.Left.Logarithmic = true;
      tChart1.Axes.Left.Increment = 5000;
      tChart1.Axes.Left.SetMinMax(2000, 40000);
      tChart1.Axes.Bottom.SetMinMax(5, 25);

      func = new Line(tChart1.Chart);

      TrendFunction trend = new TrendFunction();
      trend.TrendStyle = TrendStyles.Exponential;
      func.Function = trend;
      func.DataSource = series;
    }
of the video you link to, which functionality do you need which is present in Excel but which you cannot find in TeeChart?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Quant » Thu Sep 03, 2015 11:56 am

I am using drawline tool. I cant use series as use is drawing line as per his requirement. how to make semi log lines drawn by drawline

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Thu Sep 03, 2015 1:05 pm

Hello,
Quant wrote:how to make semi log lines drawn by drawline
I'm sorry, but I don't understand this request. The DrawLine tool is designed to draw a line between two points defined by mouse clicks. This tool works as expected in semi-log charts.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Quant » Wed Sep 09, 2015 4:51 am

1) I am using drawline tool to draw a line on normal scale.
2) when i convert normal scale to semilog
3) all series got converted to semilog except the line drawn with drawline tool.
4) I want to convert this line which is drawn by drawline tool to semilog.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Wed Sep 09, 2015 10:19 am

Quant wrote:1) I am using drawline tool to draw a line on normal scale.
2) when i convert normal scale to semilog
3) all series got converted to semilog except the line drawn with drawline tool.
4) I want to convert this line which is drawn by drawline tool to semilog.
The following code does all of the above:

Code: Select all

    Line series;
    DrawLine tool;

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series = new Line(tChart1.Chart);
      series.Add(9, 25112);
      series.Add(12, 12223);
      series.Add(14, 9216);
      series.Add(16, 7488);
      series.Add(21, 4889);

      tChart1.Axes.Left.SetMinMax(2000, 40000);
      tChart1.Axes.Bottom.SetMinMax(5, 25);

      tool = new DrawLine(tChart1.Chart);

      tChart1.Draw();

      DrawLineItem line = new DrawLineItem(tool);
      line.StartPos = new PointDouble(9, 25112);
      line.EndPos = new PointDouble(21, 4889);
      tool.Lines.Add(line);

    }


    private void button4_Click(object sender, EventArgs e)
    {
      tChart1.Axes.Left.Logarithmic = true;
      tChart1.Axes.Left.Increment = 5000;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Quant » Wed Sep 09, 2015 10:52 am

we dont want predefined series. we want user to draw line same as drawing with drawline tool.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Wed Sep 09, 2015 1:31 pm

Quant wrote:we dont want predefined series. we want user to draw line same as drawing with drawline tool.
I'm afraid I don't understand what you mean here. Could you please try and be a little more specific with the use of code examples I can run here, images and videos?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Marc
Site Admin
Site Admin
Posts: 1265
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Marc » Fri Oct 09, 2015 10:29 am

Hello,
we dont want predefined series. we want user to draw line same as drawing with drawline tool.
Drawline tool may be used in normal manner. Code values will be updated according to any Axis visualisation changes. DrawLine co-ordinates can be updated at any time by customer code.

Regards,
Marc Meumann
Steema Support

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Quant » Fri Feb 19, 2016 9:38 am

Hi,

We are starting this discussion again to discuss "Semi-Log Trendline" in more detail, thereby we can help each other to solve this requirement.

Note: Following steps are based on usage of "Semi-Log Trendline" from a popular charting software.

Step 1] Consider a chart (OHLC with Candle Line) with Right Axis Semi Log Scaled as shown in below screenshot (Screen 1).
SL1.jpg
Screen 1
SL1.jpg (104.55 KiB) Viewed 22033 times
Step 2] Now a User Draws a "Semi-Log Trendline" on a Chart by using "Semi-Log Trendline" Tool as shown in below Screenshot (Screeen 2).
As shown in "Screen 2" it shows straight line drawn on semi log scaled chart.
SL2.jpg
Screen 2
SL2.jpg (108.21 KiB) Viewed 22031 times

Step 3] When user changes Semi log scale to Arithmetic scale, then previously drawn straight line becomes a curved line as shown in below screenshot (Screen 3).
SL3.jpg
Screen 3
SL3.jpg (105.02 KiB) Viewed 22026 times
Above three steps comprises of Semi Log Trendline working.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Mon Feb 22, 2016 12:05 pm

Quant wrote: Above three steps comprises of Semi Log Trendline working.
Here it is working in TeeChart:

Code: Select all

    Line series;
    DrawLine tool;

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      series = new Line(tChart1.Chart);
      series.Add(9, 25112);
      series.Add(12, 12223);
      series.Add(14, 9216);
      series.Add(16, 7488);
      series.Add(21, 4889);

      tChart1.Axes.Left.SetMinMax(2000, 40000);
      tChart1.Axes.Bottom.SetMinMax(5, 25);

      tChart1.Axes.Left.Logarithmic = true;
      tChart1.Axes.Left.Increment = 5000;

      tool = new DrawLine(tChart1.Chart);

      DrawLineItem line = new DrawLineItem(tool);
      line.StartPos = new PointDouble(9, 25112);
      line.EndPos = new PointDouble(21, 4889);
      tool.Lines.Add(line);

    }

    private List<PointDouble> CalcCurve()
    {
      List<PointDouble> result = new List<PointDouble>();

      Point start = new Point(tChart1.Axes.Bottom.CalcXPosValue(tool.Lines[0].StartPos.X), tChart1.Axes.Left.CalcYPosValue(tool.Lines[0].StartPos.Y));
      Point end = new Point(tChart1.Axes.Bottom.CalcXPosValue(tool.Lines[0].EndPos.X), tChart1.Axes.Left.CalcYPosValue(tool.Lines[0].EndPos.Y));
      double dxdy = (double)Math.Abs(start.X - end.X) / (double)Math.Abs(start.Y - end.Y);

      int count = 0;

      for (int i = start.Y; i <= end.Y; i++)
      {
        result.Add(new PointDouble(tChart1.Axes.Bottom.CalcPosPoint(start.X + Utils.Round(count * dxdy)), tChart1.Axes.Left.CalcPosPoint(i)));
        count++;
      }

      return result;
    }

    private void button4_Click(object sender, EventArgs e)
    {
      if(tChart1.Axes.Left.Logarithmic)
      {
        List<PointDouble> list = CalcCurve();
        Line newLine = new Line(tChart1.Chart);
        newLine.Color = Color.Black;
        newLine.Legend.Visible = false;
        tChart1.Legend.LegendStyle = LegendStyles.Values;
        foreach (var item in list)
        {
          newLine.Add(item.X, item.Y);
        }
        tool.Active = false;
      }
      else
      {
        if(tChart1.Series.Count > 1)
        {
          tChart1.Series.RemoveAt(1);
        }
        tool.Active = true;
      }

      tChart1.Axes.Left.Logarithmic = !tChart1.Axes.Left.Logarithmic;
    }
Step 1:
export635917393165277370.png
export635917393165277370.png (23.04 KiB) Viewed 22010 times
Step 2:
export635917393212439633.png
export635917393212439633.png (21.26 KiB) Viewed 22009 times
This is just a proof of concept that TeeChart is capable of rendering this change from [straight line in log] -> [curve in non-log] ... the actual implementation of this in your context may be a little different.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Quant » Mon Mar 14, 2016 8:43 am

Thanks for the reply. Yes sample code is working as per the same concept.

But how can we draw semi log trend line vice versa i.e. [curve in non-log] --> [straight line in log]. Could you please provide the sample code for the same?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Trendline with Snap to Point & Semi log Aware Trendline

Post by Christopher » Mon Mar 14, 2016 9:00 am

Quant wrote:But how can we draw semi log trend line vice versa i.e. [curve in non-log] --> [straight line in log]. Could you please provide the sample code for the same?
Again, I'm not sure about your requirements here, but the code I sent you can be engineered to work in reverse so that it draws the "log curve" in the non-log plot and vice-versa. I'm afraid I don't have the time at the moment to actually write the code for you.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply