馅饼太小了 [英] Pie Piece Too Small

查看:91
本文介绍了馅饼太小了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态数据数组,其中包含3个用于构建饼图的整数。在大多数情况下,IE浏览器工作正常:[5,10,3]。饼图呈现正确,你看到所有的作品。



然而在某些情况下,这些数字可能会有很大的不同。 IE [1,500,250]或[400,1,2]。在这种情况下,你只会看到较大的馅饼,而较小的馅饼变得如此之小以至于看不见;或点击。



我需要一些方法来纠正这些情况下的数据数组。我有能力在调整显示值的同时保留真实值,以便显示各个部分。我正在寻找的是一个检查,看看是否有必要,然后根据其他值调整它的相对数。



建议?

$首先,我会说你并没有像对数据进行纠正,而是为了满足你的要求而伪造数据。

基本上,这个比例的一小部分是可以点击的最低百分比,您需要将所有部分至少放到这个大小。



当然 - 这不适用于最极端的例子。如果你有1,000,000个切片都具有相同的价值,那么无论你如何缩放它们,其中一些将会太小(或全部)。



你还需要意识到如何缩放某些非常小的切片会抛出其他较大切片之间的明显比例。然而,一种非常粗糙的做法可能会...

  var minPC = 0.5,//可见的最小%时间片
total; // total应设置为所有切片的值的总和

var minValue = total / 100 * minPC; //可见的最小值(给出当前总数)

(片段中的切片){//假设切片是标准的JS'数组'
if(slices [slice]< ; minValue)slices [slice] = minValue;
}

当然会使切片变大,这样会增加总数 - 意义小片仍然小于最小可见百分比。您需要使 minPC 足够大以应对此问题。当然,越小的切片越有利于这种效果。您可以解释这是重新缩放更大的切片。然而,我建议您找到一种更好的方式让用户选择与用户交互的数据/关闭切片 - 或切片爆炸。


I have a dynamic data array that contains 3 ints that are used to build a pie chart. In most cases it works fine IE: [5, 10, 3]. The pie chart renders correctly and you see all the pieces.

However in some cases the numbers can be widely different. IE [1,500,250] or [400,1,2]. When this is the case you will only see the larger of the pie pieces and the smaller ones become so small they can not be seen; or clicked.

I need some way of correcting the data array for these cases. I have the ability to retain the true value while adjusting the display value so the pieces show up. What I am looking for is a check to see if it's necessary and then a relative number to adjust it by based on the other values.

Suggestions?

解决方案

Well firstly I'd say you aren't so much "correcting" the data as fudging the data to meet your requirements.

Basically, there is a minimum percentage for which a slice of that proportion will be clickable and you will need to bring all pieces up to at least this size.

Of course - this can't work at the most extreme examples. If you had 1,000,000 slices all of the same value then no matter how you scaled them, some of them are going to be too small (or all of them).

You also need to be aware of how scaling certain very small slices will throw out the apparent proportions between other, larger, slices.

But - a very crude way of doing it could be something like...

var minPC = 0.5 ,    // the minimum %age slice visible
    total;         // total should be set to the sum of the values of all your slices

var minValue = total / 100 * minPC; // The smallest value visible (given the current total)

for (var slice in slices) { //assuming slices is a standard JS 'array'
   if ( slices[slice] < minValue ) slices[slice] = minValue;
}

of course making the slices bigger like this will in turn increase the total - meaning that the small slices will still be less than the minimum visible percentage. You will need to make minPC sufficiently large to cope with this. And of course the more very small slices you have the worse this effect will be. You could account for this be re-scaling the larger slices.

However - I would advise you find a better way of the user interacting with the data by letting them select on/off slices - or by having slices 'explode'.

这篇关于馅饼太小了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆