Comments (8)
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.
where $series is...
my $series = Chart::Clicker::Data::Series->new( %$i );
from chart-clicker.
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.
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.
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.
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.
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.
maybe put this in the examples/ directory?
from chart-clicker.
Related Issues (20)
- Feature Request: Render graph in reverse HOT 1
- Bug in Legend draw HOT 1
- Bug in drawing range_axis label with spaces in name. HOT 2
- unable to create Bar Graph HOT 1
- Passing a list of values to enum is deprecated HOT 1
- Circular references causing memory leaks HOT 1
- Chart::Clicker fails to install because Graphics::Primitive::Driver::Cairo doesn't install HOT 2
- Large amount of white space around range label HOT 1
- broken link on home page HOT 1
- t/axis-division-rounded.t test fails on FreeBSD 10.1 with -Duselongdouble
- MS Windows failure (probably related to Graphics-Primitive-Driver-GD-0.01) HOT 2
- Warnings with recent Moose versions HOT 4
- Question: Is it possible to draw text on chart? HOT 1
- Chart::Clicker makes way too many set-font-options and select-font-face calls
- Rendering Blurriness Due to Default Cairo Library Grid System
- Need Option to Reverse Order of Legend Items
- Decimals of 0 value not scaling correctly on chart
- Examples not working HOT 2
- Additional modules required on Kubuntu 18
- Chart::Clicker::Axis + LinearRounded FAIL under -Dusequadmath
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chart-clicker.