0

how can i use data with sql database in zkchart?

asked 2021-11-25 22:18:24 +0800

kurosabama gravatar image kurosabama
1

updated 2021-11-29 17:32:57 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

am trying to use zkchart for my next project, i understand how i to choose the model of chart of type etc

but every example take data from hardcode line like this:

{
public class LineBasicData {private static final CategoryModel model;

static 

{       model = new DefaultCategoryModel();
        model.setValue("Tokyo", "Jan", 7);
        model.setValue("Tokyo", "Feb", 6);
        model.setValue("Tokyo", "Mar", 9);
        model.setValue("Tokyo", "Apr", 14);
        model.setValue("Tokyo", "May", 18);
        model.setValue("Tokyo", "Jun", 21);
        model.setValue("Tokyo", "Jul", 25);
        model.setValue("Tokyo", "Aug", 26);
        model.setValue("Tokyo", "Sep", 23);
        model.setValue("Tokyo", "Oct", 18);
        model.setValue("Tokyo", "Nov", 13);
        model.setValue("Tokyo", "Dec", 9);

    }

    public static CategoryModel getCategoryModel() {
        return model;
    }
}}

any idea how can i fill that line from my database? is arraylist method is doable in here? sorry, am so newb in java

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-29 17:57:55 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

Since zkchart is also a component of ZK framework, it's better you should learn some basic of ZK via https://www.zkoss.org/documentation#Getting_Started including MVC, and event listening.

Basically, what you need to do are in MVC patter: 1. apply a controller(composer) in a zul 2. query data from a database and put it in a model in doAfterCompose() 3. assign the model object to Charts

public class MyComposer extends SelectorComposer<Component> {

    @Wire
    Charts chart;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        initData();
    }

    private void initData() {
        //query data from a database
        //set data to a model object
        //chart.setModel(model)
    }
}

ZK is a UI framework, so that you have to integrate other frameworks or library by yourselves. You can also check architecture of this example project: https://github.com/zkoss/zkessentials/tree/zk-jpa

If you still have problems, please post your code here.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2021-11-25 22:18:24 +0800

Seen: 4 times

Last updated: Nov 29 '21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More