Chart DataPerformance !!!Bar and Column ChartsLine and Area ChartsPie and Funnel ChartsScatter and Bubble ChartsRadar and Polar ChartsFinancial ChartsGantt ChartsCombinational ChartsDynamic ChartsWorking with Chart AxesChart FeaturesCustomizing ChartClient-Side Events |
This sample demonstrates how to customize the data point labels with dataPointLabelCreating
Event.
For detailed implementation, please take a look at the Aspx, Razor and Controller code tabs. <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <%@ Import Namespace="JQChart.Web.Mvc" %> <!DOCTYPE html> <html> <head runat="server"> <title></title> <link rel="stylesheet" type="text/css" href="~/Content/jquery.jqChart.css" /> <link rel="stylesheet" type="text/css" href="~/Content/themes/le-frog/jquery-ui-1.8.20.css" /> <script src="<%: Url.Content("~/Scripts/jquery-1.11.1.min.js") %>" type="text/javascript"></script> <script src="<%: Url.Content("~/Scripts/jquery.jqChart.min.js") %>" type="text/javascript"></script> <body> <script lang="javascript" type="text/javascript"> function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } $(document).ready(function () { $('#jqChart').bind('tooltipFormat', function (e, data) { return '$' + addCommas(data.y); }); $('#jqChart').bind('dataPointLabelCreating', function (event, data) { data.text = '$' + addCommas(data.text); }); }); </script> <div> <%= Html.JQChart() .Chart() .ID("jqChart") .Width(500) .Height(300) .Title("dataPointLabelCreating Event") .Border(border => border.StrokeStyle("#6ba851")) .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop => { stop.Add(0, "#d2e6c9"); stop.Add(1, "white"); })) .Animation(TimeSpan.FromSeconds(1)) .Series(series => { series.Column().Title("Column") .XValues(new string[] { "A", "B", "C", "D", "E", "F", "G", "H" }) .YValues(new double[] { 4600, 3500, 6800, 4000, 2700, 8500, 4300, 2900 }) .Labels(el => el.Font("11px sans-serif").FillStyle("red")); } ) .Render()%> </div> </body> </html> @using JQChart.Web.Mvc <!DOCTYPE html> <html> <head runat="server"> <title></title> <link rel="stylesheet" type="text/css" href="~/Content/jquery.jqChart.css" /> <link rel="stylesheet" type="text/css" href="~/Content/themes/le-frog/jquery-ui-1.8.20.css" /> <script src="@Url.Content("~/Scripts/jquery-1.11.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.jqChart.min.js")" type="text/javascript"></script> <body> <script lang="javascript" type="text/javascript"> function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } $(document).ready(function () { $('#jqChart').bind('tooltipFormat', function (e, data) { return '$' + addCommas(data.y); }); $('#jqChart').bind('dataPointLabelCreating', function (event, data) { data.text = '$' + addCommas(data.text); }); }); </script> <div> @(Html.JQChart() .Chart() .ID("jqChart") .Width(500) .Height(300) .Title("dataPointLabelCreating Event") .Border(border => border.StrokeStyle("#6ba851")) .Background(background => background.LinearGradient(0, 0, 0, 1).ColorStops(stop => { stop.Add(0, "#d2e6c9"); stop.Add(1, "white"); })) .Animation(TimeSpan.FromSeconds(1)) .Series(series => { series.Column().Title("Column") .XValues(new string[] { "A", "B", "C", "D", "E", "F", "G", "H" }) .YValues(new double[] { 4600, 3500, 6800, 4000, 2700, 8500, 4300, 2900 }) .Labels(el => el.Font("11px sans-serif").FillStyle("red")); } ) .Render() ) </div> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace SamplesBrowser.Models { public class EmptyChartModel { } } using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using SamplesBrowser.Models; namespace SamplesBrowser.Controllers { public class ChartController : Controller { public ActionResult DataPointLabelCreatingEvent() { return View(); } } } |