Creating interactive Diagrams with eCharts

Creating interactive Diagrams with eCharts

LiaScript uses the powerful eCharts library to create interactive diagrams, whether you’re visualizing ASCII art or presenting data from tables. In our previous blog post, we introduced the <lia-chart> tag—a custom web component that uses eCharts under the hood to easily generate custom diagrams.

Creating interactive Diagrams with ChatGPT

Exploring AI-generated content opens the door to fascinating possibilities. In this article, we delve into how you can leverage AI models, like ChatGPT, to create interactive diagrams that can be customized on the fly. Prompt with Variables and Examples While ChatGPT might not be capable of independently generating complex scripts, it excels at modifying existing code snippets to meet your needs. Take, for example, a script from the LiaScript documentation, specifically from the section on Custom Diagrams with ECharts.

For more complex visualizations, you might want to go beyond the basic capabilities of the <lia-chart> tag and tap directly into the eCharts library, particularly when combined with “echarts-gl,” a WebGL extension for eCharts that enables even more advanced graphical features. This can be done directly within your script tags. Here’s how you can import the necessary libraries in your course setup:

<!--
script: https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js
        https://cdn.jsdelivr.net/npm/echarts-gl@2.0.9/dist/echarts-gl.min.js
-->

# Your Course

Examples

Below are some examples illustrating how to combine eCharts with LiaScript inputs. The process is similar to using the <lia-chart> tag, but with a few key differences. For instance, when working with eCharts directly, you’ll need to define additional functions that cannot be handled by the <lia-chart> tag alone. Additionally, you’ll need to create a <div> element in your document where the script will render the diagram.

The script functions silently in the background—it doesn’t produce visible output within the document itself but rather makes the necessary modifications to render the diagram. Whenever the input values associated with the script change, the main script is automatically re-executed, and the diagram updates in real-time.

Why is the script re-executed? This happens because of the @input(topic) markers. These markers “subscribe” to any changes in the scripts that define the specified topic as their output. When those scripts change, the main script is triggered again, ensuring your diagram remains up-to-date.





Learn More

To dive deeper into using the eCharts library directly and explore the comprehensive examples provided in the link below:

eCharts Examples

Now that you’re familiar with using ChatGPT to create interactive diagrams, you’re ready to take things to the next level. By combining LiaScript snippets with the more advanced examples from the eCharts library, you can create dynamic visualizations that bring your ideas to life. The possibilities are endless — start experimenting and visualize everything you can imagine!

Automate with Macros

To streamline your workflow, especially when working with repetitive eCharts diagrams, you can create custom macros. Here’s a quick example to demonstrate how you can use macros to simplify your coding process.

When incorporating code into a macro, the following syntax is recommended:

```language @macro(params)
console.log("The code block is passed as the last parameter")

   ...

```

This syntax is utilized in the examples below. The @echarts macro is defined in the document’s main header and is designed to accept two parameters. The first parameter is the background theme, which can be set to either light or dark. The second parameter is the code block that generates the diagram.

Rather than directly injecting LiaScript code, this macro uses a helper function @echarts_. It first calls the @uid macro to generate a unique ID, which is then assigned to the <div> element and used in the document.getElementById query. The macro then passes the background parameter and the code block, which is enclosed in triple backticks to denote a multi-line string. If you’re working with a single line of code, you can use single backticks to indicate the string, especially if it includes additional commas.



Your standard Markdown viewer will still highlight the code blocks as usual, but the LiaScript interpreter will go a step further by transforming them into fully interactive diagrams.

Related Posts

OE³R the next Generation of OER?

OER or in long Open Educational Resources is a “relatively” new and vaguely defined term. Wikipedia describes it as follows: Open educational resources (OER) are freely accessible, openly licensed text, media, and other digital assets that are useful for teaching, learning, and assessing as well as for research purposes… https://en.wikipedia.org/wiki/Open_educational_resources Thus, the ER defines any kind of Educational¹ content while the O points to an open licensing format. But the idea is actually not new at all, there have been attempts that predate the OER movement by nearly a century.

Read More

Embedding Multimedia and More

There are 4 ways in LiaScript to embed multimedia content: the classical way ![alt](image-url) sound ?[alt](sound-url) video !?[alt](video-url] for everything else ??[alt](url) You can use this this example as a basis for your own course by following this link … Or experiment with it in the LiveEditor below:

Read More

LiaScript: a domain-specific-language for interactive online courses

This is the first paper published about LiaScript, which was presented at the International Association for Development of the Information Society (IADIS) International Conference on e-Learning 2019 in Porto. It gives an overview of the language and its features, as well as the motivation behind its development. Abstract. LiaScript is an attempt to enable everyone to create free and interactive online courses, without the need of being an experienced programmer. Instead, it aims to bring both parties, software-and course-developers, closer together by introducing Open-Source techniques into the Open-courSe development process.

Read More