Can I setNull use other funcion ?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Can I setNull use other funcion ?

Post by coldwind » Thu Feb 16, 2023 11:33 am

Hello :

i want to show data with null, TeeChart API ,I can find the setNull(int valueIndex) function could achieve my goal.Does TeeChart has other function to do this, so i don't need to collect the null value index Array to execute SetNull api function?
Do I have to use SetNull function?

Code: Select all

		list.Add(new Student("A", 10));
		list.Add(new Student("B", null));
		list.Add(new Student("C", 11));
		list.Add(new Student("D",14));
		age.Add(list as IList);
		
		tChart1[0].SetNull(2);
		
		(tChart1[0] as Steema.TeeChart.Styles.CustomPoint).TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Can I setNull use other funcion ?

Post by Christopher » Tue Feb 21, 2023 4:19 pm

Hello,
Do I have to use SetNull function?
Can you please post a minimal, reproducible example (reprex) that we can copy and paste into a Windows Form and run? The example you give:

Code: Select all

		list.Add(new Student("A", 10));
		list.Add(new Student("B", null));
		list.Add(new Student("C", 11));
		list.Add(new Student("D",14));
		age.Add(list as IList);
		
		tChart1[0].SetNull(2);
		
		(tChart1[0] as Steema.TeeChart.Styles.CustomPoint).TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
Is not a reprex as I can't run it when I copy and past it into a Windows Form. Without a reprex we also cannot understand the context in which you run your code and so cannot give you the best answer to it.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Re: Can I setNull use other funcion ?

Post by coldwind » Wed Feb 22, 2023 3:55 am

Hello:
Okay,the code is below

Code: Select all

	public Form4()
        {
            InitializeComponent();
            InitializeChart();
        }
        class Student
        {
            public string Name { get; set; }
            public double? Value { get; set; }

            public Student(string name, double? value)
            {
                Name = name;
                Value = value;
            }
        }

        private void InitializeChart()
        {

            List<Student> list = new List<Student>();

            var age = new Line(tChart1.Chart);
            age.YValues.DataMember = "Value";
            age.LabelMember = "Name";
            age.Title = "Age";
            age.LinePen.Width = 3;
            
            list.Add(new Student("A", 10));
            list.Add(new Student("B", null));
            list.Add(new Student("C", 11));
            list.Add(new Student("D",14));
            age.Add(list as IList);
  
            
            (tChart1[0] as Steema.TeeChart.Styles.CustomPoint).TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
        }
Maybe TeeChart think when value is null,then process it to 0 . Can i set it to DoNotPaint but not use SetNull(int valueIndex) function. So I don't need know the null value is which valueIndex. I hope TeeChart can process null value automatic. Does TeeChart has which function can do it?


The below code execute result is what i expect.

Code: Select all

	public Form4()
        {
            InitializeComponent();
            InitializeChart();
        }
        class Student
        {
            public string Name { get; set; }
            public double? Value { get; set; }

            public Student(string name, double? value)
            {
                Name = name;
                Value = value;
            }
        }

        private void InitializeChart()
        {

            List<Student> list = new List<Student>();

            var age = new Line(tChart1.Chart);
            age.YValues.DataMember = "Value";
            age.LabelMember = "Name";
            age.Title = "Age";
            age.LinePen.Width = 3;
            
            list.Add(new Student("A", 10));
            list.Add(new Student("B", null));
            list.Add(new Student("C", 11));
            list.Add(new Student("D",14));
            age.Add(list as IList);
  		
 	 	for (var i = 0; i < list.Count; i++)
            {

                if (list[i].Value is null)
                {
                    tChart1[0].SetNull(i);
                }
            }
            
            (tChart1[0] as Steema.TeeChart.Styles.CustomPoint).TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
        }

Maybe my datalist is large, then I don't need to iterator the list can reduce the code rendering time

Do I make myself clear?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Can I setNull use other funcion ?

Post by Christopher » Wed Feb 22, 2023 10:46 am

Hello,
I hope TeeChart can process null value automatic. Does TeeChart has which function can do it?
I think that the question you are trying to ask is: are the values that TeeChart manipulates internally nullable value types? And the answer to this question is: no, they are not; the type that TeeChart uses internally for its data is double, and not double?.
Maybe my datalist is large, then I don't need to iterator the list can reduce the code rendering time
Iterating the data is not a problem, as that is what TeeChart does internally anyway when you use the Add(IList list) overload.
Do I make myself clear?
Yes, thank you, being able to run a reprex makes both the question clearer and the answer more precise.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Can I setNull use other funcion ?

Post by Christopher » Wed Feb 22, 2023 11:10 am

Hello,

Okay, I can see your worry about the iterator, as you were interating twice in your example—to iterate only once you can use code such as the following:

Code: Select all

      public Form1()
        {
            InitializeComponent();

            InitializeChart();

        }
        class Student
        {
            public string Name { get; set; }
            public double? Value { get; set; }

            public Student(string name, double? value)
            {
                Name = name;
                Value = value;
            }
        }

        private void InitializeChart()
        {
            const double defaultnull = -1;

            List<Student> list = new List<Student>();

            var age = new Line(tChart1.Chart);
            age.YValues.DataMember = "Value";
            age.LabelMember = "Name";
            age.Title = "Age";
            age.TreatNulls = TreatNullsStyle.DoNotPaint;
            age.DefaultNullValue = defaultnull;

            list.Add(new Student("A", 10));
            list.Add(new Student("B", null));
            list.Add(new Student("C", 11));
            list.Add(new Student("D", 14));


            list.ForEach(x => {
                if (x.Value.HasValue)
                {
                    tChart1[0].Add(x.Value.Value, x.Name);
                }
                else
                {
                    tChart1[0].Add(defaultnull, x.Name, Color.Transparent);
                }
            });
        }
        
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply