1

Embedded eCharts into Ninox

I have tried to embed eCharts into Ninox but have yet to succeed. 

For example, I put the following code inside a function field, but nothing:

var _style := "* {
  margin: 0;
  padding: 0;
}
#chart-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
}";
var _code := http("GET", "https://fastly.jsdelivr.net/npm/echarts@5/dist/echarts.min.js");
var _localScript := "var dom = document.getElementById('chart-container');
var myChart = echarts.init(dom, null, {
  renderer: 'canvas',
  useDirtyRect: false
});
var app = {};  var option;  option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    }
  ]
};  if (option && typeof option === 'object') {
  myChart.setOption(option);
}  window.addEventListener('resize', myChart.resize);";
var _html := ---
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Basic Line Chart - Apache ECharts Demo</title>
  <style>{ _style }</style>
</head>
<body>
  <div id="chart-container"></div>
  <script>{ _code } { _localScript }</script>
</body>
</html>

 

Is this due to the restrictions that Ninox places on Javascript?

   in a previous post, you mention eCharts. How do you manage to make it work?

15 replies

null
    • m_daaboul
    • 6 mths ago
    • Reported - view

    Hey Sotirios,
    Here is a working example that you can adapt to your app.

    function loadeCharts() do
        "<script src='https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js'></script>"
    end;
    function renderEChart(chartId : text,options : text) do
        loadeCharts() + "<div id='" + chartId +
        "' class='echart-graph' style='width: 100%;height:100%;'></div>
        <script type='text/javascript'>
          setTimeout(function(){
            echarts.registerTheme('customed', {});
            var myChart = echarts.init(document.getElementById('" +
        chartId +
        "'),'customed');
            myChart.setOption(" +
        options +
        ");
          },100);
        </script>"
    end;
    let chartOptions := {
            grid: {
                top: "10%",
                bottom: "10%"
            },
            xAxis: {
                type: "category",
                data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
            },
            yAxis: {
                type: "value"
            },
            series: [{
                    data: [150, 230, 224, 218, 135, 147, 260],
                    type: "line"
                }]
        };
    html(renderEChart("_cid_" + random(), text(chartOptions)))

    Hints : 
    - Make sure you wait a few milliseconds before starting the render process (until ninox finishes rendering the views). by trial and error, 100 ms seems tenough.
    - Set a unique id for each graph on your dashboard ( we got plenty of these graphs in each view)
    - Ideally, load the echarts library from your own database through a shared link. your browser will cache the library upon refresh and for security reasons it's always better.
    - Isolate the options object outside the rendering function so that you can use it later on with the dynamic print engine. It's the same format.

    Enjoy !

      • Rafael Sanchis
      • Rafael_Sanchis
      • 6 mths ago
      • Reported - view

       

      Hi I would like some help, I have this curve in Ninox, horrible, the yellow curve represents the financial curve of the project (Total Earned Plan) the blue curve represents the (Total Earned Value) at the Cut-Off Date in this example 12/Apr/2024 and the Green curve represents the accumulated cost also as of the Cutoff Date.  These last two curves should not be seen beyond April 12, 2024. Is there any option to have an example like the previous one for 3 curves?  I would appreciate your help.

      • m_daaboul
      • 6 mths ago
      • Reported - view

      Hey Raphael, the example in this thread is an eCharts example. You could achieve this i guess. Look at https://echarts.apache.org/examples/en/index.html , you got an emulator on the left which allows you to test your data. From what you're saying, i'd go for this example https://echarts.apache.org/examples/en/editor.html?c=area-stack and get it integrated into your code using the above code. Wish echarts becomes more native in ninox as it's the same library used by the dynamic rendering engine.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 6 mths ago
      • Reported - view

       Thanks I will try 👍

      • Rafael Sanchis
      • Rafael_Sanchis
      • 6 mths ago
      • Reported - view

       

      Hi again. 

      1. Legend don't display three data: data: ["Planned Value", "Earned Value", "Cumulative Cost"]

      2. The values green and yellow do not correspond to the values entered.

      some idea

      function loadeCharts() do
          "<script src='https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js'></script>"
      end;
      function renderEChart(chartId : text,options : text) do
          loadeCharts() + "<div id='" + chartId +
          "' class='echart-graph' style='width: 100%;height:100%;'></div>
          <script type='text/javascript'>
            setTimeout(function(){
              echarts.registerTheme('customed', {});
              var myChart = echarts.init(document.getElementById('" +
          chartId +
          "'),'customed');
              myChart.setOption(" +
          options +
          ");
            },100);
          </script>"
      end;
      let chartOptions := {
              title: {
                  text: "Financial Progress Curve Data|Date 30/April/2024"
              },
              tooltip: {
                  trigger: "axis"
              },
              legend: {
                  data: ["Planned Value", "Earned Value", "Cumulative Cost"]
              },
              grid: {
                  left: "3%",
                  right: "4%",
                  bottom: "3%",
                  containLabel: true
              },
              toolbox: {
                  feature: {
                      saveAsImage: {}
                  }
              },
              xAxis: {
                  type: "category",
                  boundaryGap: false,
                  data: ["Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct"]
              },
              yAxis: {
                  type: "value"
              },
              series: [{
                      name: "Total Planed Value",
                      type: "line",
                      stack: "Total",
                      data: [0, 120000, 212000, 390000, 520000, 680000, 860000, 921000, 950000]
                  }, {
                      name: "Total Earned Value",
                      type: "line",
                      stack: "Total",
                      data: [0, 90000, 115670]
                  }, {
                      name: "Cumulative Cost",
                      type: "line",
                      stack: "Total",
                      data: [0, 110000, 123200]
                  }]
          };
      html(renderEChart("_cid_" + random(), text(chartOptions)))
      
      • m_daaboul
      • 6 mths ago
      • Reported - view

      Hi Rafael, the names you're using in the legend should be exactly the same ones in the series name field. so

      legend: {
                  data: ["Total Planed Value", "Total Earned Value", "Cumulative Cost"]
              },
      • Rafael Sanchis
      • Rafael_Sanchis
      • 6 mths ago
      • Reported - view

       Thanks again Daaboul, now works great. Appreciate your post

    • szormpas
    • 6 mths ago
    • Reported - view

     thank you, your code example works nice and your hints are very helpful!

    • Nick
    • 6 mths ago
    • Reported - view

    Hello everyone,
    with your help I have made a small template with two graphs taking data from a table. 
    One pie type chart and one bar chart.

    I hope it will be useful

    Nikos

      • szormpas
      • 6 mths ago
      • Reported - view

          Hello Nikos, thank you for helping us improve our understanding of how to present our data.

      • m_daaboul
      • 6 mths ago
      • Reported - view

      another hint > try to load the echarts library only once in the view in a separate fx. also try to find a way to put all the charts in one big fx that will handle responsiveness. something like purejs worked for us. enjoy.

      • szormpas
      • 6 mths ago
      • Reported - view

         thanks again, your advice has helped us a lot to get familiar with the use of eCharts library. If you have some time could you explain what you mean by "- Ideally, load the echarts library from your own database through a shared link...."

      • Rafael Sanchis
      • Rafael_Sanchis
      • 6 mths ago
      • Reported - view

       

      Hi Sotirios some time the first graph don't display when open the table need  click on the key and display the graph, then always display the graph although change the tables

      • m_daaboul
      • 6 mths ago
      • Reported - view

      probably you're loading the library twice, and one of the two calls got blocked by CDN during loading. try to load the library in a separate fx, once. we haven't faced this particular issue in a much dense 20 charts dashboard.

    • Rafael Sanchis
    • Rafael_Sanchis
    • 5 mths ago
    • Reported - view

Content aside

  • Status Answered
  • 1 Likes
  • 5 mths agoLast active
  • 15Replies
  • 263Views
  • 5 Following