Page 1 of 1
Using subchart
Posted: Thu Sep 09, 2010 12:36 pm
by 15654246
Hi,
I want to use Teechart's SubChart's tool for achiving the below user interface.
Let me know if it is possible.
Query 1: Can a TeeChart tool bound to a SubChart tool. That means, i want to use Annotation tool inside a Subchart so that the annotation tool moves along with the subchart when the subchart is moved.
Please see the image below -
- expected UI layout using SubChart
- SubChartUsage.JPG (145.46 KiB) Viewed 4924 times
Regards,
Avijit
Re: Using subchart
Posted: Fri Sep 10, 2010 2:52 pm
by yeray
Hi Avijit,
Here you have an example to start with. Press control and drag the chart in the right.
Code: Select all
public Form1()
{
InitializeComponent();
CreateChart();
CreateSubChart();
InitializeChart();
InitializeSubChart();
}
private Steema.TeeChart.TChart tChart1; //Chart1
private Steema.TeeChart.TChart tChart2; //SubChart - Chart2
private Steema.TeeChart.ChartController chartController1;
private int MouseDownX, MouseDownY = -1;
private void CreateChart()
{
tChart1 = new Steema.TeeChart.TChart();
this.Controls.Add(tChart1);
chartController1 = new Steema.TeeChart.ChartController();
this.Controls.Add(chartController1);
chartController1.Chart = tChart1;
tChart1.Dock = DockStyle.Fill;
tChart1.Chart.CustomChartRect = true;
tChart1.Chart.ChartRect = new Rectangle(10, 10, 210, 210);
tChart1.Panel.Gradient.Visible = false;
}
private void CreateSubChart()
{
Steema.TeeChart.Tools.SubChartTool subchart1 = new Steema.TeeChart.Tools.SubChartTool(tChart1.Chart);
tChart2 = subchart1.Charts.AddChart("SubChart");
tChart2.Panel.Gradient.Visible = false;
Rectangle tmpRect = tChart1.Chart.ChartRect;
tChart2.Width = tmpRect.Width;
tChart2.Height = tmpRect.Height + 8;
tChart2.Left = tmpRect.Left + tmpRect.Width + 10;
tChart2.Top = 2;
tChart2.Chart.ChartRect = new Rectangle(10, 10, 210, 210);
tChart2.Zoom.Allow = false;
tChart2.MouseDown += new MouseEventHandler(tChart2_MouseDown);
tChart2.MouseMove += new MouseEventHandler(tChart2_MouseMove);
tChart2.MouseUp += new MouseEventHandler(tChart2_MouseUp);
}
void tChart2_MouseUp(object sender, MouseEventArgs e)
{
MouseDownX = -1;
MouseDownY = -1;
}
void tChart2_MouseMove(object sender, MouseEventArgs e)
{
if ((MouseDownX != -1) && (MouseDownY != -1))
{
tChart2.Left = tChart2.Left - (MouseDownX - e.X);
tChart2.Top = tChart2.Top - (MouseDownY - e.Y);
MouseDownX = e.X;
MouseDownY = e.Y;
Steema.TeeChart.Tools.Annotation annot1 = tChart2.Tools[0] as Steema.TeeChart.Tools.Annotation;
annot1.Shape.Left = tChart2.Left + 20;
annot1.Shape.Top = tChart2.Top + 50;
tChart2.Refresh();
}
}
void tChart2_MouseDown(object sender, MouseEventArgs e)
{
if ((Control.ModifierKeys & Keys.Control) == Keys.Control )
{
MouseDownX = e.X;
MouseDownY = e.Y;
}
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
tChart1[0].FillSampleValues(5);
}
private void InitializeSubChart()
{
tChart2.Aspect.View3D = false;
new Steema.TeeChart.Styles.FastLine(tChart2.Chart);
tChart2[0].FillSampleValues(5);
Steema.TeeChart.Tools.Annotation annot1 = new Steema.TeeChart.Tools.Annotation(tChart2.Chart);
annot1.Text = "My annotation";
annot1.Shape.CustomPosition = true;
annot1.Shape.Left = tChart2.Left + 20;
annot1.Shape.Top = tChart2.Top + 50;
tChart2.Refresh();
}