Search results

Getting started with ASP.NET Core Bullet Chart control

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Please refer to this link to know about registering Syncfusion license key in your ASP.NET Core application to use our components.

Prerequisites

To get start with ASP.NET Core application, need to ensure the following software to be installed on the machine.

  • Visual Studio 2017
  • DotNet Core 2.0

Setup ASP.NET Core application with Essential JS 2 for ASP.NET Core

The following steps to create ASP.NET Core Application.

Step 1: Create ASP.NET Core Web Application with default template project in Visual Studio 2017.

Alt text

Step 2: Once your project created. We need to add Syncfusion EJ2 package into your application by using Nugget Package Manager.

Open the nuGet package manager.

Alt text

Install the Syncfusion.EJ2 package to the application

Alt text

After Installation complete this will included in the project. You can refer it from the Project Assembly Reference.

We need to install NewtonSoft.JSON as dependency since it Syncfusion.EJ2 dependent to NewtonSoft.JSON package.

Step 3: Open the Views/_ViewImports.cshtml to import Syncfusion.EJ2 package.

@addTagHelper *, Syncfusion.EJ2

Step 4: Add client side resource through CDN or local package in the layout page Views/Shared/_Layout.cshtml.

<head>
@* Syncfusion Essential JS 2 Styles *@
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css" />

@* Syncfusion Essential JS 2 Scripts *@
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>
</head>

Step 5: Adding Script Manager in layout page Views/Shared/_Layout.cshtml.

<body>
    @RenderBody()
    @RenderSection("Scripts", required: false)
<ejs-scripts></ejs-scripts>
</body>

Adding component to the Application

  • Now open your view page to render our Syncfusion components.
<ejs-bulletchart id="container"></ejs-bulletchart>

BulletChart With Data

This section explains how to plot local data to the bullet chart.

<script type="text/javascript" >
        window.onLoad = function (args) {
            args.bulletChart.dataSource = data;
        }
        var data = [
       { value: 100, target: 80 },
       { value: 200, target: 180 },
       { value: 300, target: 280 },
       { value: 400, target: 380 },
       { value: 500, target: 480 },
        ];
</script>

Now assign the data to dataSource property. value and target values should be mapped with valueName and targetName respectively.

tagHelper
default.cs
<ejs-bulletchart id="bulletgraph" minimum="0" maximum="300" interval="50" valueField="value" targetField="target" dataSource="ViewBag.dataSource">
</ejs-bulletchart>
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 270, target = 250}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }

Add Bullet Chart Title

You can add a title using title property to the bullet chart to provide quick information to the user about the data plotted in the bullet chart.

tagHelper
title.cs
<ejs-bulletchart id="bulletgraph" title="Revenue" minimum="0" maximum="300" interval="50" valueField="value" targetField="target" dataSource="ViewBag.dataSource">
</ejs-bulletchart>
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 270, target = 250}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }

Ranges

You can add a range using e-bullet-range of the e-bullet-range-collection.

tagHelper
ranges.cs
<ejs-bulletchart id="bulletgraph" minimum="0" maximum="300" interval="50" valueField="value" targetField="target" dataSource="ViewBag.dataSource">
        <e-bullet-range-collection>
            <e-bullet-range end="150"></e-bullet-range>
            <e-bullet-range end="250"></e-bullet-range>
            <e-bullet-range end="300"></e-bullet-range>
        </e-bullet-range-collection>
</ejs-bulletchart>
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 270, target = 250}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }

Tooltip

You can use tooltip for the bullet chart by setting the enable property to true in e-bulletchart-tooltipsettings.

tagHelper
tooltip.cs
<ejs-bulletchart id="bulletgraph" minimum="0" maximum="300" interval="50" valueField="value" targetField="target" dataSource="ViewBag.dataSource">
        <e-bulletchart-tooltipsettings enable="true"></e-bulletchart-tooltipsettings>
        <e-bullet-range-collection>
            <e-bullet-range end="150"></e-bullet-range>
            <e-bullet-range end="250"></e-bullet-range>
            <e-bullet-range end="300"></e-bullet-range>
        </e-bullet-range-collection>
</ejs-bulletchart>
public IActionResult Index()
        {
            List<DefaultBulletData> bulletData = new List<DefaultBulletData>
            {
                new DefaultBulletData { value = 270, target = 250}     
            };
            ViewBag.dataSource = bulletData;
            return View();
        }
        public class DefaultBulletData
        {           
            public double value;
            public double target;
        }