• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Svelte Component for FusionCharts JavaScript Charting Library

Svelte-FusionCharts

A simple and lightweight official Svelte component for FusionCharts JavaScript charting library. svelte-fusioncharts enables you to add JavaScript charts in your Svelte application or project without any hassle.

Demo


Table of Contents

Getting Started

Requirements

  • Node.js, NPM/Yarn installed globally in your OS.
  • FusionCharts and Svelte installed in your project, as detailed below:

Installation

There are multiple ways to install svelte-fusioncharts component.

Install from NPM

npm install --save svelte-fusioncharts

See npm documentation to know more about npm usage.

Usage

Import svelte-fusioncharts and FusionCharts in your app:

<script>
  import FusionCharts from 'fusioncharts/core';
  import Column2d from 'fusioncharts/viz/column2d';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  fcRoot(FusionCharts, Column2d);
</script>

Note: This way of import will not work in IE11 and below.

Quick Start

Here is a basic sample that shows how to create a chart using svelte-fusioncharts:

<script>
  import FusionCharts from 'fusioncharts';
  import Charts from 'fusioncharts/fusioncharts.charts';
  import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  // Always set FusionCharts as the first parameter
  fcRoot(FusionCharts, Charts, FusionTheme);

  const dataSource = {
    chart: {
      caption: 'Countries With Most Oil Reserves [2017-18]',
      subCaption: 'In MMbbl = One Million barrels',
      xAxisName: 'Country',
      yAxisName: 'Reserves (MMbbl)',
      numberSuffix: 'K',
      theme: 'fusion'
    },
    data: [
      { label: 'Venezuela', value: '290' },
      { label: 'Saudi', value: '260' },
      { label: 'Canada', value: '180' },
      { label: 'Iran', value: '140' },
      { label: 'Russia', value: '115' },
      { label: 'UAE', value: '100' },
      { label: 'US', value: '30' },
      { label: 'China', value: '30' }
    ]
  };

  const chartConfigs = {
    type: 'column2d',
    width: 600,
    height: 400,
    dataFormat: 'json',
    dataSource: dataSource
  };
</script>

<SvelteFC {...chartConfigs} />

Render FusionMaps

To render a map, import the FusionMaps module along with the map definition.

<script>
  import FusionCharts from 'fusioncharts';
  import Maps from 'fusioncharts/fusioncharts.maps';
  import World from 'fusioncharts/maps/fusioncharts.world';
  import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  // Always set FusionCharts as the first parameter
  fcRoot(FusionCharts, Maps, World, FusionTheme);
  
  const dataSource = {
    chart: {
      caption: 'Average Annual Population Growth',
      subcaption: ' 1955-2015',
      numbersuffix: '%',
      includevalueinlabels: '1',
      labelsepchar: ': ',
      entityFillHoverColor: '#FFF9C4',
      theme: 'fusion'
    },
    colorrange: {
      minvalue: '0',
      code: '#FFE0B2',
      gradient: '1',
      color: [
        { minvalue: '0.5', maxvalue: '1.0', color: '#FFD74D' },
        { minvalue: '1.0', maxvalue: '2.0', color: '#FB8C00' },
        { minvalue: '2.0', maxvalue: '3.0', color: '#E65100' }
      ]
    },
    data: [
      { id: 'NA', value: '.82', showLabel: '1' },
      { id: 'SA', value: '2.04', showLabel: '1' },
      { id: 'AS', value: '1.78', showLabel: '1' },
      { id: 'EU', value: '.40', showLabel: '1' },
      { id: 'AF', value: '2.58', showLabel: '1' },
      { id: 'AU', value: '1.30', showLabel: '1' }
    ]
  };

  const chartConfigs = {
    type: 'world',
    width: 600,
    height: 400,
    dataFormat: 'json',
    dataSource: dataSource
  };
</script>

<SvelteFC {...chartConfigs} />

Working with Events

To attach event callbacks to a FusionCharts component, follow the sample below.

<script>
  import FusionCharts from 'fusioncharts';
  import Charts from 'fusioncharts/fusioncharts.charts';
  import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  // Always set FusionCharts as the first parameter
  fcRoot(FusionCharts, Charts, FusionTheme);

  const dataSource = {
      chart: {
        caption: 'Countries With Most Oil Reserves [2017-18]',
        subCaption: 'In MMbbl = One Million barrels',
        xAxisName: 'Country',
        yAxisName: 'Reserves (MMbbl)',
        numberSuffix: 'K',
        theme: 'fusion'
      },
      data: [
        { label: 'Venezuela', value: '290' },
        { label: 'Saudi', value: '260' },
        { label: 'Canada', value: '180' },
        { label: 'Iran', value: '140' },
        { label: 'Russia', value: '115' },
        { label: 'UAE', value: '100' },
        { label: 'US', value: '30' },
        { label: 'China', value: '30' }
      ]
    },
    dataplotClickHandler = event => {
      // code for dataplotClick event handler
    },
    renderCompleteHandler = event => {
      // code for renderComplete event handler
    };

  const chartConfigs = {
    type: 'column2d',
    width: 600,
    height: 400,
    dataFormat: 'json',
    dataSource: dataSource
  };
</script>

<SvelteFC
  {...chartConfigs}
  on:dataplotClick={dataplotClickHandler}
  on:renderComplete={renderCompleteHandler}
/>

Working with APIs

To call APIs we will need the chart object. To get the chart object for an SvelteFC component, bind a variable with the chart property of SvelteFC component.

<script>
  import FusionCharts from 'fusioncharts';
  import Charts from 'fusioncharts/fusioncharts.charts';

  import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  fcRoot(FusionCharts, Charts, FusionTheme);

  let chartObj,
    dataSource = {
      "chart": {
        "caption": "Market Share of Web Servers",
        "plottooltext": "<b>$percentValue</b> of web servers run on $label servers",
        "showLegend": "1",
        "showPercentValues": "1",
        "legendPosition": "bottom",
        "useDataPlotColorForLabels": "1",
        "enablemultislicing": "0",
        "showlegend": "0",
        "theme": "fusion",
      },
      "data": [{
        "label": "Apache",
        "value": "32647479"
      }, {
        "label": "Microsoft",
        "value": "22100932"
      }, {
        "label": "Zeus",
        "value": "14376"
      }, {
        "label": "Other",
        "value": "18674221"
      }]
    },
    chartConfig = {
      type: 'pie2d',
      width: '600',
      height: '400',
      renderAt: 'chart-container',
      dataSource 
    };

  const sliceDataPlot = (index, sliceOut = true) => {
    chartObj.slicePlotItem(index, sliceOut)
  };
</script>

<div id="chart-container" >
  <SvelteFC {...chartConfig} bind:chart={chartObj} />
</div>

<button on:click={() => {
  sliceDataPlot(1);
}}>
  Slice out
</button>
<button on:click={() => {
  sliceDataPlot(1, false);
}} >
  Slice in
</button>

links to help you get started:

Usage and integration of FusionTime

From [email protected], You can visualize timeseries data.

Learn more about FusionTime here.

Consider the example below for integration of FusionTime

<script>
  import FusionCharts from 'fusioncharts';
  import Timeseries from 'fusioncharts/fusioncharts.timeseries';
  import SvelteFC, { fcRoot } from 'svelte-fusioncharts';

  fcRoot(FusionCharts, Timeseries);

  let promise,
    jsonify = res => res.json(),
    dataFetch = fetch(
      'https://s3.eu-central-1.amazonaws.com/fusion.store/ft/data/line-chart-with-time-axis-data.json'
    ).then(jsonify),
    schemaFetch = fetch(
      'https://s3.eu-central-1.amazonaws.com/fusion.store/ft/schema/line-chart-with-time-axis-schema.json'
    ).then(jsonify);

  promise = Promise.all([dataFetch, schemaFetch]);

  const getChartConfig = ([data, schema]) => {
    const fusionDataStore = new FusionCharts.DataStore(),
      fusionTable = fusionDataStore.createDataTable(data, schema);

    return {
      type: 'timeseries',
      width: '100%',
      height: 450,
      renderAt: 'chart-container',
      dataSource: {
        data: fusionTable,
        caption: {
          text: 'Sales Analysis'
        },
        subcaption: {
          text: 'Grocery'
        },
        yAxis: [
          {
            plot: {
              value: 'Grocery Sales Value',
              type: 'line'
            },
            format: {
              prefix: '$'
            },
            title: 'Sale Value'
          }
        ]
      }
    };
  };
</script>

<div id="chart-container" >
  {#await promise}
    <p>Fetching data and schema...</p>
  {:then value}
    <SvelteFC
      {...getChartConfig(value)}
    />
  {:catch error}
    <p>Something went wrong: {error.message}</p>
  {/await}
</div>

Useful links for FusionTime

Going Beyond Charts

  • Explore 20+ pre-built business specific dashboards for different industries like energy and manufacturing to business functions like sales, marketing and operations here.
  • See Data Stories built using FusionCharts’ interactive JavaScript visualizations and learn how to communicate real-world narratives through underlying data to tell compelling stories.

For Contributors

  • Clone the repository and install dependencies
$ git clone https://github.com/fusioncharts/svelte-fusioncharts.git
$ cd svelte-fusioncharts
$ npm i
$ npm run dev
  • Run npm run build to create a production build.

Licensing

The FusionCharts Svelte component is open-source and distributed under the terms of the MIT/X11 License. However, you will need to download and include FusionCharts library in your page separately, which has a separate license.

More Repositories

1

angularjs-fusioncharts

AngularJS Directive for FusionCharts JavaScript Charting Library (for Angular 1.x)
JavaScript
111
star
2

react-fusioncharts-component

ReactJS component for FusionCharts JavaScript Charting library.
JavaScript
92
star
3

vue-fusioncharts

Vue Component for FusionCharts JavaScript Charting Library
JavaScript
88
star
4

fusioncharts-dist

FusionCharts JavaScript Charting library. Over 95+ charts and 1,400+ maps to choose from, with integrations available for all popular JavaScript frameworks & back-end programming languages.
JavaScript
84
star
5

react-native-fusioncharts

Simple and Lightweight React Native component for FusionCharts JavaScript Charting Library
JavaScript
77
star
6

fusioncharts-jquery-plugin

jQuery plugin for FusionCharts JavaScript Charting Library
JavaScript
57
star
7

angular-fusioncharts

Angular Component for FusionCharts JavaScript Charting Library
TypeScript
55
star
8

php-wrapper

PHP Module for FusionCharts JavaScript Charting Library
PHP
46
star
9

react-fusioncharts

ReactJS component for FusionCharts
JavaScript
41
star
10

faberjs

FaberJS is an open-source platform-independent layouting engine capable of mimicking different CSS layouting paradigm(ex. CSS grids)
JavaScript
33
star
11

redraphael

JavaScript Graphics library built on top of raphaeljs to enhance rendering graphics on the browser.
JavaScript
22
star
12

rails-wrapper

Ruby On Rails Gem for FusionCharts JavaScript Charting Library
Ruby
20
star
13

redis-contentful

A tiny library to map Contentful ☁️ space into Redis ⚡️
JavaScript
17
star
14

angular4-fusioncharts

A simple and lightweight Angular 4 component which provides bindings for FusionCharts JavaScript Charting Library
TypeScript
17
star
15

django-wrapper

Django Module for FusionCharts JavaScript Charting Library
Python
15
star
16

fusioncharts-smartlabel

SmartLabel component of FusionCharts
JavaScript
13
star
17

asp-net-wrapper

ASP.NET (C#) Wrapper for FusionCharts JavaScript Charting Library
C#
9
star
18

bouquet

Collection of plugins for JSDoc
JavaScript
8
star
19

fusionmaps-dist

Data-driven maps in JavaScript from FusionMaps (FusionCharts). Over 1,400+ maps of all countries, regions, counties etc.
JavaScript
8
star
20

jswarrior

JavaScript
7
star
21

jslink

Automated module concatenation with dependency management
JavaScript
7
star
22

fusionexport-apexcharts-samples

Examples to export charts and dashboards built using ApexCharts
HTML
6
star
23

dev_centre_docs

Documentation of FusionCharts JavaScript Charting Library
JavaScript
6
star
24

ember-fusioncharts

A lightweight EmberJS component which provides bindings for FusionCharts JavaScript Charting Library
JavaScript
6
star
25

fc-calendar

Light weight calendar component
JavaScript
5
star
26

svgDeCanvo

This library can be used to draw the SVG equivalent to HTML5 Canvas
JavaScript
5
star
27

fusionexport-node-client

Language SDK for FusionExport which enables exporting of charts & dashboards through NodeJS.
HTML
4
star
28

fusionexport-go-client

Language SDK for FusionExport which enables exporting of charts & dashboards through Golang.
Go
4
star
29

fusionexport-python-client

Language SDK for FusionExport which enables exporting of charts & dashboards through Python.
JavaScript
3
star
30

multi-charting

Data visualization that deals with multiple charts
JavaScript
3
star
31

jsp-wrapper

Java Plugin for FusionCharts JavaScript Charting Library
Java
3
star
32

fusionexport-cli

CLI for FusionExport. Enables exporting from FusionExport directly from command line.
JavaScript
3
star
33

rails-exporter

Export Server for FusionCharts on RoR
Ruby
3
star
34

chart-samples

Contains all the fiddles which fusioncharts showcases in the website.
JavaScript
3
star
35

backbone-fusioncharts

Backbone component for FusionCharts
JavaScript
3
star
36

fusioncharts.net-core-sample

FusionCharts samples created using FusionCharts.NET Standard libraries
C#
2
star
37

blazor-fusioncharts

JavaScript
2
star
38

fusionexport-csharp-client

Language SDK for FusionExport which enables exporting of charts & dashboards through C#.
HTML
2
star
39

fusionexport-php-client

Language SDK for FusionExport which enables exporting of charts & dashboards through PHP.
HTML
2
star
40

vb-net-wrapper

ASP.NET (VB) Wrapper for FusionCharts JavaScript Charting Library
Visual Basic .NET
2
star
41

fusionexport-csharp-examples

C#
1
star
42

fusionexport-node-examples

1
star
43

data-filters

1
star
44

data-generator

Tool to generate chart specific data dynamically
JavaScript
1
star
45

fusionexport-tutorials

Tutorial samples for FusionExport
HTML
1
star
46

fusionexport-php-examples

HTML
1
star
47

react-native-fusioncharts-samples

HTML
1
star
48

fileMaker-with-fusionCharts

1
star
49

date-range-chooser-ext

Date range chooser extension for FusionCharts time-series chart
JavaScript
1
star
50

fusioncharts-trial

JavaScript Data Visualisation Library
1
star
51

data-aggregator-ext

1
star
52

growth-analyser-ext

1
star
53

larry

Larry is a generic packaging tool for applications that need to bundle their source code in packages, ready to be shipped.
JavaScript
1
star
54

htmltosvg

JavaScript
1
star
55

flutter-fusioncharts

Dart
1
star
56

fc-with-zend-framwork

1
star
57

django-exporter

FusionCharts server side exporter for Django
Python
1
star
58

fusionexport-java-client

Language SDK for FusionExport which enables exporting of charts & dashboards through Java.
Java
1
star
59

d3-scroller

Draw a customizable SVG scroller
JavaScript
1
star