Oreshkovski
Oreshkovski

Reputation: 69

How to show c3.js data in table

I have c3.js chart and everything is working fine. The code of the chart.

adminChart = c3.generate({
        bindto: '#admin-chart',
        data: {
            columns: [
                ['data1', 300, 350, 300, 0, 0, 0],
                ['data2', 130, 100, 140, 200, 150, 50]
            ],
            types: {
                data1: 'area',
                data2: 'area-spline'
            }
        }
    });

Now i need to bind the data into a table. Is there any way to use c3.js to put the data into a table or I need to use javascript or jquery to do that?

Upvotes: 1

Views: 727

Answers (1)

Stephen Montana
Stephen Montana

Reputation: 41

ANSWER: Build a constructor function that normalizes the data based on your table schema and insert the data into your database using an ORM (Object Relationship Mapper). If you are using MySQL, I would suggest using Sequelize as your ORM. If you are using PostGres, I would suggest using MonGoose as your ORM.

To Elaborate: If you are trying to take the data from the chart and insert it into a database table, then you should build some sort of constructor function that grabs the data and normalizes it based on your table schema. Then, feed the normalized data to an ORM method to Insert or Update your database table.

Normally, you would do it the other way around, i.e., pull the data from your database to populate the chart. So the fact that you are wanting to do the opposite leads me to believe that you are having users enter data somewhere on the page and then you are grabbing those inputs for use with the chart.

If my assumption is correct, I would suggest feeding the user inputs to the database first (using the ORM) and then retrieving the data you want to use for the chart (again, using the ORM).

I hope this adequately answered your question.

Upvotes: 1

Related Questions