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
Custom Ticks on Axis X
Moderator: Queue Moderators
Re: Custom Ticks on Axis X
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.
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.
Re: Custom Ticks on Axis X
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
The code I wrote is this:
What's wrong?
Thank
Gian
The function required many resource and time consuming and the result is the attached image
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
Thank
Gian
Last edited by TheGian on Fri Dec 13, 2013 7:14 am, edited 1 time in total.
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Custom Ticks on Axis X
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.
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
Re: Custom Ticks on Axis X
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
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
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Custom Ticks on Axis X
Yes. You'll need to recalculate the custom ticks.- now if I zoom o scroll may graph I need to recalculate the custom ticks, isn't it?
You can use axis.RangeChanged event handler for that.- what is the zoom event? is beforerendering?
RangeChanged event handler tells the axis Minimum and Maximum, that you can use for calculating custom ticks between these.- can I know the first and the last real point displayed to calculate the ticks?
LightningChart Support Team, PT