Hello,
If allowed (MoveByMouse set to true) the title, axis labels and legendbox call all be moved around the chart by the user. How do I get the locations so that I can restore the positions the next time the plot is shown? The Offset X and Y do not seem to get updated when any of these are moved by the user.
Thanks
Greg.
Title, Axis, LegendBox - saving locations?
Moderator: Queue Moderators
-
- Posts: 42
- Joined: Thu Mar 28, 2013 9:20 am
Re: Title, Axis, LegendBox - saving locations?
Hi Greg,
You can restore LegendBoxXY and ChartTitle location by using kind of code that follows. Idea is to update Offset values according to rendered coordinates.
For WinForms, control is drawn first time on some unapplicable location, for which there is the flag to skip the first render.
Unfortunately positioning axis titles is not possible using code like above.
You can restore LegendBoxXY and ChartTitle location by using kind of code that follows. Idea is to update Offset values according to rendered coordinates.
For WinForms, control is drawn first time on some unapplicable location, for which there is the flag to skip the first render.
Code: Select all
//At chart initialize
m_chart.BeforeRendering += new LightningChartUltimate.BeforeRenderingHandler(m_chart_BeforeRendering);
m_chart.AfterRendering += new LightningChartUltimate.AfterRenderingHandler(m_chart_AfterRendering);
//At component root
bool m_bFirstRendering = true;
String m_strLBFileLoc = @"C:\lbpos.txt";
String m_strTitleFileLoc = @"C:\titlepos.txt";
void m_chart_AfterRendering(LightningChartUltimate chart)
{
if (m_bFirstRendering)
{
m_bFirstRendering = false;
return;
}
//Store lb coordinates
Rectangle drawRect = chart.ViewXY.LegendBox.GetRenderedRect();
if (File.Exists(m_strLBFileLoc))
File.Delete(m_strLBFileLoc);
using (StreamWriter file = File.CreateText(m_strLBFileLoc))
{
file.WriteLine("{0},{1}", drawRect.X, drawRect.Y);
}
//Store title coordinates
drawRect = chart.Title.DrawRectangle;
if (File.Exists(m_strTitleFileLoc))
File.Delete(m_strTitleFileLoc);
using (StreamWriter file = File.CreateText(m_strTitleFileLoc))
{
file.WriteLine("{0},{1}", drawRect.X, drawRect.Y);
}
}
void m_chart_BeforeRendering(LightningChartUltimate chart, int width, int height)
{
if (m_bFirstRendering)
{
return;
}
Rectangle drawRect = new Rectangle();
//Disable rendering
chart.BeginUpdate();
//LegendBox
if (File.Exists(m_strLBFileLoc))
{
using (StreamReader file = File.OpenText(m_strLBFileLoc))
{
char[] aSeparator = new char[] {','};
String[] aLines = file.ReadLine().Split(aSeparator);
drawRect.X = int.Parse(aLines[0]);
drawRect.Y = int.Parse(aLines[1]);
}
chart.ViewXY.LegendBox.Position = LegendBoxPosition.TopLeft;
chart.ViewXY.LegendBox.Offset.X = drawRect.X - chart.Margin.Left + 2;
chart.ViewXY.LegendBox.Offset.Y = drawRect.Y - chart.Margin.Top + 2;
}
//Chart title
if (File.Exists(m_strTitleFileLoc))
{
using (StreamReader file = File.OpenText(m_strTitleFileLoc))
{
char[] aSeparator = new char[] { ',' };
String[] aLines = file.ReadLine().Split(aSeparator);
drawRect.X = int.Parse(aLines[0]);
drawRect.Y = int.Parse(aLines[1]);
}
chart.Title.Align = ChartTitleAlignment.TopLeft;
chart.Title.Offset.X = drawRect.X;
chart.Title.Offset.Y = drawRect.Y;
}
//Allow rendering
chart.EndUpdate();
}
LightningChart Support Team, TK