Prompt Title: Google charts

Created 1 year ago
Votes 0
Views 163 times
IT
0

Prompt Detail:

To install Google Charts via NPM (Node Package Manager), follow these steps:

  1. Open your terminal and navigate to the root directory of your project.

  2. Type the following command to install the google-charts package:

    npm install google-charts
  3. Wait for the installation process to complete. NPM will download and install the google-charts package along with its dependencies.

  4. Once the installation is complete, you can use the google-charts package in your JavaScript code.

Here's an example of how to use google-charts to create a simple pie chart:

javascript
const { google } = require('google-charts'); google.charts.load('current', { 'packages': ['corechart'] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { const data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day'], ['Work', 8], ['Sleep', 8], ['Play', 8], ]); const options = { title: 'My Daily Activities', }; const chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); }

Note that you'll need to include the google-charts package in your HTML file and add a div element with the id of piechart for the chart to be rendered:

html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Google Charts Example</title> <script src="https://www.gstatic.com/charts/loader.js"></script> </head> <body> <div id="piechart"></div> <script src="index.js"></script> </body> </html>
avatar
acx
Shared 1 prompt
Created 1 year ago

Leave a Comment