CustomTick overlap problem.

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
ehdrnsep
Posts: 48
Joined: Mon Jan 12, 2015 6:52 am

CustomTick overlap problem.

Post by ehdrnsep » Tue Nov 22, 2016 9:03 am

Hello.

I using segment and custom tick.

if axis "RangeChanged" event fired, update custom ticks. (axis InvalidateCustomTicks method called)

How to fix this ploblem?
Attachments
1.png
1.png (45 KiB) Viewed 11109 times

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomTick overlap problem.

Post by ArctionPasi » Wed Nov 23, 2016 4:04 pm

Hello,

I made this test app. Red Y axis has CustomAxisTicks. When giving new range for the red axis, the space adjusts correctly.
Custom axis ticks in red axis
Custom axis ticks in red axis
CustomTicksInRedAxis.jpg (120.46 KiB) Viewed 11102 times

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Axes;
using Arction.WinForms.Charting.Views;
using Arction.WinForms.Charting.Views.ViewXY; 

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        LightningChartUltimate _chart; 

        public Form1()
        {
            InitializeComponent();

            CreateChart();
        }

        void CreateChart()
        {
            _chart = new LightningChartUltimate();
            _chart.BeginUpdate();

            _chart.Parent = this;
            _chart.Dock = DockStyle.Fill;

            ViewXY v = _chart.ViewXY;
            
            v.AxisLayout.Segments.Add(new YAxisSegment(v.AxisLayout));
            v.AxisLayout.Segments.Add(new YAxisSegment(v.AxisLayout));
            v.AxisLayout.Segments.Add(new YAxisSegment(v.AxisLayout)); 

            v.AxisLayout.YAxesLayout = YAxesLayout.Segmented;
            v.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllLeft;
            
            foreach (AxisY yAxis in v.YAxes)
                yAxis.Dispose(); 
            v.YAxes.Clear(); 

            AxisY yAxis1 = new AxisY(v);
            yAxis1.SegmentIndex = 0;
            yAxis1.AxisColor = Color.Yellow; 
            v.YAxes.Add(yAxis1);

            AxisY yAxis2 = new AxisY(v);
            yAxis2.SegmentIndex = 0;
            yAxis2.AxisColor = Color.Red;
            yAxis2.CustomTicksEnabled = true;
            yAxis2.AutoFormatLabels = false; 
            yAxis2.RangeChanged += yAxis2_RangeChanged;
            UpdateAxis2CustomTicks(yAxis2, yAxis2.Minimum, yAxis2.Maximum);

            v.YAxes.Add(yAxis2);

            AxisY yAxis3 = new AxisY(v);
            yAxis3.SegmentIndex = 0;
            yAxis3.AxisColor = Color.Yellow;
            v.YAxes.Add(yAxis3);

            AxisY yAxis4 = new AxisY(v);
            yAxis4.SegmentIndex = 1;
            yAxis4.AxisColor = Color.Yellow;
            v.YAxes.Add(yAxis4);

            AxisY yAxis5 = new AxisY(v);
            yAxis5.SegmentIndex = 2;
            yAxis5.AxisColor = Color.Yellow;
            v.YAxes.Add(yAxis5);

            _chart.EndUpdate(); 
        }

        void yAxis2_RangeChanged(object sender, RangeChangedEventArgs e)
        {
            UpdateAxis2CustomTicks(sender as AxisY, e.NewMin, e.NewMax); 
        }

        void UpdateAxis2CustomTicks(AxisY yAxis, double min, double max)
        {
            _chart.BeginUpdate(); 

            yAxis.CustomTicks.Clear();
            yAxis.CustomTicks.Add(new CustomAxisTick(yAxis, min, min.ToString("0.0000")));
            yAxis.CustomTicks.Add(new CustomAxisTick(yAxis, (min + max) / 2.0, ((min + max) / 2.0).ToString("0.0000")));
            yAxis.CustomTicks.Add(new CustomAxisTick(yAxis, max, max.ToString("0.0000")));
            yAxis.InvalidateCustomTicks();

            _chart.EndUpdate();
        }
    }
}
I hope this helps :)
LightningChart Support Team, PT

Post Reply