Giter Site home page Giter Site logo

nikspatel007 / chartjs.net Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 6.09 MB

Creating a .NET wrapper using MVCHtmlString to allow Razor Engine to render charts on the fly. We have used MVCHtmlString to generate HtmlString and we will use HtmlHelpers to extend the functionality of Razor Engine.

License: MIT License

C# 17.49% Batchfile 0.02% PowerShell 0.07% CSS 34.61% ASP 0.02% JavaScript 44.59% HTML 3.20%

chartjs.net's Introduction

ChartJS.NET

Creating a .NET wrapper using MVCHtmlString to allow Razor Engine to render charts on the fly. We have used MVCHtmlString to generate HtmlString and we will use HtmlHelpers to extend the functionality of Razor Engine.

Rendering Bar Charts

To build your Bar Chart, you will need to add code to your controller and then use the HTML Extensions in your view. Below is the controller code:

  public ActionResult Index()
    {
        BarChart barChart = new BarChart();

        barChart.ChartData.Datasets = new List<BarDataSet>()
        {
            new BarDataSet() {
                Data = new double[] { 65, 59, 80, 81, 56, 55, 40 },
                Label = "First Dataset",
                FillColor = "rgba(220, 220, 220, 0.5)",
                StrokeColor = "rgba(220, 220, 220, 0.8)",
                HighlightFillColor = "rgba(220, 220, 220, 0.75)",
                HighlightStrokeColor = "rgba(220, 220, 220, 1)"
            },
            new BarDataSet() {
                Data = new double[] { 28, 48, 40, 19, 86, 27, 90 },
                Label = "Second Dataset",
                FillColor = "rgba(151,187,205, 0.5)",
                StrokeColor = "rgba(151,187,205, 0.8)",
                HighlightFillColor = "rgba(151,187,205, 0.75)",
                HighlightStrokeColor = "rgba(151,187,205, 1)"
            }
        };

        barChart.ChartData.Labels = new List<string>() {
            "January", "February", "March", "April", "May", "June", "July"
        };


        barChart.ChartConfig.BarDatasetSpacing = 50;
        barChart.ChartConfig.ScaleGridLineColor = "rgba(0,0,0, 1)";
        barChart.ChartConfig.ScaleGridLineWidth = 2;
        barChart.ChartConfig.ScaleShowGridLines = true;
        barChart.ChartConfig.ScaleShowHorizontalLines = true;

        return View(barChart);
    }

and then in your view, you can use this:

  @model ChartJS.NET.Charts.Bar.BarChart

  @Html.BuildChart(Model)

You should now see your bar chart rendered on the page. There is also a samples project included so you can see how the code is being used.

chartjs.net's People

Contributors

launchpad-tester avatar nikspatel007 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

chartjs.net's Issues

Polar Area Chart

Create the structure and page for the Polar Area Chart. This will follow the pattern of Pie and Doughnut charts.

Global Options

Need to figure out how to allow the user / coder to apply global options as well as chart specific options.

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.