Eel icon indicating copy to clipboard operation
Eel copied to clipboard

Can i use eel with chartsjs

Open vikramsamak opened this issue 3 years ago • 4 comments

I m new in ds and i want to develop a Gui for ds app so can I use eel for modern UI based dashboards ? can is use eel to fetch data from python program and put it into chartjs ? Chartjs : https://www.chartjs.org/

vikramsamak avatar Sep 24 '22 15:09 vikramsamak

Yes you can.

netesy avatar Sep 30 '22 06:09 netesy

Hi netesy.

Yes you can.

But how could this be done? is there any example for this? Can I use eel with chartsjs?

ghost avatar Oct 09 '22 00:10 ghost

I will quickly share one when I am with my system.

netesy avatar Oct 11 '22 07:10 netesy

I will quickly share one when I am with my system.

Waiting sir ...

vikramsamak avatar Oct 19 '22 01:10 vikramsamak

I got a working chart days ago using python and eel, here are a few tips:

Add this to your html file, in the head tag:

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

Create a div to use as a container (might not be required afaik but useful for setting height and width) and create an element inside it with the canvas tag:

<div id="chart" style="width:400px; height:400px;"><canvas id="myChart"></canvas></div>

Function on your script.js file to add the chart details:

function createchart() {

data = {
    labels: [
      'Red',
      'Blue',
      'Yellow'
    ],
    datasets: [{
      label: 'My First Dataset',
      data: [300, 50, 100],
      backgroundColor: [
        'rgb(255, 99, 132)',
        'rgb(54, 162, 235)',
        'rgb(255, 205, 86)'
      ],
      hoverOffset: 4
    }]
  };
    config = {
    type: 'doughnut',
    data: data,
  };

  myChart = new Chart(document.getElementById('myChart'), config);
  
}

This creates a basic chart with predefined values. To get data from python you could use the following example:

on your python file:

@eel.expose	
def dashboard():

	result = [300, 50, 100]

	return (result)

On your script.js file:

async function createchart() {

  let result = await eel.dashboard()();
  console.log(result)
  data = {
      labels: [
        'Red',
        'Blue',
        'Yellow'
      ],
      datasets: [{
        label: 'My First Dataset',
        data: [result[0], result[1], result[2]],
        backgroundColor: [
          'rgb(255, 99, 132)',
          'rgb(54, 162, 235)',
          'rgb(255, 205, 86)'
        ],
        hoverOffset: 4
      }]
    };
      config = {
      type: 'doughnut',
      data: data,
    };
  
    myChart = new Chart(document.getElementById('myChart'), config);
    
}

1drg avatar Oct 21 '22 21:10 1drg

thank you so much sir...

vikramsamak avatar Oct 22 '22 11:10 vikramsamak

Hi all. Can someone help me? Why would someone help you? I'm trying to insert an example of chart js in the eel.

ghost avatar Dec 16 '22 15:12 ghost