Dynamic multiple charts

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
dave
Newbie
Newbie
Posts: 35
Joined: Fri Feb 24, 2006 12:00 am

Dynamic multiple charts

Post by dave » Fri Jul 27, 2007 12:28 am

Hi,

Currently, if I don't use RemoveAllSeries and Tool.Clear, each time I run a series chart, the new series will be added to the same chart as the previous series, with a common vertical & horizontal axis.

Is it possible, if on each run, the new series will appear with its own vertical & horizontal axis? So, if I were to run the series chart 3 times, I would end up with 3 separate series with their own horizontal & vertical axis? The later charts will appear on top of the older ones.

Thanks.

dave
Newbie
Newbie
Posts: 35
Joined: Fri Feb 24, 2006 12:00 am

Post by dave » Fri Jul 27, 2007 6:43 am

After trying for a while, I roughly got what I wanted but with a few problems. This is my code:

[/img]

Code: Select all


            tChart1.Aspect.View3D = false;
            tChart1.Series.RemoveAllSeries();
            tChart1.Tools.Clear();
            tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
            tChart1.Legend.CheckBoxes = true;

            int lineSeries = 0;

            //Initialise line names
            List<Steema.TeeChart.Styles.Line> lineStorage = new List<Steema.TeeChart.Styles.Line>();
            List<Steema.TeeChart.Styles.Line> linePercent = new List<Steema.TeeChart.Styles.Line>();
            List<Steema.TeeChart.Axis> lAxis = new List<Steema.TeeChart.Axis>();
            List<Steema.TeeChart.Axis> rAxis = new List<Steema.TeeChart.Axis>();
            List<Steema.TeeChart.Axis> hAxis = new List<Steema.TeeChart.Axis>();
            
            PhysicalData dh = new PhysicalData();   //initialise class

            foreach (DataList d in dData) //data stored in a <List> class
            {
                if (d.endDate > d.startDate)
                {
                    lineStorage.Add(new Steema.TeeChart.Styles.Line(tChart1.Chart));
                    linePercent.Add(new Steema.TeeChart.Styles.Line(tChart1.Chart));

                    lAxis.Add(new Steema.TeeChart.Axis(tChart1.Chart)); //left axis
                    rAxis.Add(new Steema.TeeChart.Axis(tChart1.Chart)); //right axis
                    hAxis.Add(new Steema.TeeChart.Axis(tChart1.Chart)); //horizontal axis

//assigns horizontal & vertical axis to the series
                    lineStorage[lineSeries].CustomVertAxis = lAxis[lineSeries];
                    linePercent[lineSeries].CustomVertAxis = rAxis[lineSeries];
                    lineStorage[lineSeries].CustomHorizAxis = hAxis[lineSeries];
                    linePercent[lineSeries].CustomHorizAxis = hAxis[lineSeries];                    

                    DataTable dt = dh.DataValues(d.startDate, d.endDate, d.name);
                    foreach (DataRow dr in dt.Rows) //insert data into series
                    {
                        lineStorage[lineSeries].Add(Convert.ToDateTime(dr["calendardate"].ToString()), Single.Parse(dr["value"].ToString()));
                        linePercent[lineSeries].Add(Convert.ToDateTime(dr["calendardate"].ToString()), Single.Parse(dr["percentage"].ToString()));
                    }

                    lineSeries++;
                }               
            }

//calculate start & end position for the axis
            for (int i = 0; i < lineSeries; i++)
            {
                lAxis[i].Horizontal = false;
                lAxis[i].OtherSide = false;                
                lAxis[i].StartPosition = i * 100 / lineSeries;
                lAxis[i].EndPosition = (i+1) * 100 / lineSeries;

                rAxis[i].Horizontal = false;
                rAxis[i].OtherSide = true;                
                rAxis[i].StartPosition = i * 100 / lineSeries;
                rAxis[i].EndPosition = (i + 1) * 100 / lineSeries;
                rAxis[i].Title.Text = "%";

                hAxis[i].Horizontal = true;
                hAxis[i].OtherSide = false;
                hAxis[i].RelativePosition = i * 100 / lineSeries;

                tChart1.Axes.Custom.Add(lAxis[i]);
                tChart1.Axes.Custom.Add(rAxis[i]);
                tChart1.Axes.Custom.Add(hAxis[i]);
            }
The issues I have, however, are:
1) The left & right axis values & titles are 'chopped off'.
2) How could I create a gap between each chart, so that there's no continuity on the vertical axis (also to prevent overlap of labels)? I've tried subtracting 2 from the endposition for the vertical axis, but it didn't seem to work as I thought it should.
3) When I call the following code:

Code: Select all

            tChart1.Series.RemoveAllSeries();
            tChart1.Tools.Clear();
the series is no longer appearing, but the horizontal axis line remains in the middle of the chart (if I plotted more than 1 chart previously). How could I clear that?

I could attach a sample of the chart gif file, but not sure how I could do it here without hosting it with some hyperlink/url.

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Jul 30, 2007 1:07 pm

Hi dave,
The issues I have, however, are:
1) The left & right axis values & titles are 'chopped off'.
It's most likely that you need to set your chart margins as when using custom axes they are not set automatically:

Code: Select all

			tChart1.Panel.MarginLeft = 5;
			tChart1.Panel.MarginRight = 5;
2) How could I create a gap between each chart, so that there's no continuity on the vertical axis (also to prevent overlap of labels)? I've tried subtracting 2 from the endposition for the vertical axis, but it didn't seem to work as I thought it should.
You could try playing with one axis EndPosition and next's StartPosition. If this doesn't help please send us a simple example project we can run "as-is" to reproduce the problem here.
3) When I call the following code:

Code:
tChart1.Series.RemoveAllSeries();
tChart1.Tools.Clear();

the series is no longer appearing, but the horizontal axis line remains in the middle of the chart (if I plotted more than 1 chart previously). How could I clear that?
You could try removing axes as well.
I could attach a sample of the chart gif file, but not sure how I could do it here without hosting it with some hyperlink/url.
Yes, that's right. You can also post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply