After using example from http://code.google.com/p/drupal-chart-api/wiki/Examples I've got error's

Notice: Undefined index: chts in _chart_append() (line 513 of C:\xampp\htdocs\drupal\sites\all\modules\chart\chart.module).
Notice: Undefined index: chxl in _chart_append() (line 639 of C:\xampp\htdocs\drupal\sites\all\modules\chart\chart.module).
Notice: Undefined index: chxp in _chart_append() (line 659 of C:\xampp\htdocs\drupal\sites\all\modules\chart\chart.module).
Notice: Undefined index: set in _chart_append() (line 658 of C:\xampp\htdocs\drupal\sites\all\modules\chart\chart.module).

$chart = array(
      '#chart_id' => 'test_chart',
      '#title' => chart_title(t('Servings'), 'cc0000', 15),
      '#type' => CHART_TYPE_LINE,
      '#size' => chart_size(400, 200),
      '#adjust_resolution' => TRUE,
    );
    
  $chart['#data']['fruits'] = array(1, 3, 5, 4, 2);
  $chart['#data']['meats']  = array(2, 2, 4, 3, 1);
  $chart['#data']['dairy']  = array(5, 2, 3, 1, 2);

  $chart['#legends'][] = t('Fruits');
  $chart['#legends'][] = t('Meats');
  $chart['#legends'][] = t('Dairy');

  $chart['#data_colors'][] = '00ff00';
  $chart['#data_colors'][] = 'ff0000';
  $chart['#data_colors'][] = '0000ff';

  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0, 5);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_label(t('Count'), 95);
  
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Mon'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Tue'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Wed'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Thu'));  
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Fri'));
  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('Days of the week'), 50);
echo theme('chart', array('chart' => $chart));

Comments

Itex’s picture

StatusFileSize
new63.51 KB
ununpentium’s picture

I, too, get this same list of errors when using the line chart example.

leszek.hanusz’s picture

subscribing

SebCorbin’s picture

Same thing here

maulik.kamdar’s picture

Hello,

I had faced similar problems when I was trying to append the Axis Labels using Chart Views.
You might wish to review the patch I had uploaded for the issue #1206306: Setting Chart Axes, Gridlines and Axis Labels in Chart using Views Plugin. It allows a user to set Axis Labels (value Range and custom Field) for Line and Bar Charts. I had made minor modifications in the Chart API for the same, as below:

diff --git a/chart.module b/chart.module
index 76e177b..cc36512 100644
--- a/chart.module
+++ b/chart.module
@@ -632,6 +632,7 @@ function _chart_append($attr, $value, &$data) {
       }
       // Generate regular labels
       if (count($regular)) {
+        $data['chxl'] = "";
         foreach ($regular as $axis => $indices) {
           if (count($indices)) {
             foreach ($indices as $i => $labels) {
@@ -641,6 +642,7 @@ function _chart_append($attr, $value, &$data) {
                 foreach ($labels as $j => $label) {
                   $data['chxl'] .= '|' . $label['#label'];
                   $positions[$index]['data'][] = isset($label['#position']) ? $label['#position'] : 0;
+                  $positions[$index]['set'] = FALSE;
                   if ($label['#position']) {
                     $positions[$index]['set'] = TRUE;
                   }

I donot know if these are correct (Patch has just been uploaded for review), but it worked out pretty splendid for me.
Thanks.

Konstantin Komelin’s picture

subscribing

levelos’s picture

Status: Active » Needs review
StatusFileSize
new897 bytes

Here's a patch for 7.x-1.0

defconjuan’s picture

Applied patch and still getting error. (I validated that the updates in the patch file were implemented and flushed all caches.)

nkschaefer’s picture

StatusFileSize
new544 bytes

I looked at it - "chts" is how the Google Chart API defines the style of the chart title. If we wanted to make this fancier, we could add a property in the user-defined chart array called '#title_style' or something and come up with a default value. That would go in chart_build() -- define a default value and then later add a line that does something like _chart_append('chts', $chart['#title_style']), $data);

This seems complicated, though, and I don't know too much about how this was designed. So instead, I just changed line 513 to set chts initially, instead of trying to append to it. In other words, I deleted the dot in front of the equals sign. That fixed it.

Here's a patch that does that. I think that's all we need here.

nkschaefer’s picture

Oops. I had clicked here from another issue - I should clarify that my patch only addresses the "undefined index: chts" error. That's the only one I was getting.

nodestroy’s picture

#7 works for me

ximo’s picture

StatusFileSize
new1.69 KB

Here's a hotfix patch for 7.x-1.0. It's similar to #7, with an added fix for the same error on $data['chxr'] and $data['chxp'].

13rac1’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Needs review » Fixed
StatusFileSize
new1.29 KB

I used one change in #7, and then applied additional isset() checks for everything else. Now the chart code above works w/o notices. Isset() is the method used in the rest of the module. The 7.x-1.x-dev patch of changes is attached, if needed in 6.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.