How can I make a bar chart (bar graph) in Prolog GUI (XPCE) programming?

纵饮孤独 提交于 2019-12-24 17:09:58

问题


I'm trying to make a barchart by using XPCE in Proglog libraries. Though I found some materials but I cannot execute it right away. The code is as below.

barchart :-
    barchart(vertical).
barchart(HV) :-
    new(W, picture),
    active_classes(Classes),
    length(Classes, N),
    required_scale(Classes, Scale),
    send(W, display, new(BC, bar_chart(HV, 0, Scale, 200, N))),
    forall(member(class(Name, Created, Freed), Classes),
           send(BC, append,
                bar_group(Name,
                          bar(created, Created, green),
                          bar(freed, Freed, red)))),
    send(W, open).

And what I want to make is like Figure27 in this site.

http://www.swi-prolog.org/packages/xpce/UserGuide/libplot.html

Edited)

I just want to make very simple bar chart. Like this below. http://image.tutorvista.com/content/feed/u845/bargraph.gif

sorry for link not image(I don't have enough reputation points to upload the picture)


回答1:


here (another) sample

:- use_module(library(pce)).
:- use_module(library(plot/barchart)).
:- use_module(library(autowin)).

test_barchart :-
    new(W, picture),
    send(W, display, new(BC, bar_chart(vertical,0,200))),
    forall(member(Name/Height/Color,
              [x/100/red, y/150/green, z/80/blue, v/50/yellow]),
           (   new(B, bar(Name, Height)),
               send(B, colour(Color)),
               send(BC, append, B)
           )),
    send(W, open).

that yields

You can inspect XPCE objects from Help\XPCE Manual\Browsers\Class Browser...



来源:https://stackoverflow.com/questions/20349862/how-can-i-make-a-bar-chart-bar-graph-in-prolog-gui-xpce-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!