javascript - how to display chart data as html table chartjs - Stack Overflow

I would like to know how to view chart data as html table on button click in chartjs.I have implemente

I would like to know how to view chart data as html table on button click in chartjs. I have implemented the line chart using chartjs , xaxis represents the color yaxis represents votes and points

Working fiddle:/ I want to display chart as table

Color | # of Votes | # of Points
Red     12           7
Blue    19           11
... and so on
var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
        {
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
        },  
            {
                label: '# of Points',
                data: [7, 11, 5, 8, 3, 7],
                borderWidth: 1
            }
        ]
  },
  options: {
    scales: {
        yAxes: [{
        ticks: {
                    reverse: false
        }
      }]
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
//html
<body>
    <canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>

I would like to know how to view chart data as html table on button click in chartjs. I have implemented the line chart using chartjs , xaxis represents the color yaxis represents votes and points

Working fiddle:https://jsfiddle/miyavv/ehqrL20o/ I want to display chart as table

Color | # of Votes | # of Points
Red     12           7
Blue    19           11
... and so on
var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
        {
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
        },  
            {
                label: '# of Points',
                data: [7, 11, 5, 8, 3, 7],
                borderWidth: 1
            }
        ]
  },
  options: {
    scales: {
        yAxes: [{
        ticks: {
                    reverse: false
        }
      }]
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
//html
<body>
    <canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>

Share Improve this question edited Jan 15, 2020 at 15:15 Sen asked Jan 11, 2020 at 10:23 SenSen 7733 gold badges14 silver badges35 bronze badges 4
  • Unfortunately, your question is not clear, please provide more info or sandbox sample. – Alex Commented Jan 11, 2020 at 12:26
  • @Alex thanks for reply, I want to display chart data as html table, – Sen Commented Jan 13, 2020 at 1:53
  • @Alex I have updated my question and fiddle – Sen Commented Jan 15, 2020 at 15:16
  • What's the problem with @SciFiThief answer? what do you mean by "chart as table"?please draw your desired result and attach to question. could help to clarify exactly what do you intend – Alex Commented Jan 15, 2020 at 21:36
Add a ment  | 

1 Answer 1

Reset to default 1

You need to identify what in your chart data could be represented as columns and rows in the table. If you named your x-axis, you could represent the chart data like this:

Color | # of Votes | # of Points
Red     12           7
Blue    19           11
... and so on

Also, chart data can be represented as a crosstab which is a more direct representation (since datapoint lies where x and y intersects):

             | Red | Blue | ... and so on
# of Votes     12    19
# of Points    7     11

Here's the example of how you can convert the chart data to crosstab: https://jsfiddle/tara5/cjvuphkL/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745295570a4621119.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信