pChart 2.x 图表使用小数而不是整数绘制比例

发布于 2024-11-01 21:14:39 字数 342 浏览 8 评论 0原文

我正在处理包含访问次数的统计数据,pChart 上的比例显示小数而不是整数。

默认设置是使用类似于下面的分数创建比例:

0  0.2  0.4  0.6  0.8  1.0  1.2
|===
|========
|============================
|===
|===================

这不起作用,因为您不能访问某个网站 1.2 次。

我试图使用 "Mode"=>SCALE_MODE_MANUAL 参数仅使用整数(0、1、2 等)进行缩放,但失败了。

如何设置或强制 pChart 在轴上使用整数进行绘图?

I'm working on stats containing a number of visits and the scale on pChart is showing decimals instead of whole integers.

The default setting is creating scales with fractions similar to below:

0  0.2  0.4  0.6  0.8  1.0  1.2
|===
|========
|============================
|===
|===================

That doesn't work as you can't visit a site 1.2 times.

I was trying to make scale only with whole numbers (0, 1, 2 etc.) with "Mode"=>SCALE_MODE_MANUAL parameter but I failed.

How do I set or force pChart to plot using whole numbers on the axis?

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

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

发布评论

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

评论(3

薄荷→糖丶微凉 2024-11-08 21:14:39

您可能最好调整数据,而不是图表,因为即使比例显示为 1,您仍然会看到显示 1.2 的条形图。

如果您仍在尝试修复轴边界,则可以设置轴边界,然后使用最小 div 高度值,您可以更好地控制轴。

$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>16));
$myPicture->drawScale(array("MinDivHeight"=>50, "CycleBackground"=>TRUE,"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>30,"Pos"=>SCALE_POS_TOPBOTTOM,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries, "ScaleSpacing"=>100)); //

另一种稍微狡猾的方法是在调用drawScale函数之前创建一个包含整数的数据集,然后将其删除并添加实际数据。

You are possibly best to adjust your data, rather than your graph, as you will still see the bar chart showing 1.2, even if the scale says 1.

If you were still trying to fix the axis boundaries, you set the axis boundaries, and use the minimum div height value, you can have better control over your axis.

$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>16));
$myPicture->drawScale(array("MinDivHeight"=>50, "CycleBackground"=>TRUE,"DrawSubTicks"=>FALSE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>30,"Pos"=>SCALE_POS_TOPBOTTOM,"Mode"=>SCALE_MODE_MANUAL, "ManualScale"=>$AxisBoundaries, "ScaleSpacing"=>100)); //

Another, slightly dodgy way, is to create a dataset with whole numbers to before you call the drawScale function, then remove it, and add your actual data.

日久见人心 2024-11-08 21:14:39

为了实现这一目标,我做了几件事,首先我设置了一个带有最小值和最大值的固定比例。

$scaleConfig = array("Min"=>1,"Max"=>100); //set explicit scale size

然后,当我使用 drawScale() 方法时,我将 Factor 属性设置为 1:

$pImage->drawScale(array('Mode'=>SCALE_MODE_MANUAL,'Factors'=>array(1),'ManualScale'=>$scaleConfig,'DrawSubTicks' => false));

I did a couple of things to achieve this, first I set a fixed scale with a min and max.

$scaleConfig = array("Min"=>1,"Max"=>100); //set explicit scale size

And then when I use the drawScale() method I set the Factor property to 1:

$pImage->drawScale(array('Mode'=>SCALE_MODE_MANUAL,'Factors'=>array(1),'ManualScale'=>$scaleConfig,'DrawSubTicks' => false));
喜你已久 2024-11-08 21:14:39

如果您设置“因素”=>; array(10000) 在drawScale 函数中,pChart 显示整数(1, 2)。我自己找到了解决方案。

if you set "Factors" => array(10000) in drawScale function the pChart is showing intergers(1, 2). I found the solution myself.

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