Page 1 of 1

Individual major/minor line style

Posted: Tue Sep 23, 2014 3:21 pm
by kDanil
Hello,

Thank you for your work.
We tested several chart controls recently and your chart showed the best performance.

But we have not found the option how to set custom style for individual major/minor axis line.

Is it possible?

In our application we use several line styles (dotted, dashed).

Re: Individual major/minor line style

Posted: Wed Sep 24, 2014 6:19 am
by ArctionPasi
Hello,

One axis supports only one MajorGridStyle and MinorGridStyle. All the grid lines are of same style. But there's a workaround, using LineSeriesCursors as X axis grid lines or ConstantLines as Y axis grid lines.

xAxis.GetMajorTicks gets the ticks visible on the x axis. You can then create a LineSeriesCursor/ConstantLine for each tick position (or anywhere in axis range).

Code: Select all

m_chart.ViewXY.XAxes[0].MajorGrid.Visible = false;
m_chart.ViewXY.XAxes[0].MinorGrid.Visible = false; 
m_chart.ViewXY.XAxes[0].RangeChanged += new AxisBase.RangeChangedHandler(ExamplePointLineSeriesXY_RangeChanged);

void ExamplePointLineSeriesXY_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            cancelRendering = true; 

            m_chart.BeginUpdate(); 
            
            AxisX xAxis =  ((AxisX)axis);
            double[] majorTicks =xAxis.GetMajorTicks();

            if (majorTicks != null && majorTicks.Length > 0)
            {
                m_chart.ViewXY.LineSeriesCursors.Clear();
                int iTickCount = majorTicks.Length; 

                for(int i =0;i< iTickCount;i++)
                {
                    bool bAddGridLineHere = (majorTicks[i] % 3 == 0) || (majorTicks[i] % 4 == 0);

                    if (bAddGridLineHere)
                    {
                        LineSeriesCursor cursor = new LineSeriesCursor(m_chart.ViewXY, xAxis);
                        cursor.ValueAtXAxis = majorTicks[i];
                        cursor.SnapToPoints = false;
                        cursor.Style = CursorStyle.VerticalNoTracking;
                        cursor.MouseInteraction = false;
                        if (majorTicks[i] % 3 == 0)
                        {
                            cursor.LineStyle.Pattern = LinePattern.Dash;
                            cursor.LineStyle.Width = 2;
                            cursor.LineStyle.Color = Color.Lime;
                        }
                        else if (majorTicks[i] % 4 == 0)
                        {
                            cursor.LineStyle.Pattern = LinePattern.Dot;
                            cursor.LineStyle.Width = 3;
                            cursor.LineStyle.Color = Color.Magenta;
                        }

                        m_chart.ViewXY.LineSeriesCursors.Add(cursor);
                    }
                } 
            }

            m_chart.EndUpdate(); 
        }
Chart with custom grid lines in X axis.
Chart with custom grid lines in X axis.
ChartWithCustomGridLines.jpg (174.14 KiB) Viewed 298390 times
For minor grid lines, there's no xAxis.GetMinorTicks method available. Interpolate adjacent major ticks with axis.MinorDivCount, it tells how many minor divisions there are in between major ticks.

I hope this helps :)

Re: Individual major/minor line style

Posted: Wed Sep 24, 2014 9:35 am
by kDanil
Thank you!

Re: Individual major/minor line style

Posted: Wed Sep 24, 2014 9:50 am
by kDanil
Is it possible to draw this ConstantLines with the lowest zindex?

In your attachment you can see that line is painted over the marker.
Because in my case this lines is part of the chart grid I want to draw this lines in the level of axis grid so other elements (points, lines, markers) will be above them.

Re: Individual major/minor line style

Posted: Wed Sep 24, 2014 9:56 am
by ArctionPasi
ConstantLines have Behind property. Set it to True.

LineSeriesCursors don't have and they are rendered on top of the series.

Re: Individual major/minor line style

Posted: Wed Sep 24, 2014 10:02 am
by kDanil
ArctionPasi wrote:ConstantLines have Behind property. Set it to True.

LineSeriesCursors don't have and they are rendered on top of the series.
Ok, thank you, it works.

Re: Individual major/minor line style

Posted: Thu Sep 25, 2014 3:39 pm
by fredd41
is it possible to add a different grid for each segment ?

Re: Individual major/minor line style

Posted: Thu Sep 25, 2014 4:33 pm
by ArctionPasi
is it possible to add a different grid for each segment ?
If you are referring to regular grid (not special grid made with LineSeriesCursors or ConstantLines), Y axis grid can be specified for each segment separately. Define the grid style in yAxis.MajorGrid and yAxis.MinorGrid. For example, set the LineStyle and Color for them.

Re: Individual major/minor line style

Posted: Thu Sep 25, 2014 5:08 pm
by fredd41
I need different vertical grid lines of each segment

Re: Individual major/minor line style

Posted: Thu Sep 25, 2014 5:28 pm
by ArctionPasi
I need different vertical grid lines of each segment
If you are talking about vertical grid lines (X axis grid) for each segment, it is not directly possible. Or you'll need to compose them with LineCollections. Set one SegmentLine for each grid line, and set lineCollection.Behind = true so it will show in the background.

Use ViewXY.GetGraphSegmentInfo method to gain access to screen coordinates of each segment, and use Yaxis.CoordToValue to convert screen coordinate into Y axis value. Set segment bottom as LineSegment point A and segment top as point B.

Re: Individual major/minor line style

Posted: Thu Sep 25, 2014 6:41 pm
by fredd41
ok what I need
thanks

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 1:28 pm
by fredd41
your workaround works with linecollection but I think there is a bug:

if my Y-Axis has a negative min and a negative max (ex: -50 to -10),
the lines are invisible.
I tried to switch min and max for AY and BY but it doent work.
I tried BY=math.abs(max), doesn't work

thanks

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 1:40 pm
by fredd41
same thing if min and max are positive, the lines disappear

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 2:22 pm
by fredd41
and the Behind property doesn't work, the lines are always behind the sampladataseries.

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 2:49 pm
by ArctionPasi
Behind really should work well, and LineCollections with negative values as well.

Code: Select all

 //Setup x-axis
            AxisX axisX = m_chart.ViewXY.XAxes[0];
            axisX.SetRange(0, 50);
            axisX.ScrollMode = XAxisScrollMode.None;
            axisX.ValueType = AxisValueType.Number;

            //Chart has one Y axis ready to go. Just set the range 
            m_chart.ViewXY.YAxes[0].SetRange(-200, -50);

            LineCollection gridLines = new LineCollection(m_chart.ViewXY, axisX, m_chart.ViewXY.YAxes[0]);
            SegmentLine[] lines = new SegmentLine[3];
            gridLines.LineStyle.Color = Color.White;
            gridLines.LineStyle.Pattern = LinePattern.Dash;
            gridLines.LineStyle.Width = 5; 
            gridLines.Behind = true; 

            lines[0].AX = 10;
            lines[0].AY = -80;
            lines[0].BX = 10;
            lines[0].BY = -150;

            lines[1].AX = 20;
            lines[1].AY = -80;
            lines[1].BX = 20;
            lines[1].BY = -150;

            lines[2].AX = 40;
            lines[2].AY = -80;
            lines[2].BX = 40;
            lines[2].BY = -150;

            gridLines.Lines = lines;
            m_chart.ViewXY.LineCollections.Add(gridLines);


            SampleDataSeries sds = new SampleDataSeries(m_chart.ViewXY, axisX, m_chart.ViewXY.YAxes[0]);
            sds.LineStyle.Width = 3;
            sds.LineStyle.Color = Color.Red;
            double[] samples = new double[50];
            Random rand = new Random(); 
            for (int i = 0; i < 50; i++)
            {
                samples[i] = -150 + 70.0 * rand.NextDouble(); 
            }
            sds.SamplingFrequency = 1; 
            sds.FirstSampleTimeStamp = 1.0 / sds.SamplingFrequency;
            sds.SamplesDouble = samples; 
            m_chart.ViewXY.SampleDataSeries.Add(sds); 
Custom made grid, LineCollection
Custom made grid, LineCollection
customgrid.jpg (144.6 KiB) Viewed 298355 times

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:09 pm
by fredd41
I tried your code, and the behind property doesn't work
try it
gridLines.Behind = false;

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:21 pm
by fredd41
now try this code

run the project and move the y-axis up and down
the lines will disappear if min and max > 0 or min and max < 0

thanks

Imports Arction.LightningChartUltimate.SeriesXY
Imports Arction.LightningChartUltimate
Imports Arction.LightningChartUltimate.Axes

Public Class Form2

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load


Dim axisX As AxisX = m_Chart.ViewXY.XAxes(0)
axisX.SetRange(0, 50)
axisX.ScrollMode = XAxisScrollMode.None
axisX.ValueType = AxisValueType.Number


AddHandler m_Chart.ViewXY.YAxes(0).RangeChanged, AddressOf YAxis_RangeChanged

Dim gridLines As New LineCollection(m_Chart.ViewXY, axisX, m_Chart.ViewXY.YAxes(0))
Dim lines As SegmentLine() = New SegmentLine(2) {}
gridLines.LineStyle.Color = Color.White
gridLines.LineStyle.Pattern = LinePattern.Dash
gridLines.LineStyle.Width = 5
gridLines.Behind = False

lines(0).AX = 10
'lines(0).AY = -80
lines(0).BX = 10
'lines(0).BY = -150

lines(1).AX = 20
'lines(1).AY = -80
lines(1).BX = 20
'lines(1).BY = -150

lines(2).AX = 40
'lines(2).AY = -80
lines(2).BX = 40
'lines(2).BY = -150

gridLines.Lines = lines



Dim sds As New SampleDataSeries(m_Chart.ViewXY, axisX, m_Chart.ViewXY.YAxes(0))
sds.LineStyle.Width = 3
sds.LineStyle.Color = Color.Red
Dim samples As Double() = New Double(49) {}
Dim rand As New Random()
For i As Integer = 0 To 49
samples(i) = -150 + 70.0 * rand.NextDouble()
Next
sds.SamplingFrequency = 1
sds.FirstSampleTimeStamp = 1.0 / sds.SamplingFrequency
sds.SamplesDouble = samples
m_Chart.ViewXY.SampleDataSeries.Add(sds)

m_Chart.ViewXY.LineCollections.Add(gridLines)
m_Chart.ViewXY.YAxes(0).SetRange(-200, 50)

End Sub

Private Sub YAxis_RangeChanged(newMin As Double, newMax As Double, axis As Arction.LightningChartUltimate.Axes.AxisBase, ByRef cancelRendering As Boolean)


For i As Integer = 0 To 2 Step 1
m_Chart.ViewXY.LineCollections(0).Lines(i).AY = m_Chart.ViewXY.YAxes(0).Maximum
m_Chart.ViewXY.LineCollections(0).Lines(i).BY = m_Chart.ViewXY.YAxes(0).Minimum
Next

End Sub


End Class

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:26 pm
by ArctionPasi
Sorry I read you message too fast. You are right, the LineCollections don't render over SampleDataSeries. It renders over specific series types but not SampleDataSeries, FreeformPointLineSeries, and PointLineSeries at least. We'll check what we can do to change the rendering order.

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:36 pm
by ArctionPasi
We'll change the rendering order in 6.2 version next week, so when LineCollection.Behind = false, it will render after the SampleDataSeries.

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:37 pm
by fredd41
ok because that would be really useful to show grid lines above the sampledataseries

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:38 pm
by fredd41
ok perfect thanks

did you tried my code ?

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 3:47 pm
by ArctionPasi
fredd41 wrote:now try this code

run the project and move the y-axis up and down
the lines will disappear if min and max > 0 or min and max < 0

thanks

Imports Arction.LightningChartUltimate.SeriesXY
Imports Arction.LightningChartUltimate
Imports Arction.LightningChartUltimate.Axes

Public Class Form2

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load


Dim axisX As AxisX = m_Chart.ViewXY.XAxes(0)
axisX.SetRange(0, 50)
axisX.ScrollMode = XAxisScrollMode.None
axisX.ValueType = AxisValueType.Number


AddHandler m_Chart.ViewXY.YAxes(0).RangeChanged, AddressOf YAxis_RangeChanged

Dim gridLines As New LineCollection(m_Chart.ViewXY, axisX, m_Chart.ViewXY.YAxes(0))
Dim lines As SegmentLine() = New SegmentLine(2) {}
gridLines.LineStyle.Color = Color.White
gridLines.LineStyle.Pattern = LinePattern.Dash
gridLines.LineStyle.Width = 5
gridLines.Behind = False

lines(0).AX = 10
'lines(0).AY = -80
lines(0).BX = 10
'lines(0).BY = -150

lines(1).AX = 20
'lines(1).AY = -80
lines(1).BX = 20
'lines(1).BY = -150

lines(2).AX = 40
'lines(2).AY = -80
lines(2).BX = 40
'lines(2).BY = -150

gridLines.Lines = lines



Dim sds As New SampleDataSeries(m_Chart.ViewXY, axisX, m_Chart.ViewXY.YAxes(0))
sds.LineStyle.Width = 3
sds.LineStyle.Color = Color.Red
Dim samples As Double() = New Double(49) {}
Dim rand As New Random()
For i As Integer = 0 To 49
samples(i) = -150 + 70.0 * rand.NextDouble()
Next
sds.SamplingFrequency = 1
sds.FirstSampleTimeStamp = 1.0 / sds.SamplingFrequency
sds.SamplesDouble = samples
m_Chart.ViewXY.SampleDataSeries.Add(sds)

m_Chart.ViewXY.LineCollections.Add(gridLines)
m_Chart.ViewXY.YAxes(0).SetRange(-200, 50)

End Sub

Private Sub YAxis_RangeChanged(newMin As Double, newMax As Double, axis As Arction.LightningChartUltimate.Axes.AxisBase, ByRef cancelRendering As Boolean)


For i As Integer = 0 To 2 Step 1
m_Chart.ViewXY.LineCollections(0).Lines(i).AY = m_Chart.ViewXY.YAxes(0).Maximum
m_Chart.ViewXY.LineCollections(0).Lines(i).BY = m_Chart.ViewXY.YAxes(0).Minimum
Next

End Sub


End Class

You need to call InvalidateData for the line collection. It's a struct type, and chart can't know the line segment field has been changed. InvalidateData tells the chart that.

Code: Select all

void ExamplePointLineSeriesXY_RangeChanged(double newMin, double newMax, AxisBase axis, ref bool cancelRendering)
        {
            m_chart.BeginUpdate(); 
            for(int i=0;i<3; i++)
            {
                m_chart.ViewXY.LineCollections[0].Lines[i].AY = m_chart.ViewXY.YAxes[0].Maximum;
                m_chart.ViewXY.LineCollections[0].Lines[i].BY = m_chart.ViewXY.YAxes[0].Minimum;
                m_chart.ViewXY.LineCollections[0].InvalidateData();
            }
            m_chart.EndUpdate(); 
        }
Then it won't disappear.

Re: Individual major/minor line style

Posted: Fri Sep 26, 2014 4:54 pm
by fredd41
thanks

Re: Individual major/minor line style

Posted: Tue Nov 17, 2015 10:28 pm
by cwodarczyk82
For anyone interested, or still reading this post, this workaround also works great for custom ticks, when you need to specify a different div count rather than 1 for each tick location....