Blazor.ECharts

repository·master·Indexed 41 days ago

https://github.com/lishewen/blazor.echarts

A Blazor component wrapper for the Apache ECharts library that enables the creation of rich, interactive charts within Blazor applications using C#. Includes support for the echarts-wordcloud library via Blazor.ECharts.WordCloud and provides a JFunc object to pass JavaScript functions in ECharts options.

Tokens
2.6K
Snippets
13
Records
13
Agent score
99%

What's inside Blazor.ECharts

  1. Use Open Iconic SVG Sprites

    master

    The SVG sprite allows you to load all icons in a single request. To use an icon, use an <svg> tag with a <use> element pointing to the sprite ID.

    Styling Tips:

    • Sizing: Set equal width and height on the <svg> tag.
    • Coloring: Use the CSS fill property on the <use> tag.
    • Best Practice: Add a general class to the <svg> tag and a unique class to the <use> tag for easier styling.
    <svg class="icon">
      <use xlink:href="open-iconic.svg#account-login" class="icon-account-login"></use>
    </svg>
    
    <style>
    .icon {
      width: 16px;
      height: 16px;
    }
    
    .icon-account-login {
      fill: #f00;
    }
    </style>
  2. Use Open Iconic's SVG Sprite

    master

    Open Iconic provides an SVG sprite that allows you to load all icons in a single request. To use it, embed an <svg> tag containing a <use> element that references the specific icon ID within the sprite file.

    Styling

    • Sizing: Set equal width and height on the <svg> tag.
    • Coloring: Use the CSS fill property on the <use> tag to change the icon color.

    Tip: Add a general class to the <svg> tag for shared styles and a unique class to the <use> tag for icon-specific styling.

    <svg class="icon">
      <use xlink:href="open-iconic.svg#account-login" class="icon-account-login"></use>
    </svg>
    /* Sizing */
    .icon {
      width: 16px;
      height: 16px;
    }
    
    /* Coloring */
    .icon-account-login {
      fill: #f00;
    }
  3. Use Open Iconic Icon Fonts

    master

    Open Iconic can be used as an icon font via CSS stylesheets. Depending on your framework, you should link to the appropriate stylesheet and use the corresponding HTML structure.

    With Bootstrap

    1. Link the Bootstrap-specific stylesheet: /open-iconic/font/css/open-iconic-bootstrap.css
    2. Use the oi oi-icon-name class pattern.

    With Foundation

    1. Link the Foundation-specific stylesheet: /open-iconic/font/css/open-iconic-foundation.css
    2. Use the fi-icon-name class pattern.

    Standalone (Default)

    1. Link the default stylesheet: /open-iconic/font/css/open-iconic.css
    2. Use the oi class and the data-glyph attribute.
    <!-- Bootstrap -->
    <link href="/open-iconic/font/css/open-iconic-bootstrap.css" rel="stylesheet">
    <span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span>
    
    <!-- Foundation -->
    <link href="/open-iconic/font/css/open-iconic-foundation.css" rel="stylesheet">
    <span class="fi-icon-name" title="icon name" aria-hidden="true"></span>
    
    <!-- Standalone -->
    <link href="/open-iconic/font/css/open-iconic.css" rel="stylesheet">
    <span class="oi" data-glyph="icon-name" title="icon name" aria-hidden="true"></span>
  4. Install and Setup Blazor.ECharts

    master

    To use Blazor.ECharts in your Blazor project, follow these steps:

    1. Install the NuGet package: Search for and install Blazor.ECharts.
    2. Add Namespace: In your _Imports.razor file, add: @using Blazor.ECharts.Components
    3. Register Services: In Program.cs, add the ECharts service to the builder: builder.Services.AddECharts();
    4. Include ECharts Library: In wwwroot/index.html, add the ECharts script to the <head> section. You can use a CDN like Baomitu: <script src="https://lib.baomitu.com/echarts/5.6.0/echarts.min.js"></script>
    5. Include Library Core: In wwwroot/index.html, add the library's core JS module to the <body> section: <script type="module" src="_content/Blazor.ECharts/core.js"></script>

    Note on Sizing: The components do not have default styles. You must set a Class or Style attribute on the component to control its width and height.

    // Program.cs
    builder.Services.AddECharts();
    <!-- wwwroot/index.html (Head) -->
    <script src="https://lib.baomitu.com/echarts/5.6.0/echarts.min.js"></script>
    
    <!-- wwwroot/index.html (Body) -->
    <script type="module" src="_content/Blazor.ECharts/core.js"></script>
  5. Configure Map Features

    master

    If you intend to use map-related features (such as Baidu Maps integration), you must manually add the necessary map JS references to the <head> of your wwwroot/index.html file. This typically includes the Baidu Map API and the ECharts BMap extension.

    <!-- Add to <head> in wwwroot/index.html -->
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=[Your Key Here]"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/extension/bmap.min.js"></script>
  6. Recommended CSS for Chart Containers

    master

    Since components require explicit dimensions, use CSS to manage layouts. The following examples demonstrate how to create a flexible container and specific chart sizes as seen in the project demos.

    /* Container for multiple charts */
    .chart-container {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
        padding-left: 20px;
        padding-bottom: 20px;
        padding-right: 0px;
        padding-top: 0px;
        height: 95%;
        width: 95%;
    }
    
    /* Standard sized chart */
    .chart-normal {
        border-radius: 4px;
        height: 300px;
        width: 400px;
        margin-top: 20px;
    }
    
    /* Full width/height chart */
    .chart-fill {
        width: 100%;
        height: 720px;
        margin-top: 20px;
        margin-right: 20px;
    }