Code Monkey home page Code Monkey logo

echarts-satori's Introduction

Echarts Satori

A demo app implementing custom charts using ECharts, Satori and Next.js route handler

1st Part - Setup Project

  1. Setup Next.js.
  2. Install packages echarts and echarts-for-react.
  3. Create a component for Echarts that accepts an chartOptions prop.
  4. Setup the Echart in the page route.

2nd Part - Download Chart

  1. Create a route handler at api/chart/route.ts that returns an SVG string of the chart.
  2. Implement a Download component that performs a POST request using the chartOptions.
  3. Convert the SVG string to either an SVG URI or PNG URI based on the use case.

3rd Part - Download Custom Chart

  1. Setup Satori:
  • Install package satori and intl-segmenter-polyfill.
  • Extend the global window interface with __resource typings.d.ts.
  • Add the font file using by satori to the public directory.
  1. Creaye a reactToSVG function that converts a React component to an SVG string satori
  2. Add a React Template to customize the chart ChartTemplate.
  3. Pass the template to Satori using reactToSVG to generate an SVG string of the customized chart.
  4. Convert the SVG string to a data URI and download it.

4th Part - Improvement

  1. Instead of returning an SVG string from route handler, you can return a data URI directly so that we can skip one function call.

echarts-satori's People

Contributors

pixeledcode avatar

Stargazers

Arthur Sosnowski avatar Pushp Ratan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.