Custom Ticks on Axis X

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Queue Moderators

Post Reply
TheGian
Posts: 11
Joined: Thu Sep 19, 2013 7:52 am

Custom Ticks on Axis X

Post by TheGian » Tue Dec 10, 2013 3:12 pm

Hi, I have made a function which graphs many data to multiple PointLineSeries from a Datatable (every column on a PointLineSeries).
The first Two columns are: the first a sequential index, and the second a datatime which may be not sequential.

my question is: Can I apply the second column of my datatable as a customtick label of the axis X (that is the first column)?

is there a fast way to make this and which make an autospacing of the labels?

Thanks
Gian

ArctionJari

Re: Custom Ticks on Axis X

Post by ArctionJari » Thu Dec 12, 2013 9:42 am

You can use custom axis ticks for this. Just enable AxisX.CustomTicksEnabled and disable AxisX.AutoFormatLabels. Than add the same number of custom ticks to AxisX.CustomTicks list that you have data points in your table. Set each custom tick's AxisValue (index) and LabelText (datetime) accordingly.

One thing to remember that if you have a real-time solution (i.e. a scrolling chart) and you have set ViewXY.DropOldSeriesData to true, then you have to maintain the custom tick list manually. I.e. remove old ticks from the list when old data gets dropped. Otherwise the list contains not needed ticks and they consume memory. Naturally it depends on the situation and do you want to keep the old ticks even though old data is not there anymore but in general speaking.

I hope this is what you were looking for. :)

TheGian
Posts: 11
Joined: Thu Sep 19, 2013 7:52 am

Re: Custom Ticks on Axis X

Post by TheGian » Thu Dec 12, 2013 1:10 pm

I've already try, but I think I'm getting something wrong.
The function required many resource and time consuming and the result is the attached image
chart_custom ticks.png
chart_custom ticks.png (246.42 KiB) Viewed 21385 times
The code I wrote is this:

Code: Select all

               #region X-axis
                    AxisX axisX = m_chart.ViewXY.XAxes[0];

                    axisX.ValueType = AxisValueType.Number;
                    axisX.LabelsAngle = 90;               
                    axisX.LabelsColor = Color.LightGray;

                    axisX.CustomTicksEnabled = true;
                    axisX.AutoFormatLabels = false;
                    axisX.LabelsFont = new Font(FontFamily.GenericSansSerif, 8f);
                    foreach (DataRow dr in DT.Rows)
                    {
                        DateTime data = (DateTime)dr[ER_DateTime];
                        double Xval = (int)dr[GlobalVar.RDVTINDEX];
                        axisX.CustomTicks.Add(new CustomAxisTick(axisX, Xval, data.ToString("MM-dd-yyyy\r\nHH:mm:ss.fff")));
                    }
                    axisX.AutoDivSpacing = true;
                    axisX.MinorGrid.Visible = false;
                    axisX.InvalidateCustomTicks();

                    axisX.Title.Visible = true;
                    axisX.Title.Text = ER_DateTime;
                    axisX.Title.Color = Color.Orange;
                    axisX.Title.DistanceToAxis = 100;
                    double origin = int.Parse(DT.Rows[0][GlobalVar.RDVTINDEX].ToString());
                    double finish = int.Parse(DT.Rows[DT.Rows.Count - 1][GlobalVar.RDVTINDEX].ToString());
                
                    axisX.SetRange(origin, finish);
                #endregion
What's wrong?

Thank
Gian
Last edited by TheGian on Fri Dec 13, 2013 7:14 am, edited 1 time in total.

TheGian
Posts: 11
Joined: Thu Sep 19, 2013 7:52 am

Re: Custom Ticks on Axis X

Post by TheGian » Mon Dec 23, 2013 9:19 am

:cry: :cry: Any Idea? :cry: :cry:

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

Re: Custom Ticks on Axis X

Post by ArctionPasi » Fri Dec 27, 2013 4:15 pm

Hi Gian,

you shouldn't add a CustomTick for each data row. Now there's millions of ticks and grid lines and they are rendered glued together.

Maybe you could add a tick for every Nth data row instead. For example, calculate graph width as:
int graphWidth = chart.ClientSize.Width - chart.Margins.Left - chart.Margins.Right;

Reserve at least 30 pixels for each tick with label.

int tickCount = graphWidth / 30;

int N = DTRows.Length / tickCount;

int i = 0;
foreach (DataRow dr in DT.Rows)
{

DateTime data = (DateTime)dr[ER_DateTime];

double Xval = (int)dr[GlobalVar.RDVTINDEX];
if(i % N == 0)
{
axisX.CustomTicks.Add(new CustomAxisTick(axisX, Xval, data.ToString("MM-dd-yyyy\r\nHH:mm:ss.fff")));
}
i++;

}

Something like that.

When using CustomTicks, you are responsible for adding only the ticks that should appear in the chart.
;)
LightningChart Support Team, PT

TheGian
Posts: 11
Joined: Thu Sep 19, 2013 7:52 am

Re: Custom Ticks on Axis X

Post by TheGian » Sun Jan 05, 2014 5:00 pm

:D :D :D This is exactly what I was looking for, thank you very much

I've some other questions about the custom ticks:
- now if I zoom o scroll may graph I need to recalculate the custom ticks, isn't it?
- what is the zoom event? is beforerendering?
- can I know the first and the last real point displayed to calculate the ticks?

thank you very much

Gian

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

Re: Custom Ticks on Axis X

Post by ArctionPasi » Mon Jan 06, 2014 1:34 pm

- now if I zoom o scroll may graph I need to recalculate the custom ticks, isn't it?
Yes. You'll need to recalculate the custom ticks.
- what is the zoom event? is beforerendering?
You can use axis.RangeChanged event handler for that.
- can I know the first and the last real point displayed to calculate the ticks?
RangeChanged event handler tells the axis Minimum and Maximum, that you can use for calculating custom ticks between these.
LightningChart Support Team, PT

Post Reply