Drupal google Chart api Y 轴值需要帮助

发布于 2024-10-24 12:22:39 字数 1773 浏览 1 评论 0原文

我正在使用 chart,这是一个使用 Google 图表工具

我已经成功创建了图表,但我的问题是我想在 Y 轴上放置整数值。我正在制作一张总票数图表。假设我有一个有 55 票(总数)的民意调查。 Y 轴范围应直到最大值属性。就像如果我们有 A、B 和 C,那么 A 有 25 票,B 有 10 票,C 有 20 票。因此,Y 轴范围应等于 25,并且它们之间没有 1.5 或 2.5 等浮点值。这是我的函数的代码:

//theme the poll results block

  $html = $variables['results'];
  $pattern = "@class=\"text\"\>(.*)\</div\>@";
  preg_match_all($pattern, $html, $choices); //extract choices
  $pattern = "@style=\"width: (.*)%;\"@";
  preg_match_all($pattern, $html, $votes); //extract percentages
  $chart = array(
      '#chart_id' => 'poll_chart' . $variables[nid],
      '#type' => CHART_TYPE_BAR_V,
      '#size' => chart_size(600, 350),
      '#grid_lines' => chart_grid_lines(100,10 ),
      '#bar_size' => chart_bar_size(30, 50),
  );

// NEED TO FILL IN DATA TO MAKE CHART
  for ($c=0; $c < count($choices[1]); $c++) { //make labels and values
     $chart['#data_colors'][] = 'ff8e07';
     $chart['#data'][$choices[1][$c]] = $votes[1][$c]; //number of votes
     $chart['#legends'][] = $choices[1][$c] . " (" . $votes[1][$c] . "%)"; // labels
     $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t($choices[1][$c]))
     ;
     print $choice['chvotes'];
  }

  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('Choices'), 50);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][3][] = chart_mixed_axis_label(t('Votes'), 95);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][4][] = chart_mixed_axis_range_label(0, $variables['votes']);

  $variables['results'] = chart_render($chart); //render graph

I am using chart, a drupal module using google chart tools.

I have created the graph successfully but my problem is that I want to put integer values in the Y axis. I am making a graph of total number of votes. So let's suppose I have a poll with 55 votes (total nummer). The Y axis range should be till the max value property. Like if we have A, B and C then A has 25 votes, B has 10 votes and C has 20 votes. So the Y axis range should be equal to 25 with no float values like 1.5 or 2.5 between them. Here is the code of my function:

//theme the poll results block

  $html = $variables['results'];
  $pattern = "@class=\"text\"\>(.*)\</div\>@";
  preg_match_all($pattern, $html, $choices); //extract choices
  $pattern = "@style=\"width: (.*)%;\"@";
  preg_match_all($pattern, $html, $votes); //extract percentages
  $chart = array(
      '#chart_id' => 'poll_chart' . $variables[nid],
      '#type' => CHART_TYPE_BAR_V,
      '#size' => chart_size(600, 350),
      '#grid_lines' => chart_grid_lines(100,10 ),
      '#bar_size' => chart_bar_size(30, 50),
  );

// NEED TO FILL IN DATA TO MAKE CHART
  for ($c=0; $c < count($choices[1]); $c++) { //make labels and values
     $chart['#data_colors'][] = 'ff8e07';
     $chart['#data'][$choices[1][$c]] = $votes[1][$c]; //number of votes
     $chart['#legends'][] = $choices[1][$c] . " (" . $votes[1][$c] . "%)"; // labels
     $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_label(t($choices[1][$c]))
     ;
     print $choice['chvotes'];
  }

  $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('Choices'), 50);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][3][] = chart_mixed_axis_label(t('Votes'), 95);
  $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][4][] = chart_mixed_axis_range_label(0, $variables['votes']);

  $variables['results'] = chart_render($chart); //render graph

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文