0

I need to use the http://www.highcharts.com/ jQuery plugin to make a bartype graph on my intranet.

All my data are in CSHTML with my SQL requests and all results are stored in int types.

I want to put the values in the plugin for use them.

The part of the plugin where to put data is like this :

series: [{
            name: 'Actifs',
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]

        }, {
            name: 'Inactifs',
            data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0]

        }]

I have search how to "break" the jQuery to put my CSHTML vars but I haven't find an answer.

Is that possible ? If not how to get my CSHTML var in my jQuery ? Insert the base code CSHTML @{ //CSHTML Code } in the jQuery don't work.

Thanks in advance for answers

Alex L
  • 125
  • 4
  • 16

1 Answers1

0

You can use the Json Helper to generate JSON data for the chart. Or you can simply generate a comma-separated string in your server-side code and plug that in at the appropriate place by prefixing the variable with the @ sign. No need for code block braces:

series: [{
            name: 'Actifs',
            data: [@MyFirstCommaSeparateString]

        }, {
            name: 'Inactifs',
            data: [@MySecondCommaSeparateString]

        }]
Mike Brind
  • 28,238
  • 6
  • 56
  • 88