Hello Amol,
Amol wrote:The code you provided is working fine except following:
By seeing it we can observe that the slope of the line it slightly changing as soon as we start moving it, from the position it was initially drawn. Means the slope of line at very first time is different from when we first start movement

.
Here we need same slope (45°) of line during initial state and while movement too.
Please help me to finalize this task.
That's what I meant when I said:
Yeray wrote:The only thing I'm not sure why it isn't working as I'd expect is how the line looks the first time it is drawn. Maybe you can find what I'm missing.
But it seems to work as I'd expect when you drag it, isn't it?
I'm not sure about the reason why the values aren't correct the first time the chart is drawn but Narcís made me note that moving the slope initialization to the form Shown event, it seems to work as expected:
Code: Select all
private void CreateChart()
{
//...
//List<double> XDATA = new List<double>();
//List<double> YDATA = new List<double>();
//CreateDataForHalfSlopeLine(80, 30, ref XDATA, ref YDATA);
//m_lnHalfSlope.Add(XDATA.ToArray(), YDATA.ToArray());
//...
this.Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
List<double> XDATA = new List<double>();
List<double> YDATA = new List<double>();
CreateDataForHalfSlopeLine(80, 30, ref XDATA, ref YDATA);
m_lnHalfSlope.Add(XDATA.ToArray(), YDATA.ToArray());
}
Another tip you may be interested in. Note that there is a ClickedPointer function for the Line series as well. So, if you want the slope to be dragged only through the pointer, you can use it:
Code: Select all
private void tChart1_MouseDown(object sender, MouseEventArgs e)
{
//...
//indexOfHalfSlopeLine = m_lnHalfSlope.Clicked(e.X, e.Y);
indexOfHalfSlopeLine = m_lnHalfSlope.ClickedPointer(e.X, e.Y);
//...
}