score:3
Accepted answer
Well, I worked it out myself after all... I thought I should post it in case some other HighCharts newbie like me is interested:
Here's the jQuery that worked:
function getHighChart() {
var actionUrl = '<%= Url.Action("GetChartData") %>';
var customerId = $('#customersId').val();
var customerName = $('#customersId option:selected').text();
var startdate = $('.date-pickStart').val();
var enddate = $('.date-pickEnd').val();
//define the options
var options = {
chart: {
renderTo: 'chart-container',
defaultSeriesType: 'column'
},
title: {
text: 'Hours worked for ' + customerName
},
xAxis: {
categories: [customerName]
},
yAxis: {
title: {
text: 'Hours'
}
},
series: []
};
//Calls the JSON action method
jQuery.getJSON(actionUrl,
{ customerId: customerId, startdate: startdate, enddate: enddate }, function (items) {
$.each(items, function (itemNo, item) {
var series = {
data: []
};
series.name = item.Key;
series.data.push(parseFloat(item.Value));
options.series.push(series);
});
var chart = new Highcharts.Chart(options);
});
}
If someone can find faults in this and point me to a better way to do it, I'll gladly hand over the answer credit, otherwise I'll accept my own answer...
score:4
I use:
//Controller action:
public JsonResult GetData(int id)
{
Dictionary<int, double> data = this.repository.GetData(id);
return Json(data.ToArray(), JsonRequestBehavior.AllowGet);
}
View:
<script>
var chart1;
$(document).ready(function () {
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'chart-container-1',
defaultSeriesType: 'scatter',
events: {
load: requestData
}
},
options...
,
series: [{
name: 'some data',
data: []
}]
});
}
);
function requestData() {
$.ajax({
url: '/ControllerName/GetData?id=@(Model.Id)',
success: function (items) {
$.each(items, function (itemNo, item) {
chart1.series[0].addPoint([item.Key,item.Value], false);
});
chart1.redraw();
},
cache: false
});
}
</script>
<div id="chart-container-1"></div>
So basically I use addPoint('array of x,y',false for not redrawing chart)
Source: stackoverflow.com
Related Query
- Simple bar chart in jQuery HighCharts and MVC 2 application?
- Highcharts percentage of total for simple bar chart
- Highcharts / jQuery - destroy and rebuild chart with original options
- highcharts jquery dynamic change chart type column to bar
- Highcharts - Bar - Setting the X axis width and the chart area width to be constant
- Highcharts bar chart with fixed bar widths and gaps
- Highcharts no longer animates and readjusts/rescales chart upon addition and removal of series in legend after upgrading to jQuery 1.10
- (Horizontal) bar and line chart with Highcharts
- Switch between pie charts and bar chart in highcharts
- .net Highcharts can't show the bar chart correctly in mvc
- Highcharts single horizontal stacked bar chart with data names (labels) and %-ages always shown and data numbers and series name shown on mousehover
- Displaying count on bar and percentage on Y-axis of cloumn chart using Highcharts
- How can I prepare a Group Stacked Bar Chart in Highcharts using multiple and different types of data?
- Highcharts - column chart has space between bar and xAxis
- Combined Chart Highcharts Pie plus Bar grouppadding and pointapadding issue
- Real Time Bar chart using Highcharts and AngularJs
- Highcharts bar chart configuration to increase height and round edges
- realign Labels inside and outside the bar chart on highcharts
- Controlling Highcharts bar chart look and layout
- Parsing CSV and then Using the Data to Build Highcharts Bar Chart
- Plot Bar chart and Line series chart on separate x-axis in Highcharts out of common dataset
- Highcharts bar chart with negative and positive data
- Combining a horizontal bar graph and stock chart (with navigator) HighCharts
- Chart using highcharts and Json asp.net MVC
- How to create a column range chart in Highcharts using range and navigator functions?
- How to display the value instead of percentage in a pie chart using jquery Highcharts
- How do I rotate my HighCharts bar chart so its vertical, not horizontal?
- Loading Highcharts via shim using RequireJS and maintaining jQuery dependency
- dealing with highcharts bar chart with really long category names
- jQuery UI Tabs and Highcharts display/rendering issue
More Query from same tag
- HighCharts Stock Chart error code 18
- HTML5 Chart library that supports pinch zooming
- Interact with highcharts using jQuery?
- highcharts.js - Dynamic Label Color
- rendering react-highcharts with mount enzyme gives an InvalidCharacterError
- Highcharts in angular scope problem with passing class reference
- Highcharts Columnrange Questions (multiple y-axes and column widths)
- Highcharts lines not being drawn until browser is resized
- UseHTML property in XAxisTitle or YAxisTitle
- Highcharts unable to fit it to mobile screen size
- Converting svg from Highcharts data into data points
- Highcharts - Line breaks from node to node in sankey diagram
- Stock notes are overlapping on StockChart, Is there any way to handle this?
- How to find max: value of colorAxis for highMaps drilldown maps
- Rails + PostgreSQL group data hourly with datetime
- Highcharts Tooltip display different data
- How to add box shadow for highchart chart?
- highcharts start from hinges base
- HighCharts - problems with tickInterval and tickAmount
- Use server-side json with Highchart
- Setting Highcharts styledMode: true fails to load CSS
- How to provide dynamic hover color in highmaps?
- Highcharts make pie chart goal value only 50%
- HighChart Tooltip Position can be changed?
- Is it possible to customize the features of stack parameter in highchart.js library
- How can i add dynamic data inside flag series in highcharts
- Dynamically changing Highcharts Theme through Jquery code not working
- Highchart Persist bar widh for null data
- Highcharts - chartanimation step by step
- If a point is clicked then add a marker in highcharts