Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any solution we can integrate Apache Echarts in gollum wiki? #2036

Open
klion26 opened this issue Apr 14, 2024 · 4 comments
Open

Is there any solution we can integrate Apache Echarts in gollum wiki? #2036

klion26 opened this issue Apr 14, 2024 · 4 comments

Comments

@klion26
Copy link

klion26 commented Apr 14, 2024

Hi, is there any solution that we can integrate Apache Echarts in gollum wiki, thanks. Did some search but didn't find the solution.

@dometto
Copy link
Member

dometto commented Apr 14, 2024

Hi there! There is at present no readymade solution for doing this. However, you could try using a custom JS file (using the --js command line switch) and including Echarts with something like:

var jQueryScript = document.createElement('script');  
jQueryScript.setAttribute('src','https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js');
document.head.appendChild(jQueryScript);

Echarts looks like a great project that we could try to support officially, so please let me know if you manage to get it running in a basic way with the above, and how you think a supported Echarts feature in gollum should look! (For example, what syntax should be used by the user to define a chart?)

@klion26
Copy link
Author

klion26 commented Apr 15, 2024

@dometto thanks for the reply, will try the given solution.

For the official support, maybe writing the code like the js code here in the gollum editor is fine to me.

@klion26
Copy link
Author

klion26 commented Apr 21, 2024

@dometto I've tried to add a custom.js file as below, and start by the command[1], but the content didn't show any echarts chart, the rendered HTML source of the wiki page has been attached below[2], I manually wrote a single HTML page with the code[3], showing the rendered echarts chart. Could you please give some hints on how to make it work, thanks.

Tried adding the HTML code in the wiki content from the web editor, but it didn't work either.

var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('src','https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js');

<div id="main" style="width: 600px;height:400px;"></div>
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
var option = {
    title: {
      text: 'ECharts 入门示例'
    },
    tooltip: {},
    legend: {
       data: ['销量']
    },
    xAxis: {
       data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {},
    series: [
      {
         name: '销量',
         type: 'bar',
         data: [5, 20, 36, 10, 10, 20]
      }
    ]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);

document.head.appendChild(jQueryScript);

[1] docker run --rm -p 4567:4567 -v /path/to/wiki:/wiki gollumwiki/gollum:master --mathjax --h1-title --js
[2] todo_html.txt
[3]
test_echarts_html.txt

@klion26
Copy link
Author

klion26 commented Jun 29, 2024

@dometto update some status here, currently, I can get the result of apache echarts in gollum wiki after the following steps:

  1. add custom.js
document.write('<script  src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>');


document.addEventListener('DOMContentLoaded', function() {
  // Initialize ECharts
  var myChart = echarts.init(document.getElementById('echarts-container'));

  // ECharts configuration and data
  var option = {
    // Your ECharts configuration here
    title: {
          text: 'ECharts Getting Started Example'
    },
    tooltip: {},
    legend: {
       data: ['sales']
    },
    xAxis: {
       data: ['Shirts', 'Cardigans', 'Chiffons', 'Pants', 'Heels', 'Socks']
    },
    yAxis: {},
    series: [
       {
          name: 'sales',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
       }
    ]
  };

  // Render the chart
  myChart.setOption(option);
});
  1. start gollumn wiki with the -js enabled docker run --rm -p 4567:4567 -v /path/to/wiki-path:/wiki gollumwiki/gollum:master --mathjax --h1-title --js
  2. add <div id="echarts-container" style="width: 600px; height: 400px;"></div> in the documentation.
  3. save the documentation, then can get the result, I can see the chart in the wiki. (but the chart did not show in the preview mode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants