# echart-by-java **Repository Path**: as4535/echart-by-java ## Basic Information - **Project Name**: echart-by-java - **Description**: 用java8在服务端渲染echarts。 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-18 - **Last Updated**: 2025-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ECharts Java Pure Java implementation of [Apache ECharts](https://echarts.apache.org/) for server-side SVG generation. ## Overview ECharts-by-java is a library that allows you to generate SVG charts on the server side using a Java API compatible with the ECharts configuration options. This project aims to provide a solution for scenarios where you need to generate charts without a browser or JavaScript environment, such as: - Server-side report generation - Email attachments with charts - Static chart generation in backend applications - PDF report generation with embedded charts ## Features - Pure Java implementation, no JavaScript or browser dependencies - API compatible with ECharts option configuration - SVG output format (with potential for PNG, PDF extensions) - Fluent API design for easy chart creation - Support for common chart types: bar, line, pie, scatter, etc. ## Project Structure The project is organized into several Maven modules: - **echarts-common**: Common utilities and helper classes - **echarts-option**: Configuration options compatible with ECharts - **echarts-render**: Rendering implementation with a logical coordinate system (left-bottom origin) - **echarts-model**: Entity model and data computation - **echarts-coordinator**: Coordinates the rendering process between model and render modules - **echarts-app**: Main entry point and API ## Architecture The architecture follows a clean separation of concerns: 1. **Model Layer**: Provides complete and rigorous configuration information, including default settings, styles, and themes. 2. **Render Layer**: Focuses solely on drawing graphics using a logical coordinate system with the origin (0,0) at the bottom-left corner. 3. **Coordinator Layer**: Bridges the gap between model data and rendering operations, handling transformations and coordinating the rendering process. This design ensures a clean separation between data management and rendering concerns, making the code more maintainable and flexible. ## Quick Start ### Maven Dependency ```xml io.github.echarts echarts-app 1.0.0-SNAPSHOT ``` ### Creating a Simple Bar Chart ```java import io.github.echarts.app.Chart; public class ChartExample { public static void main(String[] args) { // Create a new chart instance Chart chart = new Chart(600, 400); // Configure the chart EChartOption option = new EChartOption(); // Add title Title title = new Title(); title.setText("Sales Statistics"); option.setTitle(title); // Add bar series BarSeries barSeries = new BarSeries(); barSeries.setName("Sales"); barSeries.setData(new Number[]{5, 20, 36, 10, 15}); option.setSeries(new BarSeries[]{barSeries}); // Set the option chart.setOption(option); // Render to SVG String svg = chart.renderToSVG(); System.out.println(svg); // Or save to file // Files.write(Paths.get("chart.svg"), svg.getBytes(StandardCharsets.UTF_8)); } } ``` ### Custom Chart Configuration ```java import io.github.echarts.app.Chart; import io.github.echarts.option.EChartOption; import io.github.echarts.option.component.Grid; import io.github.echarts.option.component.Title; import io.github.echarts.option.series.BarSeries; public class CustomChartExample { public static void main(String[] args) { Chart chart = new Chart(800, 600); // Configure using the option API EChartOption option = new EChartOption(); // Add title Title title = new Title(); title.setText("Custom Chart"); title.setSubtext("With detailed configuration"); option.setTitle(title); // Configure grid Grid grid = new Grid(); grid.setLeft("10%"); grid.setRight("10%"); grid.setBottom("15%"); option.setGrid(grid); // Add bar series BarSeries barSeries = new BarSeries(); barSeries.setName("Data"); barSeries.setData(new Number[]{10, 20, 30, 40, 50}); option.setSeries(new BarSeries[]{barSeries}); // Set the option chart.setOption(option); // Output SVG String svg = chart.renderToSVG(); System.out.println(svg); } } ``` ## Current Status This project is under active development. Current implementation focuses on SVG generation for common chart types. ## License This project is licensed under the Apache License 2.0.