Page 1 of 1
Problem panning 2D chart
Posted: Thu Jun 14, 2007 4:54 am
by 9645016
I have a 2D line chart in my application. The only tool I have added is the "marks tip" tool. Piror to upgrading to .Net V3, i dind't have any problems with panning using the right mouse button. But after the upgrade, when I right mouse click and start to pan, the chart immediately "jumps" in to 3D mode, becomes smaller, and instead of simply scrolling the series, it also moves the entire chart (including the axes. walls, etc) around on the canvas. Any idea what's going on?
Posted: Thu Jun 14, 2007 5:50 am
by 9645016
Here's another clue: I'm using a TeeChartCommand and I only get this weird behavior when the commander is attached to the chart. When I comment out the line in my code that assigns a value to the TeeChartCommander.Chart property, the right-mouse panning works as expected. You can duplicate this problem in the "Components\Commander\Custom Buttons" demo application that's delivered with TeeChart. Just use the commander button to open the chart editor, uncheck 3D -> 3 Dimensions, then right-mouse pan. Chart will pop back into 3D mode and move the entire chart, not just the series.
Posted: Thu Jun 14, 2007 6:53 am
by 9645016
OK, this just seems to be the way the commander works... I disassembled the DoMove() method in the commander and found this:
private void DoMove(int X, int Y)
{
this.Set3D();
this.Panel.Aspect.HorizOffset += X - this.oldX;
this.Panel.Aspect.VertOffset += Y - this.oldY;
this.oldX = X;
this.oldY = Y;
}
So it intentionally sets 3D mode as soon as the pan begins. Why?
Seems no way to get around this now, so I'll just make my own toolbar.
Posted: Thu Jun 14, 2007 10:23 am
by narcis
Hi chousand,
Thank you for making us aware of this issue. I have logged it on our tracking software to be studied for a future release.
In the meantime you may be interested in implementing your own commander as shown here:
Code: Select all
private Boolean RotateChart, MoveChart, ZoomChart, DChart, Go;
private int StartX, StartY;
private void Form1_Load(object sender, EventArgs e)
{
//tChart1[0].FillSampleValues();
Steema.TeeChart.Styles.Pie pie2 = new Steema.TeeChart.Styles.Pie(tChart1.Chart);
pie2.FillSampleValues();
button1.Text = "Reset";
button2.Text = "Rotate";
button3.Text = "Move";
button4.Text = "Zoom";
button5.Text = "3D%";
button6.Text = "Editor";
}
private void button1_Click(object sender, EventArgs e)
{
SetDefaultAspect(tChart1);
tChart1.Zoom.Allow = true;
tChart1.Panning.Allow = Steema.TeeChart.ScrollModes.Both;
RotateChart = false;
MoveChart = false;
ZoomChart = false;
Go = false;
}
private void SetDefaultAspect(Steema.TeeChart.TChart c)
{
c.Aspect.Orthogonal = true;
c.Aspect.HorizOffset = 0;
c.Aspect.VertOffset = 0;
c.Aspect.Zoom = 100;
c.Aspect.Chart3DPercent = 15;
}
private void button2_Click(object sender, EventArgs e)
{
RotateChart = true;
MoveChart = false;
ZoomChart = false;
DChart = false;
DisableZoomScroll(tChart1);
}
private void button3_Click(object sender, EventArgs e)
{
RotateChart = false;
MoveChart = true;
ZoomChart = false;
DChart = false;
DisableZoomScroll(tChart1);
}
private void button4_Click(object sender, EventArgs e)
{
RotateChart = false;
MoveChart = false;
ZoomChart = true;
DChart = false;
DisableZoomScroll(tChart1);
}
private void button5_Click(object sender, EventArgs e)
{
//Changing Chart3DPercent
RotateChart = false;
MoveChart = false;
ZoomChart = false;
DChart = true;
DisableZoomScroll(tChart1);
//Standard functionality
//tChart1.Aspect.View3D = !tChart1.Aspect.View3D;
}
private void button6_Click(object sender, EventArgs e)
{
tChart1.ShowEditor();
}
private void DisableZoomScroll(Steema.TeeChart.TChart c)
{
c.Zoom.Allow = false;
c.Panning.Allow = Steema.TeeChart.ScrollModes.None;
}
private void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (RotateChart || MoveChart || ZoomChart || DChart)
{
Go = true;
StartX = e.X;
StartY = e.Y;
}
}
private void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (Go)
{
if (RotateChart) Rotate(tChart1, e);
if (MoveChart) PanChart(tChart1, e);
if (ZoomChart) Zoom(tChart1, e);
if (DChart) Set3DPercent(tChart1, e);
}
}
private void Set3DPercent(Steema.TeeChart.TChart c, MouseEventArgs e)
{
c.Aspect.Chart3DPercent += e.X - StartX;
if (c.Aspect.Chart3DPercent < 0)
c.Aspect.Chart3DPercent = 0;
if (c.Aspect.Chart3DPercent > 100)
c.Aspect.Chart3DPercent = 100;
}
private void Zoom(Steema.TeeChart.TChart c, MouseEventArgs e)
{
if (c.Aspect.Zoom +(e.X - StartX)>0)
c.Aspect.Zoom += e.X - StartX;
StartX = e.X;
StartY = e.Y;
}
private void PanChart(Steema.TeeChart.TChart c, MouseEventArgs e)
{
c.Aspect.HorizOffset += e.X - StartX;
c.Aspect.VertOffset += e.Y - StartY;
StartX = e.X;
StartY = e.Y;
}
private void Set3D()
{
tChart1.Aspect.View3D = true;
//if (bView3D != null) bView3D.Pushed = true;
}
private int CorrectAngle(int aAngle)
{
int tmpResult = aAngle;
if (tmpResult > 360) tmpResult = tmpResult - 360;
else if (tmpResult < 0) tmpResult = 360 + tmpResult;
return tmpResult;
}
private int CalcAngleChange(int aAngle, int aChange)
{
int tmpMinAngle;
if (aChange > 0) return Math.Min(360, aAngle + aChange);
else
{
if (tChart1.Graphics3D.SupportsFullRotation) tmpMinAngle = 0;
else tmpMinAngle = 270;
return Math.Max(tmpMinAngle, aAngle + aChange);
}
}
static internal Steema.TeeChart.Styles.Pie FirstSeriesPie(Steema.TeeChart.Chart c)
{
foreach (Steema.TeeChart.Styles.Series s in c.Series)
if ((s.GetType() == typeof(Steema.TeeChart.Styles.Pie)) && (s.Active))
return (Steema.TeeChart.Styles.Pie)s;
return null;
}
private void DoRotate(int X, int Y)
{
Set3D();
tChart1.Aspect.Orthogonal = false;
int tmpX = Steema.TeeChart.Utils.Round(90.0 * (X - StartX) / tChart1.Width);
int tmpY = Steema.TeeChart.Utils.Round(90.0 * (StartY - Y) / tChart1.Height);
Steema.TeeChart.Styles.Pie tmpSeries = FirstSeriesPie(tChart1.Chart);
if (tChart1.Graphics3D.SupportsFullRotation)
{
tChart1.Aspect.Rotation = CorrectAngle(tChart1.Aspect.Rotation + tmpX);
tChart1.Aspect.Elevation = CorrectAngle(tChart1.Aspect.Elevation + tmpY);
}
else
{
if (tmpSeries != null)
{
tChart1.Aspect.Rotation = 360;
if (!tChart1.Graphics3D.SupportsFullRotation) tChart1.Aspect.Perspective = 0;
if (tmpX != 0)
tmpSeries.RotationAngle = CorrectAngle(tmpSeries.RotationAngle + tmpX);
}
else tChart1.Aspect.Rotation = CalcAngleChange(tChart1.Aspect.Rotation, tmpX);
tChart1.Aspect.Elevation = CalcAngleChange(tChart1.Aspect.Elevation, tmpY);
}
StartX = X;
StartY = Y;
}
private void Rotate(Steema.TeeChart.TChart c, MouseEventArgs e)
{
DoRotate(e.X, e.Y);
//c.Aspect.Orthogonal = false;
//c.Aspect.Elevation += StartY - e.Y;
//c.Aspect.Rotation += e.X - StartX;
//StartX = e.X;
//StartY = e.Y;
}
private void tChart1_MouseUp(object sender, MouseEventArgs e)
{
if (RotateChart) Rotate(tChart1, e);
if (MoveChart) PanChart(tChart1, e);
if (ZoomChart) Zoom(tChart1, e);
if (DChart) Set3DPercent(tChart1, e);
Go = false;
}
Posted: Thu Jun 14, 2007 1:38 pm
by 9645016
Thanks for the suggestion. That's more or less what I ended up doing using disassembled pieces of the Commander as guidance. Only took a few minutes to implement the 4 buttons I needed and it seems to work just fine.