Start a new topic

Ranged Bar Charts

I have wanted a bar chart that can show a range between a Top to Bottom value and found, after much experimentation, that the slider works well for this if it is touch disabled. You can put a graph image under the slider to get a graphed display 

The slider I have used has a range of 0-100 (maxval) and a height of 300


The formulae are:

 h1.val = (R x Bot)/(R-Top+Bot)             // simple when you work it out

 h1.hig = 300*(Top-Bot)/100                  // difference converted to pixel height


Where R=100 and Top and Bot are the values you want to display (0-100)

I have not tried to generalise this for automatic range adjust


You will see that the bars do not always fit correctly. This is because of no floating point math in the nextion.  The calculation may give 87.8 but the integer answer is 87 and this makes a difference to the bar position

I am sure my math constructs could be simpler under the push button but it would be easier to do the maths in a CPU and send the hig and val values up


Also, if you use a Bot = Top-1 Top then you can get a line chart

HMI

I will argue academically - this is not because of no floating point math.

 - one has two sources to refer to

   - historical, the early PCs did not implement professional software with such error 

   - embedded, many embedded solutions also implement without error

 - because Nextion does not have floating point should only be off by one pixel

   this should mostly be less visible to the eye,

 - any and all system have rounding behaviours

    - truncate, roundup, or bankers

    - Nextion is truncated

        - this is not an error, but design.

    - No system can have default behaviour of all three

    - all code can have all three

but when one behaviour is not the one you desire

    - use code to implement the desired effect.


on 87.8 if you wanted to round this up

   same basic math principles on paper

    - isolate the fractional part according to desired behaviour

    - evaluate based on rules of desired behaviour

    - implement adjustment if needed.


Yes. I know I can round numbers up and down with basic maths; the submission was mainly to show how ta ranged chart can be accomplished. The error is dependent on the range and the slider height. With a 300 sized slider and a 100 range the error is 3 pixels per unit value, and that's what you see in this example. More accuracy would be obtained with making the range = 300, so one pixel per unit but then your Top and Bot settings would have to be multiplied by 3 which adds in other errors..


So then this is indeed not because the nextion lacks floating point

 - but by your account - it was your equation.

Also in graphics

  - range-1-thumb_height travels  slider_height-1

in a slider of range of 101 positions from 0 to 100 only 1 pixel is

   used for 1 and remainder on other range-1 positions

So the graphic background should have height of

   (range-1)*3+1  where range is (max-min+1)

   slider in graphic would need height of 301+thumb-height needed for it to align


Just making clear Nextion's accuracy is not more than 1 pixel off.

I really don't understand why you are so strongly defending the Nextion lack of floating point. The simple fact is the accuracy is related to the range you apply and the height of the slider. If you carefully adjust both then yes, you can get within a pixel. Whippy Doo.


I have found that I can display only from 0 to 85 or 100 down to 15.... This is because the cursor value can only be set to a maximum of 255 ( byte?) irrespective of the h of the slider


So if you have a large slider then you cannot have a very large cursor --- Fault?

I really don't understand why you are so strongly defending the Nextion lack of floating point.


This is embedded world and almost all MCUs lack an FPU (Floating Point Unit) coprocessor module.

When an MCU does not contain floating point - all such is done in code.

Many FPU emulations via code are simply not as effective as integer.


So why defend ... ? 

Facts.  Others will read and it is important that they read what is truly fact

With facts, understanding of what is really happening and how it works

  can begin to allow someone to use knowing the facts


With out facts?

Well then people don't understand what is really going on

  - many mistakes are made through incorrect assumptions.


I can indeed set a larger display vertical

  and in doing so have 750 for a range if I chose to do so

So I am not sure how it can be construed a fault if

   Nextion will follow my instructions and implement it correctly.


When less than accurate statements are made on not knowing all the facts

  others will also read and form their opinion based on what is less than true.


Would you want to know what is the actual fact

  or rather accept incorrect details from those who know less?


Such in the end effects the quality of your finished product

 - customers certainly want the better product that works perfectly.

Yes I agree  but statements like 

 

Just making clear Nextion's accuracy is not more than 1 pixel off.  are fatuous as what else can you have when you address at the pixel level, Also my formulae are not wrong but by your account - it was your equation. The inaccuracies are the mismatch of range and size where there is only on combination where a one pixel accuracy can be obtained with simple maths instructions



Perhaps, as the most vocal and omnipresent person on any of these forums maybe you should ask yourself about your opinions for development, certainly your responses above were nothing other than throwing cold water on someone elses idea


What I have given this community is a tool that can allow more options with Nextion,yet what I get is it thrown back in  my face!    I lesson learnt at my end and not to be repeated





Perhaps, as the most vocal and omnipresent person on any of these forums maybe you should ask yourself about your opinions for development, certainly your responses above were nothing other than throwing cold water on someone elses idea


So we circle back:
  - I am omnipresent, and trickle knowledge, because I enjoy Nextion
  - before I started to do so, questions went unanswered for months
So let see, a forum of mostly non working code and questions why
    and few working examples. 
So indeed I reply, mostly with the answer.  Quickly.

You will see that the bars do not always fit correctly.
   This is because of no floating point math in the nextion

It isn't cold water that I am attempting to throw on an idea
  - rather, I would think it is the knowledge to achieve the result
MCUs are not forgiving of error, they only do as they are instructed

Was it not just a couple of days ago, 
   did I not help you figure out order of operation and parsing
And with that new knowledge - did you not make your program better.
And did I make you wait months for a reply?
Was my answer not accurate so you could get a result?

So take a look, truly look
   with the order of operation and parsing now better
   Above is the next info in step on how to fix and make it better again
So that you don't have to make statements like 
   "this is because of no floating point math in the nextion"

I am sorry you took it as throwing in your face
   You have the answer above on how to make it accurate

But really, if no one wanted to know about how to fix, how sad
   a repository that suggests Nextion doesn't work
   when its not Nextion's fault but user equations needing repair.
   cant repair without knowledge and understanding

I will continue to correct misunderstandings, so people can learn
   maybe the next guy reading this will see the equation and
   at least his will perhaps fit correctly and not blame Nextion.

And I am not trying to discourage you, not at all.


But how did you feel having to make the statement

    You will see that the bars do not always fit correctly.

Did you make it because others would see, so preemptive

    My bet is you'd prefer not having to say so


When posted in Free Chat, section of discussion and

   through more discussion comes more understandings

I'll be honest, I may have mistaken your post as a question.


Had you posted this in Gallery

 - assuming such is not already in Gallery, you start own thread

 - if such is in Gallery, you post in existing thread

That can be less of a discussion or even more to discuss

( I would still have clarified Nextion not a fault point for accuracy )

Not to be an ass, but just to prove it can be done 

  - and that Nextion is not at fault 

such is what I was trying to show you before you became resistant


attached below is ranged.page

 - import page into project (made for 3.2" Nextion displays)

To use:

     ranged.hi.val=100 // from (0 to 100)

     ranged.lo.val=0 // from (0 to 100)

     page ranged

  - your range graph will draw no issues if hi>=lo

  Interactively

     - click high value on screen, use side slider to adjust

     - click low value on screen, use side slider to adjust

   - your range graph will refresh when leaving side slider.


Left for those to use in their projects

page
(38.4 KB)
Login or Signup to post a comment