Using the CVS reader, carriage returns and newlines in labels dosen't work


« 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 Lars Larsson on 28th February 2016
Hi,

I can't use newlines in label when I use cvs reader
I have tried this. One at time.
Textfile:
2016\n02-01, 79,569
or
'2016\n02-01', 79,569
or
['2016\n02-01', 79,569]



Don't work
  var bar = new RGraph.Bar({
                 id: 'csva',
                 data: data,
                 options: {
                     textSize:10,
                     gutterTop: 50,
                     gutterBottom: 45,
                   --> labels:labels,
                     title: 'A chart using theCSVreader',
                     colors: ['red'],
                     strokestyle: 'white',
                     noxaxis: true,
                     shadowColor: '#aaa'

but if i dont read it from file it works.

                labels:['2016\n02-01'],
Posted by Richard on 28th February 2016
Hi,

The CSV reader won't convert the CRLF to real carriage returns/newlines for you - it just reads the file and gives you back the contents. You can convert the CRLFs like this though:

for (var i=0; i<labels.length; ++i) {
     labels[i] = labels[i].replace(/(\\r)?\\n/, "\n");
}

It just loops through your labels and converts any \n or \r\n to a real newline. Put it before you create the chart.

PS Nice to see the CAPTCHA working (though I've just noticed I need to implement it for replies)!





Richard
Posted by Lars Larsson on 28th February 2016
Hi,


Thanks for quick reply.

Add a reply

 




« Back to message list
RGraph on social media