Question

I'm newbie with Xcode, I'm learning it and trying things... Now I try to draw a graph on iOS via FusionCharts XT. I add the webView to my screen and start with FusionChart's documentation example here Now I have the code:

  - (void)viewDidLoad
 {
   //chart building (via FusionChartsXT)
   [self plotChart];
 }

  - (void)plotChart
 {
   self.chartData = [NSMutableString string];
   [self.chartData appendString:@"<chart caption='Weekly Sales Summary' "];
   [self.chartData appendString:@"xAxisName='Week' yAxisName='Amount' numberPrefix='$'> "];
   [self.chartData appendString:@"<set label='Week 1' value='14400' /> "];
   [self.chartData appendString:@"<set label='Week 2' value='19600' /> "];
   [self.chartData appendString:@"<set label='Week 3' value='24000' /> "];
   [self.chartData appendString:@"<set label='Week 4' value='15700' /> "];
   [self.chartData appendString:@"</chart>"];

   //setup chart HTML
   self.htmlContent = [NSMutableString stringWithFormat:@"%@", @"<html><head>"];
   [self.htmlContent appendString:@"<script type='text/javascript' src='FusionCharts.js'></script>"];
   [self.htmlContent appendString:@"</head><body><div id='chartContainer'>Chart will render here.</div>"];
   [self.htmlContent appendString:@"<script type='text/javascript'>"];
   [self.htmlContent appendString:@"var myChart = new FusionCharts( 'Column3D.swf', 'myChartId', '400', '300' );"];
   [self.htmlContent appendFormat:@"myChart.setXMLUrl(\"%@\");", self.chartData];
   [self.htmlContent appendString:@"myChart.render('chartContainer');"];
   [self.htmlContent appendString:@"</script></body></html>"];

   //HTML loading
   [self.webView loadHTMLString:self.htmlContent
                     baseURL:nil];

   }

But Chart will render here is everything what I see. What do I do wrong? I saw example but it is too overkill. I want something simple as I wrote just xml and web render.

Was it helpful?

Solution

I found the mistake!

That last line is correct:

NSURL *baseURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@", [[NSBundle mainBundle] bundlePath]]];
    [self.webView loadHTMLString:self.htmlContent baseURL:baseURL];

OTHER TIPS

“Chart” message appears when the FusionCharts JavaScript files are inaccessible. Please ensure you’ve copied jquery.min.js, FusionCharts.HC.js and FusionCharts.HC.Widgets.js in the same folder as FusionCharts.js.

Also, ensure there are any JavaScript syntax or runtime errors that might have halted the execution of FusionCharts APIs. To debug, you could check if the HTML & XML strings are proper by writing them to the Xcode console.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top