Giter Site home page Giter Site logo

Comments (8)

djzort avatar djzort commented on June 9, 2024

You can do something like

                # if all the values are the same, then manually set min and max
                unless ($series->range->span) {
                    $series->range->max($i->{values}->[0] + 1);
                    $series->range->min($i->{values}->[0] - 1);
                }

or perhaps +/- 5%

                # if all the values are the same, then manually set min and max
                unless ($series->range->span < 1) {
                    $series->range->max($i->{values}->[0] * 1.05);
                    $series->range->min($i->{values}->[0] * 0.95);
                }

from chart-clicker.

djzort avatar djzort commented on June 9, 2024

where $series is...

my $series = Chart::Clicker::Data::Series->new( %$i );

from chart-clicker.

koknat avatar koknat commented on June 9, 2024

Thanks, that worked very well.

BTW, the reason that all data points have the same value is that I run chart::clicker in an automated process, on real data. Occasionally all data points are equal.

from chart-clicker.

djzort avatar djzort commented on June 9, 2024

I have a similar use case, were we are graphing the channel frequency of a device. Which shouldn't actually change very often :)

from chart-clicker.

gphat avatar gphat commented on June 9, 2024

Could you try using a fudge amount on the axis?

$ctx->range_axis->fudge_amount(.015);

This will add a small amount of space above and below (effectively increasing the range) and maybe preventing that error.

from chart-clicker.

djzort avatar djzort commented on June 9, 2024

fudge_amount probably wont give you what you are after if the values are all 0. (since 0 - 0 * 0.015 is still 0)

here is the code that it uses...

    if($self->fudge_amount) {
        my $span = $self->range->span;
        my $lower = $self->range->lower;
        $self->range->lower($lower - abs($span * $self->fudge_amount));
        my $upper = $self->range->upper;
        $self->range->upper($upper + ($span * $self->fudge_amount));
    }

People should be careful to drop the minimum value below zero (to negative) only if that value is appropriate in the graph. also be careful that the fudge amount doesn't expose a meaningless negative value in the axis.

So this is probably better in those cases, with no fudge_amount

                # if all the values are the same, then manually set min and max
                unless ($series->range->span) {
                    $series->range->max($i->{values}->[0] + 1);
                    my $min = $i->{values}->[0] -1;
                    $min = 0 if $min < 0;
                    $series->range->min($min)
                }

though, IMO you should always have at least a fudge_around value of 0.05 - simply so that if a plateau in values appears that people don't confuse it with truncated graphing. noting the exception for going negative

from chart-clicker.

koknat avatar koknat commented on June 9, 2024

Thanks djzort, I used your code.

There are also times where I only have one data point. A chart is somewhat meaningless, but I'd still rather have a flat-line chart than no chart at all. As a workaround, I push an identical data point onto my $i->{values}

from chart-clicker.

djzort avatar djzort commented on June 9, 2024

maybe put this in the examples/ directory?

from chart-clicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.