Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative Chart Values throwing error #175

Closed
shaunvdp opened this issue Sep 7, 2017 · 9 comments
Closed

Negative Chart Values throwing error #175

shaunvdp opened this issue Sep 7, 2017 · 9 comments
Assignees
Milestone

Comments

@shaunvdp
Copy link

shaunvdp commented Sep 7, 2017

Hi All...

Thanks to the creator of this brilliant piece of software... I have come across an issue that I wanted to point out, maybe someone came up with a solution for it.

This works great:
var dataChartBar = [
{
name : 'Region 1',
labels: ['May', 'June', 'July', 'August'],
values: [26, 53, 100, 75]
}
but as soon as I insert a negative value into the array an error is thrown: 'Cannot read property 'length' of undefined' ...

var dataChartBar = [
{
name : 'Region 1',
labels: ['May', 'June', 'July', 'August'],
values: [-26, 53, 100, 75]
}

has anyone come across this and found a solution to it? your help will be greatly appreciated...

many thanks...

@gitbrent gitbrent self-assigned this Sep 8, 2017
@gitbrent
Copy link
Owner

gitbrent commented Sep 8, 2017

Hi @shaunvdp ,

This issue must be somewhere else in your code. Negative numbers work fine in charts:

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

var dataChartBar = [{
    name : 'Region 1',
    labels: ['May', 'June', 'July', 'August'],
    values: [-26, 53, 100, 75]
}];

slide.addChart( pptx.charts.BAR, dataChartBar, {} );

pptx.save('PptxGenJS-NegChart');

screen shot 2017-09-07 at 23 10 30

@shaunvdp
Copy link
Author

shaunvdp commented Sep 8, 2017

ah... thanks so much for the quick response... I stripped the code out and it seems to be working... looks like there was an error in the additional attributes being set up... more specifically, chartColors: ['2F469C'] ...

if there are negative numbers, I am assuming that two colors need to be specified, so did so by adding chartColors: ['2F469C','2F469C'], ... and that too, broke the chart...

any help in doing this will be much appreciated...

thanks

gitbrent pushed a commit that referenced this issue Sep 9, 2017
@gitbrent gitbrent changed the title Negative Values throwing error Negative Chart Values throwing error Sep 9, 2017
gitbrent pushed a commit that referenced this issue Sep 9, 2017
@gitbrent
Copy link
Owner

gitbrent commented Sep 9, 2017

Hi @shaunvdp ,

What an awesome twist - you turned a non-error into an actual error. Thanks! :-)

Supplying chartColors without invertedColors was causing an issue. The fix is checked in now.

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

var dataChartBar = [{
    name : 'Region 1',
    labels: ['May', 'June', 'July', 'August'],
    values: [-26, 53, 100, 75]
}];

slide.addChart( pptx.charts.BAR, dataChartBar, {chartColors: ['2F469C','2F469C']} );
pptx.save('PptxGenJS-NegChart');

screen shot 2017-09-08 at 20 22 03

@gitbrent gitbrent added this to the 1.8.0 milestone Sep 9, 2017
@shaunvdp
Copy link
Author

ah ha! thanks so much... will download the newest build. :)

@shaunvdp
Copy link
Author

Hi... Me Again... Just tested the new release and noticed that when supplying 2 colors as per your code, the two colors get alternated between the bars (for example if I supply [red,white] the bars will be red, white, red, white, red, white... instead of one being assigned to positive and one being assigned to negative.

@gitbrent
Copy link
Owner

Use the invertedColors option to pass colors for negative numbers.

Correct, passing two colors is asking the system to use two alternating colors - just use one color if you want only 1 across all bars. There's tons of examples in examples/pptxgenjs-demo.html

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

var dataChartBar = [{
    name : 'Region 1',
    labels: ['May', 'June', 'July', 'August'],
    values: [-26, 53, 100, 75]
}];

slide.addChart(
  pptx.charts.BAR,
  dataChartBar,
  {
    chartColors: ['2F469C'],
    invertedColors: ['CC8800']
  }
);
pptx.save('PptxGenJS-NegChart');

screen shot 2017-09-11 at 19 56 28

@shaunvdp
Copy link
Author

Thanks so much... I didn't and still don't see invertedColors anywhere in the documentation... thanks for pointing it out. ;)

@shaunvdp
Copy link
Author

I actually found it is this issue: #140

but you do not mention it is any of the examples or documentation for usage...

gitbrent pushed a commit that referenced this issue Sep 13, 2017
@gitbrent
Copy link
Owner

Whoops!!

Added to README now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants