Code Monkey home page Code Monkey logo

blazor-sparkline's Introduction

Blazor-Sparkline

Sparkline Charts for Blazor using Fonts

Open Source Sparkline Charts for Blazor and WebAssembly. It uses C#, HTML and CSS with minimal Javascript dependencies.

Sparklines are typically used to display summary information and they commonly appear in multiple rows of a HTML table. This component uses Open Type Fonts and does not require a SVG or Canvas element. The font is downloaded once and then used to display the Sparkline charts multiple times.

The current font uses dots to draw each segment of the Sparkline and is useful when you have many data points. The width of each segment can be specified by using the SegmentWidth parameter. A bigger SegmentWidth results in a longer Sparkline. It also means more data characters (dots) need to be generated to display the Sparkline using the font. Additional fonts will be added to support specific SegmentWidth instead of just a dot. This enables the the reduction of data characters generated.

#elegantlysimple

v0.2

MIT Licence

To use Sparkline

  1. Create your Blazor project.

  2. In YourProject.csproj, add

<ProjectReference Include="../Blazor-Sparkline/Sparklines/Sparklines.csproj" />

  1. In index.html, add

<link href="_content/Sparklines/styles.css" rel="stylesheet" />

  1. Finally, in Pages->Index.razor, add

<Sparkline InputData="60,0,16,25,48,45,1,0,6,37,78,79,90,90,91,99,80,0,40,0,0,56" GenerateText="true" SegmentWidth="30"></Sparkline>

To use Column Bars

  1. Create your Blazor project.

  2. In YourProject.csproj, add

<ProjectReference Include="../Blazor-Sparkline/ColumnBars/ColumnBars.csproj" />

  1. In index.html, add

<link href="_content/ColumnBars/styles.css" rel="stylesheet" />

  1. Finally, in Pages->Index.razor, add

<ColumnBars InputData="221,330,111,114,140,158,206,249,262,266,285,340,428,81,206,249,262,440,158,206,249,262,266,285,340,428" GenerateText="true" ></ColumnBars>

Similary

To use Bullet Chart

<ProjectReference Include="../Blazor-Sparkline/BulletBars/BulletBars.csproj" />

<link href="_content/BulletBars/styles.css" rel="stylesheet" />

<BulletBars InputData="26,40,95,100" Actual="49" Target="53" GenerateText="true">
</BulletBars>

To use MiniPie

<ProjectReference Include="../Blazor-Sparkline/MiniPie/MiniPie.csproj" />

<link href="_content/MiniPie/styles.css" rel="stylesheet" />

<MiniPie InputData="26,40,95,100" GenerateText="true">
</MiniPie>

To use Win Loss Draw

<ProjectReference Include="../Blazor-Sparkline/WinLoss/WinLoss.csproj" />

<link href="_content/WinLoss/styles.css" rel="stylesheet" />

<WinLoss InputData="1,1,1,-1,1,1,1,0,1,-1,1,1,1,1,1,0,1,-1,1,1,1,1,0,0,0,1,1,1,0,1,1,-1,1,1,1,1" GenerateText="true">
</WinLoss>

Alternatively, check out our Misfits-Rebels-Outcasts/Blazor-Dashboard project on how to use this Blazor Sparkline component.

blazor-sparkline's People

Contributors

webassemblyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blazor-sparkline's Issues

Sparkline content isn't rendered correctly when input data is all zeros

Hello,

Firstly, thank you for providing this library, it's a really handy tool.

In SparklineFont.DrawSparkline you search the input data for min and max, however, if the data only contains zeros, max is set to zero and therefore pcy0 and pcy1 are set to NaN due to a divide by zero issue.

For example, the input data "0.0,0.0,0.0" results in the GeneratedText being as per sample below and not rendering correctly in the browser.

<span class="Sparklines"><span class="sparkline-start">&#-2147419558;</span>
 &#-2147483472;&#-2147483600;&#-2147483600;&#-2147483472;&#-2147483600;&#-2147483600;
<span class="sparkline-stop">&#-2147419558;</span></span>

I'd have a go at creating a PR, but not sure how you'd want it fixed. Any chance you could take a look please?

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.