Page 1 of 1

Visualize selected label/Marks in chart

Posted: Thu Sep 03, 2009 8:55 pm
by 8748279
Hi - Here is the problem. I have a multi series points chart in which the user can select certain datapoints which are then put into an arraylist. After the user has completed his selections, i want him to be able to push a button to update chart to ONLY see the label/marks/dragmarks for the items in the arraylist. He should have the ability to move the marks around to position them as needed (dragmarks?). I have been thru the tutorials and forums but can't find anything that lets me do as i describe above. Other thoughts include actually drawing the text values on the chart via the after/before draw events. Seems a little clunky if that is the way to do this.

Thanks for any help
Rick

Re: Visualize selected label/Marks in chart

Posted: Fri Sep 04, 2009 7:27 am
by narcis
Hi Rick,

For selecting points in a chart I suggest you to do as discussed on this thread.

About only displaying some marks, the easiest way I can think of is either setting empty string labels to the points so the marks are not displayed or set marks in non-selected points to an empty string in GetSeriesMark event.

Finally, for moving the marks the easiest option is using DragMarks tool.

Hope this helps!

Re: Visualize selected label/Marks in chart

Posted: Fri Sep 04, 2009 11:15 pm
by 8748279
Narcis - Thanks for the quick response... however.. after a long day of this i am convinced they may be a bug involving the Marks.Items[n] collection. See the notes in the code box.
I am using version 2.0.2009.21355:RunTime Version : v2.0.50727. I can make this work if the data is "ALWAYS" inserted sorted acsending. If by design the OK.. just would have liked to have found that little tibit somewhere...
anyway.. any comments would be appreaciated.

Thanks
Rick

Code: Select all

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        
        
        ArrayList al = new ArrayList();
        public Form1()
        {
            //I didn't use FillValues() to load the points.  The purpose of the chart is to take a user selected
            //arraylist of datapoints and find its corresponding data point in the points collection (this could be multiple point series too).
            //If found then update that series datapoints marks.text property and set the marks.tag property to 'X' so i can 
            //iterate over the collection again and set the marks.text property to an empty string in the 
            //marks.items collection where the tag property is not ="X";
            //I get a sense that the data must be loaded sorted by X acsending for the marks.items[n] to 
            //work correctly.  Is that by design?  My data typically comes from a database.  I can always make
            //sure it is sorted as such but it seems to be a limitation of the collection.
                      
            
            InitializeComponent();
            //this one works closest to what i want
            //however if i rearrange the data points
            //,the datapoint that is out of order doesn't show up with a Mark on the chart 
            //IF the datapoints are in perfect order then they all show up.
            //The code to show only selected marks works fine in either case as long as the one
            //that doesn't have a mark is not in the match list.
            //InitializeChart();

            //uncomment below to see the effects of a different loading strategy. i.e. no marks show up on 
            //the chart and the code to show selected marks doesn't work.

            InitializeChart1();

        }
        void InitializeChart()
        {
            //to maintain the bottom axis label style
            tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
            //just in case... :)
            tChart1.Series[0].Marks.Items.Clear();
            
            //load the data
            int iPoint = this.tChart1.Series[0].Add(1.0, 3.33);
            tChart1.Series[0].Marks.Items[iPoint].Text = "A";
                    
            iPoint = this.tChart1.Series[0].Add(2.0, 4.44);
            tChart1.Series[0].Marks.Items[iPoint].Text = "B";

           
            iPoint = this.tChart1.Series[0].Add(3.0, 5.55);
            tChart1.Series[0].Marks.Items[iPoint].Text = "D";

            
            iPoint = this.tChart1.Series[0].Add(4.0, 6.66);
            tChart1.Series[0].Marks.Items[iPoint].Text = "E";

           
            iPoint = this.tChart1.Series[0].Add(5.0, 7.66);
            tChart1.Series[0].Marks.Items[iPoint].Text = "G";

            
            iPoint = this.tChart1.Series[0].Add(6.0, 8.66);
            tChart1.Series[0].Marks.Items[iPoint].Text = "S";

            //change the 7.0 to 8.0 or any value greater than the last value(7.1) to see error in chart
            iPoint = this.tChart1.Series[0].Add(7.0, 9.66);
            tChart1.Series[0].Marks.Items[iPoint].Text = "K";
            
            iPoint = this.tChart1.Series[0].Add(7.1, 16.66);
            tChart1.Series[0].Marks.Items[iPoint].Text = "W"; 

            //i use an arraylist of objects that get pulled from the chart by the user
            // I have simulated that here for brevity
            
            SelectedObjects so = new SelectedObjects();
            so.OldValue = "A";
            so.NewValue = "a";//this would be the new mark value to be displayed on the chart
                              //if there were a match in the series data vs the user data
            al.Add(so);
            
            so = new SelectedObjects();
            so.OldValue = "B";
            so.NewValue = "b";
            al.Add(so);
            
            so = new SelectedObjects();
            so.OldValue = "K";
            so.NewValue = "k";
            al.Add(so);
            
            so = new SelectedObjects();
            so.OldValue = "S";
            so.NewValue = "s";
            al.Add(so);
            
           tChart1.Series[0].Marks.Visible = true;
           
        }
        void InitializeChart1()
        {
            tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;

            tChart1.Series[0].Marks.Items.Clear();
            // this is the same as above but using the Add overload
            int iPoint = this.tChart1.Series[0].Add(1.0, 3.33, "A");

            iPoint = this.tChart1.Series[0].Add(2.0, 4.44, "B");

            iPoint = this.tChart1.Series[0].Add(3.0, 5.55, "D");

            iPoint = this.tChart1.Series[0].Add(4.0, 6.66, "E");

            iPoint = this.tChart1.Series[0].Add(5.0, 7.66, "G");

            iPoint = this.tChart1.Series[0].Add(6.0, 8.66, "S");

            iPoint = this.tChart1.Series[0].Add(7.0, 9.66, "K");

            iPoint = this.tChart1.Series[0].Add(8.0, 16.66, "W");
            



            SelectedObjects so = new SelectedObjects();
            so.OldValue = "A";
            so.NewValue = "a";
            al.Add(so);

            so = new SelectedObjects();
            so.OldValue = "B";
            so.NewValue = "b";
            al.Add(so);

            so = new SelectedObjects();
            so.OldValue = "K";
            so.NewValue = "k";
            al.Add(so);

            so = new SelectedObjects();
            so.OldValue = "S";
            so.NewValue = "s";
            al.Add(so);

            tChart1.Series[0].Marks.Visible = true;

        }

        private void points1_GetSeriesMark(Steema.TeeChart.Styles.Series series, Steema.TeeChart.Styles.GetSeriesMarkEventArgs e)
        {
            if (e.ValueIndex > -1)
            {
                e.MarkText = series.Marks.Items[e.ValueIndex].Text;
                Console.WriteLine(e.MarkText.ToString() + "," + e.ValueIndex.ToString() + "," + series.Marks.Items[e.ValueIndex].Text.ToString());
            } 

        }
        //this button starts the process of iterating over the series data and the user array data to find matches 
        private void btnbutton1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < tChart1.Chart.Series[0].Count; i++)
            {
                Console.WriteLine("Series Value: " + tChart1.Chart.Series[0].Marks.Items[i].Text.ToString());
                int x = 0;
                while (x != al.Count)//spin thru the user arraylist to find a match to the series data
                {
                    SelectedObjects so = new SelectedObjects();
                    so = (SelectedObjects)al[x];
                    if (tChart1.Chart.Series[0].Marks.Items[i].Text.ToString() == so.OldValue.ToString())
                    {
                        //if there is a match then mark the collection 
                        //with an X and change to the new mark.item[n].text value                        
                        Console.WriteLine("Match");tChart1.Chart.Series[0].Marks.Items[i].Text = so.NewValue.ToString();
                        tChart1.Chart.Series[0].Marks.Items[i].Tag = "X";
                        x++;
                        break;
                    }

                    x++;
                }
                
            }

            //now go over the series data.marks.items[n] again to remove the unwanted marks
            for (int x = 0; x < tChart1.Series[0].Count; x++)
            {
                if (tChart1.Series[0].Marks.Items[x].Tag == null)
                {
                    tChart1.Series[0].Marks.Items[x].Text = "";
                }

            }
            
            
        }
    }

    public class SelectedObjects
    {
        public SelectedObjects() { }

        private string oldValue;
        private string newValue;

        public string OldValue
        {
            get { return oldValue; }
            set { oldValue = value; }
        }
        public string NewValue
        {
            get { return newValue; }
            set { newValue = value; }
        }
    }
}


Re: Visualize selected label/Marks in chart

Posted: Mon Sep 07, 2009 9:30 am
by narcis
Hi Rick,
after a long day of this i am convinced they may be a bug involving the Marks.Items[n] collection. See the notes in the code box.
I don't think it is a bug. Using InitializeChart1()'s approach you can get it working using series.Labels[index] instead of series.Marks.Items[index].Text[index]. When adding points with a text label to a series those labels are stored in the Labels ValueList.
I am using version 2.0.2009.21355:RunTime Version : v2.0.50727.
Can you please confirm the TeeChart version you are using? According to our records you have a subscription for TeeChart for .NET 2009.
I can make this work if the data is "ALWAYS" inserted sorted acsending. If by design the OK.. just would have liked to have found that little tibit somewhere...
This is not a bug either, you just need to set XValues to not being sorted. So, in InitializeChart(), before populating series you need to add the line below so that this will work whether series are populated in ascending mode or not.

Code: Select all

			tChart1[0].XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
Hope this helps!

Re: Visualize selected label/Marks in chart

Posted: Tue Sep 08, 2009 12:14 pm
by 8748279
Narcis - Thanks so much for the quick reply. I am glad to see there is no bug. I just don't know what I don't know yet about TChart. Yes, indeed i do have TChart 2009 so i am not sure where i got those version numbers off hand.
This is a really good support forum.

Thanks again.
Rick

Re: Visualize selected label/Marks in chart

Posted: Tue Sep 08, 2009 1:08 pm
by narcis
Hi Rick,

You're very welcome! I'm glad to hear that helped.