假设我有 N 个段,每个段都有一个开始值和一个结束值,例如:
[1,40],[40,80],[80,100],[90,110]
我想创建一个图表,可以在其中显示所有段,这样我就可以看到第四段与值重叠第三个。
我是图表新手,您能建议我可以使用哪种图表类型来解决此类“问题”吗?另外,如果您能够推荐一个支持该类型图表的库,那就太好了。我可以使用以下任何一种:Java、Ruby、Python、Perl、.NET。生成此类图表的应用程序将在 Windows 计算机上运行。
谢谢!
Suppose I have N segments, each one having a start and a end value, for example:
[1,40],[40,80],[80,100],[90,110]
I'd like to create a chart where I can display all of them, in such a way that I can see that the fourth segment overlaps the values of the third one.
I'm new to charting, can you suggest which chart type I could use for this kind of "problem"? Also, if you'd be able to suggest a library which supports that type of chart, that would be great. I can use any of : Java,Ruby,Python,Perl,.NET. The app that will generate this kind of chart will be ran on a Windows computer.
Thanks!
发布评论
评论(8)
您可以实现类似 matplotlib 如下:
c/2298314#2298314">Xinxua 在 python 中的答案 , 你
You can implement something like Xinxua's answer in python using matplotlib like this:
Which would give you
恕我直言,我建议您使用简单的条形图,使用伟大的 Google 条形图 API。例如,对于你的问题中提供的数据,我会做一个像这样的网址
......谷歌会返回给我一个像这样的图表。
如您所见,这是一个简单的 GET 请求。现在,他们也支持 POST 请求。
事实上,我建议您在 中进行简单搜索Google 的图表库。即使您不打算使用它,至少您的项目也会有一些非常好的示例。
(这种方法的明显缺点是需要互联网连接。但条形图推荐仍然有用。)
IMHO, I would suggest you to just use a simple Bar Chart, using the great Google Bar Charts API. For example, for the data provided in in your question I would do a url like this
...and google would return me a Chart like this.
As you can see, it's a simple GET request. And now they're supporting POST requests too.
In fact, I recommend you to do a simple search in Google's Chart Gallery. Even if you're not going to use it, at least you're going to have some really good examples for your project.
(The obvious disadvantage of this approach is the need of an internet connection. But the Bar Chart recommendation is still useful.)
使用 Google Charts API 创建像这样的堆积条形图:
将第一个系列设置为白色,这样它就不会显示。 (我使用浅绿色来展示它的工作原理;将上面 URL 中的
eeffee
更改为ffffff
以使其变为白色。)请注意,您需要计算您的实际数据,例如对于条目 [80,100],您需要使用 20 作为宽度,如上面 URL 中突出显示的那样。
Use Google Charts API to create a stacked bar chart like this:
Make the first series white so it doesn't show. (I used light-green to show how it works; change
eeffee
toffffff
in the URL above to make it white.)Note that you will need to calculate the widths of your actual data, e.g. for the entry [80,100] you will need to use 20 as the width, as highlighted in the URL above.
我能想到的图表类型如下。也许这是一个时间表。 (或甘特图)
(抱歉我有点茫然)。可能其他人会提出图表 api。 :D
I can think of the type of the chart, as below. Maybe its a timeline. (Or Gantt Chart)
(Sorry I am kinda dazed). Probably somebody else will come up with the chart api. :D
也许您想要更多的修饰,以下内容基本上可以满足您的需要:
在您的示例中,我只是使用每个数字对作为每个项目的开始、结束时间。
如果它们只是数字也没关系...参见莫奈示例...它使用一些事件开始/结束时间作为简单的数字(即:1845 和 1846)。
使用它来跟踪“事件”的生命周期或检查门票对于了解正在发生的事情非常有用。
Perhaps more polish that you want, the following will do basicaly what you need:
In your example, I'd just use each number pair as the start,end time of each item.
It's ok if they are just numbers... see the monet example... it uses some event start/end times as simple numbers (ie: 1845 and 1846).
Using this to track lifespan of 'events' or check tickets can be very useful for seeing what is going on.
您可以在此处使用支持起始值的柱形图,例如 amCharts 或者您可以使用蜡烛图,开盘价/最高价设置为相同的第一个值,收盘价/最低价设置为第二个值。
You can use a column chart that supports start value here like amCharts or you can use a candlestick chart with open/high set to the same first value and close/low to the second.
如果您要使用 .net,您可以尝试 Infragistics 控件。如果您使用的是 WPF 或 Silverlight 并且想要免费的东西,您可以尝试 WPF Toolkit 或 < a href="http://visifire.com/" rel="nofollow noreferrer">Visifire。
If you will be working with .net you can try Infragistics controls. If you are in WPF or Silverlight and want something free you can try WPF Toolkit or Visifire.
http://pchart.sourceforge.net/
PChart for PHP 是一个非常好的图表库,他们还有一个内容丰富的教程
http://pchart.sourceforge.net/
PChart for PHP is a really nice Charting Library they have an informative tutorial as well