Coding Standard - Richard, what do you use?


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Stu Andrews on 18th April 2017
Hi Richard,

So I'm just wondering, what standard you use (one or the other or both) when coding a script for rGraph.

Do you declare the graph, and put all the settings inline, OR, do you declare the graph and use the graph variable to assign the values?

IE.

var myGraph = new RGraph.Bar({
   id: "graph1",
   data: [1,2],
   options: {
     colors: ["something","something2"],
     ...
   }
});

OR

var myGraph = new RGraph.Bar("graph1",[1,2]);
myGraph.Set("chart.colors", ["something", "something2"]);
...

Looking for what you reckon is the best, if there are better ways to do it in certain situations, etc etc.

Cheers.
Posted by Richard on 18th April 2017
Hi there,

Mostly I do it when creating the chart - as used all over the site, like this:

     var bar = new RGraph.SVG.Bar({
         id: 'chart-container',
         data: [100,300,400,500],
         options: {
             title: 'Dropbox userbase',
             hmargin: 50,
             colors: ['#DE2E2D'],
             backgroundGridLinewidth: 2,
             backgroundGridColor: 'gray',
             backgroundGridVlines: false,
             backgroundGridBorder: false,
             yaxisUnitsPost: ' million',
             gutterTop: 50,
             gutterLeft: 100,
             titleX: 100,
             titleY: 30,
             titleHalign: 'left',
             titleBold: true,
             titleItalic: true,
             yaxis: false,
             xaxis: false,
             xaxisTextColor: 'gray',
             yaxisTextColor: 'gray',
             xaxisLabels: ['November 2012','May 2014','June 2015','March 2016'],
             textSize: 9
         }
     }).wave();

And then if you need to set properties after you've created the chart you can use the setter like this:

bar.set({
     colors: ['pink'],
     textSize: 12,
     xaxis: true,
     yaxis: true
});

RGraph.SVG.redraw();


Richard
Posted by Stu Andrews on 19th April 2017
Thanks Richard, really appreciate the info!

Add a reply

 




« Back to message list
RGraph on social media