打开 Flash 图表 - 工具提示 #x_label# 未显示
我目前正在使用 PHP 通过 Open Flash Charts(我相信版本 1,可能是版本 2...)实现的条形图。不幸的是,我们遇到了真正的麻烦,工具提示没有显示正确的内容。我试图让它显示悬停列的 x 轴标签,然后是“:”,然后是条的值。代码如下:
$Colour = '#3465A4';
$BarChart= new bar();
$BarChart->set_values($Bar);
$BarChart->set_colour($Colour);
$BarChart->set_tooltip('#x_label#:#val#');
$x_labels = new x_axis_labels();
$x_labels->set_labels($Roles);
$x_labels->rotate(-60);
$x = new x_axis();
$x->set_labels($x_labels);
$chart = new open_flash_chart();
$chart->add_element($BarChart);
$chart->set_bg_colour( '#FFFFFF' );
$chart->set_x_axis($x);
$tooltip = new tooltip();
$tooltip->set_hover();
$chart->set_tooltip($tooltip);
$JSONArray['my_chart_1'] = $chart->toPrettyString();
据我所知,这应该是正确的 - 条形图出现,并具有正确的值(从 $bar 填充,其生成未在上面显示)。但是,列的悬停工具提示仅显示“:值” - 缺少标签名称!
有谁知道我们可能哪里出了问题,以及我该如何修复它?
编辑:
为任何前来尝试回答此问题的赏金猎人提供更新。我没有接受以下答案的原因是它只提供了解决方法,并没有解释为什么需要解决方法。我正在寻找我最初问题的答案(如何使标签显示在正常条形图中),或者寻找关于为什么必须使用堆积条形图的合理解释(包括来源你的答案好多了!)。如果是后者,示例代码或如何创建堆叠图表的解释也将非常感激!
I'm currently playing with a bar chart implemented through Open Flash Charts (I believe version 1, might be version 2...) with PHP. Unfortunately, we're having real trouble with the tooltip not showing the correct thing. I am trying to get it to show the x-axis label for the hovered-over column, then a ":", then the value of the bar. The code is as follows:
$Colour = '#3465A4';
$BarChart= new bar();
$BarChart->set_values($Bar);
$BarChart->set_colour($Colour);
$BarChart->set_tooltip('#x_label#:#val#');
$x_labels = new x_axis_labels();
$x_labels->set_labels($Roles);
$x_labels->rotate(-60);
$x = new x_axis();
$x->set_labels($x_labels);
$chart = new open_flash_chart();
$chart->add_element($BarChart);
$chart->set_bg_colour( '#FFFFFF' );
$chart->set_x_axis($x);
$tooltip = new tooltip();
$tooltip->set_hover();
$chart->set_tooltip($tooltip);
$JSONArray['my_chart_1'] = $chart->toPrettyString();
As far as I can tell, this should be correct - the bar chart appears, with the correct values (populated from $bar, whose generation is not shown above). However, the hover-over tool-tip for a column only shows ":value" - the label name is missing!
Does anyone know where we might have gone wrong, and how I can fix it?
EDIT:
An update for any Bounty Hunters coming in to try and answer this question. The reason I have not accepted the below answer is that it only provides a work-around, and does not explain why the work-around is necessary. I am looking either for an answer to my original question (how to make the labels show in a normal bar-chart), or a reasonable explanation regarding why one must use a stacked bar chart (including sources makes your answer so much better!). If the latter, example code or an explanation of how stacked charts are created would be much appreciated as well!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对简单条形图的视觉效果感到满意,请使用堆叠条形图(将其与一个元素的数组一起使用将像简单条形图一样绘制它)。那个将正确替换#x_label#。
或者,您可以将缺少的代码从 Bars/Stack.as 复制到其他条形类型并重新编译代码。
If you are happy with the simple bar visuals then use stacked bar (using it with an array of one element will draw it just like the simple bar). That one will replace #x_label# correctly.
Alternatively you can copy the missing code from Bars/Stack.as to other bar types and recompile the code.
根据: http://forums.openflashchart.com/viewtopic.php?p=第7433章
这是最新版本 OFC2 中的一个错误(至少)。我已经找到了 #x_label# 问题的原因,但我对代码/Flash 的理解还不够好,无法知道为什么会发生/损坏。
我已经完成了一个快速修复,我需要进行更多测试,但它现在可以在条形图上运行。假设我没有破坏任何无法修复的东西,它将进入下一个社区版本。
如果有人希望在下一个版本之前更改源代码,请告诉我。
(我目前正在维护社区版本)
As per: http://forums.openflashchart.com/viewtopic.php?p=7433#p7433
It's a bug in OFC2 in the latest versions (at least). I've found what is causing the issue with #x_label#, but my understanding of the code/Flash isn't good enough to know why it's happened/broken.
I've done a quick fix that I need to test some more, but it now works on bar charts. Assuming I've not broken anything else beyond repair, it'll make it's way into the next community release.
If anyone wants the source code changes before the next release let me know.
(I am currently maintaining the community releases)