Using the CSV reader, carriage returns and newlines in labels doesn'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

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

Don't work
  var bar = new RGraph.Bar({
                 id: 'csva',
                 data: data,
                 options: {
                     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.

Posted by Richard on 28th February 2016

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)!

Posted by Lars Larsson on 28th February 2016

Thanks for quick reply.

Add a reply

« Back to message list