• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[Solved] Re: Accessing a Javascript datasource object via Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Solved] Re: Accessing a Javascript datasource object via Cocoa


  • Subject: [Solved] Re: Accessing a Javascript datasource object via Cocoa
  • From: Tito Ciuro <email@hidden>
  • Date: Sun, 11 Sep 2011 20:06:57 -0700

Hello,

On Sep 11, 2011, at 11:49 AM, Tito Ciuro wrote:

> Hello,
>
> Is there a way to manipulate a Javascript datasource object via Cocoa? For example, given the following snippet (edited for brevity):
>
> <html>
> 	<head>
> 		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> 		<title>Highcharts Example</title>
> 		<script type="text/javascript">
> 			var chart;
> 			$(document).ready(function() {
> 				chart = new Highcharts.Chart({
> 					chart: {
> 						renderTo: 'container',
> 						defaultSeriesType: 'bar',
> 					},
> 					xAxis: {
> 						categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
> 						title: {
> 							text: null
> 						}
> 					},
> 					series: [{
>        				data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]}]
> 				});
> 			});
> 		</script>
> 	</head>
> 	<body>
> 		<!-- 3. Add the container -->
> 		<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
> </body>
> </html>
>
> Is there a way to access the chart.series[0].data element in order to manipulate it? I'm not sure if it's OK to post this question here... it's about Cocoa, but probably involves WebKit, so I don't know if this is the right place.
>
> Thanks in advance,
>
> -- Tito

I figured it out. I did two things:

1) Add a Javascript function to the <script> section:

function addHits(month, incrementBy) {
    var data = chart.series[0].data[month];
    data.update(data.y + incrementBy);
};

2) Call it from my app:

- (IBAction)increment:(id)sender
{
    NSArray *args = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:10], nil];
    [[webView windowScriptObject]callWebScriptMethod:@"addHits" withArguments:args];
}

It works great :-)

-- Tito
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Accessing a Javascript datasource object via Cocoa (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Internal warning/failure appears not to be my code after all.
  • Next by Date: Avoid smooth scrolling when scrolling programmatically
  • Previous by thread: Accessing a Javascript datasource object via Cocoa
  • Next by thread: Internal warning/failure appears not to be my code after all.
  • Index(es):
    • Date
    • Thread