Commits

keba  committed d58ff50

first "working" version

  • Participants
  • Parent commits 028f0fd

Comments (0)

Files changed (3)

             js += JS_END
 
         if self.categories:
-            js += 'categories: %s\n' % str(self.categories)
+            js += 'categories: %s,\n' % str(self.categories)
 
         js += JS_END
         return js
 
     @property
     def js(self):
-        js = 'xAxis: {\n'
+        js = 'yAxis: {\n'
 
         if self.title:
             js += 'title: {\n'
         if self.yAxis: js += self.yAxis.js
 
         if self.series:
-            js += '%s\n' % str(self.series)
+            js += 'series: ['
+            series_len = len(self.series)
+            for x, serie in enumerate(self.series):
+                js += '{name: \'%s\', data: %s}' % (serie['name'], serie['data'])
+                if x +1 < series_len:
+                    js += ',\n'
+                else:
+                    js += ']\n'
+
         else:
             print "Warning: No data for this chart."
 
-        js += JS_END
         return js
 
 class Chartset(object):
         js += '$(document).ready(function() {\n' ## jQuery
 
         for x, chart in enumerate(self.charts):
-            js += 'chart%i= new Highcharts.Chart({\n' % x
-            js += '    renderTo: "chart-container-1",\n'
-            js += '    defaultSeriesType: "%s"\n' % chart.type
-            js += JS_END
+            js += 'chart%i = new Highcharts.Chart({\n' % x
+            js += '    chart: {\n'
+            js += '        renderTo: "container",\n'
+            js += '        defaultSeriesType: "%s"\n' % chart.type
+            js += '    ' + JS_END
 
-            js += chart.js
+            for line in chart.js.split('\n'):
+                js += '    ' + line + '\n'
 
             js += ' });'
         js += ' });'
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+        <title>Highcharts Example</title>
+
+
+        <!-- 1. Add these JavaScript inclusions in the head of your page -->
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+        <script type="text/javascript" src="js/highcharts.js"></script>
+        <!--[if IE]>
+            <script type="text/javascript" src="js/excanvas.compiled.js"></script>
+        <![endif]-->-
+
+
+        <!-- 2. Add the JavaScript to initialize the chart on document ready -->
+        <script type="text/javascript">
+        var mychart;
+$(document).ready(function() {
+chart0 = new Highcharts.Chart({
+    chart: {
+        renderTo: "container",
+        defaultSeriesType: "bar"
+    },
+    title: {
+        text: "Fruit Consumption"
+    },
+    xAxis: {
+    categories: ['Apples', 'Bananas', 'Oranges'],
+    },
+    yAxis: {
+    title: {
+        text: "Fruit eaten"
+    },
+    },
+    series: [{name: 'Jane', data: [1, 0, 4]},
+    {name: 'John', data: [5, 7, 3]}]
+
+ }); });
+
+
+
+        </script>
+
+</head>
+    <body>
+        <div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
+    </body>
+</html>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+        <title>Highcharts Example</title>
+
+
+        <!-- 1. Add these JavaScript inclusions in the head of your page -->
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+        <script type="text/javascript" src="js/highcharts.js"></script>
+        <!--[if IE]>
+            <script type="text/javascript" src="js/excanvas.compiled.js"></script>
+        <![endif]-->
+
+
+        <!-- 2. Add the JavaScript to initialize the chart on document ready -->
+        <script type="text/javascript">
+        var chart;
+        $(document).ready(function() {
+            chart = new Highcharts.Chart({
+                chart: {
+                    renderTo: 'container',
+                    defaultSeriesType: 'bar'
+                },
+                title: {
+                    text: 'Historic World Population by Region'
+                },
+                xAxis: {
+                    categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
+                },
+                yAxis: {
+                    title: {
+                        text: 'Population (millions)',
+                    }
+                },
+                series: [{name: 'Year 1800',
+                          data: [107, 31, 635, 203, 2]},
+                         {name: 'Year 1900',
+                          data: [133, 156, 947, 408, 6]},
+                         {name: 'Year 2008',
+                          data: [973, 914, 4054, 732, 34]}]
+            });
+
+
+        });
+        </script>
+
+</head>
+    <body>
+
+        <!-- 3. Add the container -->
+        <div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
+
+
+    </body>
+
+</html>