0

I am trying to make a chart in MVC 4. But it's not working.I am using High-Charts.This is my action method.

public ActionResult Index()
        {
            var title = new Title() { Text = "Workload" };

            var subtitle = new Subtitle() { Text = "workload per day" };

            var XData = new[] { "25", "26", "27", "28", "29", "30", "31", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
            var YData = new object[] { 195, 150, 0, 270, 0, 90, 245, 215, 350, 355, 190, 95, 0, 100, 225 };

            var xaxisTitle = new XAxisTitle { Text = "Wokload in minutes" };
            var yaxisTitle = new YAxisTitle { Text = "Time in days" };

            string serieName = "Workload per day";

            Highcharts chart = new Highcharts("chart")
                .SetTitle(title)
                .SetSubtitle(subtitle)
                .SetXAxis(new XAxis
                {
                    Categories = XData,
                    Title = xaxisTitle
                })
                .SetYAxis(new YAxis
                {
                    Title = yaxisTitle
                })
                .SetSeries(new Series
                {
                    Data = new Data(YData),
                    Name = serieName
                });

            return View(chart);

        }

and this is my View.

@model DotNet.Highcharts.Highcharts
@{
    ViewBag.Title = "Index";
}
<header>
    <script src="~/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="~/Scripts/highcharts.js" type="text/javascript"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
    <script src="~/Scripts/jquery-1.7.1.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts.src.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts-more.src.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts-more.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts-all.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts-3d.src.js"></script>
    <script src="~/Scripts/Highcharts-4.0.1/js/highcharts-3d.js"></script>
    <script src="~/Scripts/jquery-1.7.1.js"></script>
</header>

There is a graph


@(Model)

What is wrong with this code? This is showing nothing in the view. There is a blank page when i run it.Please someone guide me.

1
  • Open JavaScript console and copy&paste here errors. In Chrome it's ctrl+shift+J (or Options -> More Tools -> JavaScript Console). Commented May 28, 2015 at 13:31

2 Answers 2

1

It works fine for me Just remove the redundant Script URL and match the version of your Script file and the URL you used. for example let me show you how I used This Code. before this leave the codes inside your action as it is. do not modify it.

The problem is your Java Script version

Look at this Image

I changed this <script src="~/Scripts/jquery-1.7.1.js"></script> in to <script src="~/Scripts/jquery-1.10.2.js"></script> and <script src="~/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script> in to <script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>

now My Code is fine to run.

Happy Coding

Sign up to request clarification or add additional context in comments.

Comments

0

Worked fine on my computer after I removed two redundant jquery links. You don't need both js and min.js files. Latter is just optimized version of former with removed unnesessary spaces, shortened variable names, etc.

12 Comments

which two line should i removed please mention
<script src="~/Scripts/jquery-1.7.1.js"></script> Two of them. Also make sure you refer correct version of jquery. For example i've got 1.8.2 not 1.7.1 in my Scripts directory.
Actually, I think it's all because of wrong version number. You can have both js and min.js file. It still works this way.
not working... Please mention two lines that you have removed .
Do you have jquery-1.5.1.min.js file in your Scripts directory? I think you need to change version number.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.