0

I have a visual force page with code to draw google visualization chart. I had a problem that visualforce charts dynamically choose the baseline to start with. for e.g. check the image1 attached where it portrays a wrong visual comparison as if LYR value (13M) is 25% of YTD value (17.8M) but it's NOT. This is because the chart starts with 12M as baseline instead of 0 enter image description here

Hence I modified the Haxis to start with min:0 as below:

var options = {
          title: 'Amount',
          chartArea:{width:"60%"},
          hAxis: {viewWindow:{min:0}},
          legend: {position: 'none'}
        };

The problem with above is that if amount is negative it does not scale accordingly and does not even show bar for the -ve value as my chart starts always at ZERO. Is there a way to customize in the code mentioning that

if Amount>0 then min:0, else let the chart decide the min dynamically.

1

1 Answer 1

1

I figured out the code and below worked:

var data = google.visualization.arrayToDataTable(
[ ['Year', 'Amount'],
 ['YTD', {!obj1.ytd_value}], 
['LYR', {!obj1.lyr_value}] ]); 


if(data.getValue(0,1) >= 0 && data.getValue(1,1) >= 0) 
{ 
var options1 = { 
title: 'Amount', 
chartArea:{width:"60%"}, 
hAxis: {viewWindow:{min:0}}, 
legend: {position: 'none'} 
}; 

var chart1 = new google.visualization.BarChart(document.getElementById('chart_div')); chart1.draw(data, options1); 
} 
else
{ 
var options2 = { 
title: 'Amount', 
chartArea:{width:"60%"}, 
legend: {position: 'none'} 
}; 

var chart2 = new google.visualization.BarChart(document.getElementById('chart_div')); chart2.draw(data, options2); 
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .