Great work, could use some more documentation, I spent a lot of time in the module to get it to work.

One thing I could not solve was how to have a chart with 2 distinct bars with 2 different colors.

I believe it might thave something to do with the default is chd:t and chd:s is not generated.

Bar chart:

http://chart.apis.google.com/chart?chd=t%3A55.8%2C28.9&cht=bhs&chs=280x1...

I was successful in creating a scatter plot of userpoints by pid # - Khalil has asked me to make it into a contrib module for userpoints.

http://chart.apis.google.com/chart?chd=t%3A12.5%2C25%2C37.5%2C50%2C62.5%...

the Drupal code is here:

http://snippets.dzone.com/posts/show/5985

CommentFileSizeAuthor
#10 chart.module.patch549 bytesamagdy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

decibel.places’s picture

oops, my bad, I meant "Khalid"!

tjholowaychuk’s picture

hello,
Another user had the same issue, I think the issue may have been closed though ( was quite old ). this was due to the data passed being a single dataset. I didnt have a look at your code but you may need to simply 'nest' the data arrays another level.

http://code.google.com/p/drupal-chart-api/wiki/Examples

in one of those examples I created you will see:

 $chart['#data'][] = array(40, 50, 70);
 $chart['#data'][] = array(40, 60, 20);
 $chart['#data'][] = 40
 $chart['#data'][] = 50
decibel.places’s picture

Yeah I tried that - it will work for multiple data in each array but not for one data in each color... it will only show both bars in the first color

If more than one datapoint is in each array, then the colors sort - but I only want 2 bars (tried making the extra data 0 too...)

tried CHART_TYPE_BAR_H_GROUPED, CHART_TYPE_BAR_H, $chart['#data_colors']['solo'] = 'ff0000';, $chart['#data_colors'][] = 'ff0000';

http://chart.apis.google.com/chart?chd=t%3A55.8%2C28.9&cht=bhg&chs=500x2...

$solopts and $avgpoints are positive integers, in this case 558 and 289 respectively...

$chart = array(
      '#chart_id' => 'flybar',
      '#title' => chart_title(t('flyDollars'), '6d769f', 25),
      '#type' => CHART_TYPE_BAR_H_GROUPED,
      '#size' => chart_size(500, 200),
	  '#bar_size' => chart_bar_size(30, 5), 
);

$chart['#data']['solo'] = $solopts;
$chart['#data']['avg'] = $avgpts;

$chart['#data_colors']['solo'] = 'ff0000';
$chart['#data_colors']['avg'] = '00ff00';

$grid = array(10,10,1,1);
$chart['#grid_lines'] = $grid;

$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_range_label(0, 1000);
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t(' '));    
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t(' '));
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t(' '));    
 
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] =  chart_mixed_axis_label(t('average $'));
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] =  chart_mixed_axis_label(t('my $'));
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][2][] =  chart_mixed_axis_label(t(' '));


//label colors
$chart['#mixed_axis_label_styles'][] = array(0,'000000',12);
$chart['#mixed_axis_label_styles'][] = array(1,'6d769f',18);
$chart['#mixed_axis_label_styles'][] = array(2,'6d769f',18);

echo chart_render($chart);

iLikeSunshine’s picture

I'm having the same issue described here - I want to draw a bar chart with the bars colored according to the value of a node property. But, the only color displayed is the first one that I assign to $chart['#data_colors'][X] , where X is any number, or a blank space.

foxtrotcharlie’s picture

I've figured out that for a normal (non-grouped) bar chart, if the chart colours that are passed in the url are separated by a pipe (|) and not a comma (,) then each bar gets a different colour.

On my site, because I'm only ever using a single bar chart, I hacked the chart.module function chart_build line 280 from:

  _chart_append('chtm', $chart['#georange'],                $data); 
         
  $charts[$chart['#chart_id']] = drupal_query_string_encode($data);       
                  
  return $charts[$chart['#chart_id']];

to:

  _chart_append('chtm', $chart['#georange'],                $data); 
  
  // For standard (non-grouped) bar charts, we need to use a pipe separator
  // instead of a comma otherwise we lose the different colours.
  if ($chart['#type'] == CHART_TYPE_BAR_V || $chart['#type'] == CHART_TYPE_BAR_H) {
    $data['chco'] = str_replace(',', '|', $data['chco']);
  }
  
  $charts[$chart['#chart_id']] = drupal_query_string_encode($data);       
                  
  return $charts[$chart['#chart_id']];

I haven't tested this code extensively to see if it affects the other graph types (it shouldn't), so take care when using it.

IF this looks like a good solution to the module maintainer(s), then I'm happy to create a patch - let me know, or let me know of a better way of doing this.

boombatower’s picture

Status: Active » Postponed (maintainer needs more info)

Is this still an issue?

decibel.places’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

@boombatower

Drupal 5 has been retired; there are more options for creating charts now.

I think it's resolved :)

FWIW I have a Google chart with two bar colors in D6 at http://faiththedog.info/ (it's just Google Charts code in a block)

<p><a href="http://faiththedog.info/blogs/childrens-book-reality" title="click to learn more"><img alt="5000 Emails Needed" src="http://chart.apis.google.com/chart?chxr=0,0,15000&amp;chxt=y&amp;chbh=a&amp;chs=280x190&amp;cht=bvs&amp;chco=3D7930,793D30&amp;chds=0,3800,0,14500&amp;chd=t:15000%7C0,14000&amp;chdl=15000+Emails%7CEmails+So+Far&amp;chtt=We%20Need%20500%20Emails&amp;chts=006666,20" border="0" height="225" width="250"></a></p>
boombatower’s picture

I am aware Drupal 5 is retired, but the issue may still exist in this module in 6 or 7.

Thanks for the response.

amagdy’s picture

FileSize
549 bytes

this patch will color each column with different color

msti’s picture

Version: 5.x-1.2 » 6.x-1.3
Status: Closed (fixed) » Reviewed & tested by the community

This issue has not been fixed in the latest dev.
The patch at #10 fixes the issue for 6.x-1.3

Pierre.Vriens’s picture

apaderno’s picture

Version: 6.x-1.3 » 6.x-1.x-dev
Status: Reviewed & tested by the community » Closed (outdated)

I am closing this issue, as Drupal 6 is no longer supported.