To fix the issue with the blank line at the end of the file, replace this
line from the csvToDataTable function:
rawData.push(row);
with this:
if (i === 0 || row.length === rawData[0].length) {
rawData.push(row);
}
That will add the row of data only if it contains a number of elements
equal to the number of elements in the header row, which ensures that you
don't add any rows that are malformed due to a wrong number of elements
(like having any empty row).
On Friday, August 1, 2014 11:06:28 PM UTC-4, [email protected] wrote:
>
> One other quick question, any idea why the filename:
>
> Current - Log.csv doesnt work yet
> Current- Log.csv does?
>
> Another bummer of the software that makes the csv is that the filename is
> hard coded to "Log - Current.csv"
> Strange that 1 space works but 2 doesnt. any thoughts?
>
>
>
> On Friday, August 1, 2014 7:19:46 PM UTC-7, [email protected] wrote:
>>
>> It works!!! YESS!!!! Thank you sooo much!!
>>
>> I spent a couple hours on it last night and it was racking my brain. The
>> test values worked, but my real values with different headings then Temp1
>> Temp2 etc wasnt working. I wasnt sure if it was the names or values or
>> what, then the test values wouldnt work..was killing me! Turned out it
>> was a line return at the end of the csv file! Got rid of that and bam,
>> magical!!!
>>
>> So one quick question then, is there a way to accommodate for that line
>> return? The program that is generating the csv doesnt give me the option.
>> This is too cool, thank you thank you!
>>
>> On Thursday, July 31, 2014 9:05:13 PM UTC-7, Andrew Gallant wrote:
>>>
>>> Oops, sorry, my mistake. You need to add the csvToDataTable function I
>>> posted above to the javascript (just paste it in before the drawChart
>>> function).
>>>
>>> On Thursday, July 31, 2014 5:38:29 PM UTC-4, [email protected] wrote:
>>>>
>>>> There is Uncaught ReferenceError: csvToDataTable is not defined
>>>>
>>>> btw I set the path to the following: its in the root directory along
>>>> with mychart.html
>>>>
>>>> url: '/current.csv'
>>>> ,
>>>>
>>>>
>>>> On Thursday, July 31, 2014 5:57:50 AM UTC-7, Andrew Gallant wrote:
>>>>>
>>>>> Open the page in Chrome and open the developer's console
>>>>> (ctrl+shift+j). Are there any error messages?
>>>>>
>>>>> On Thursday, July 31, 2014 12:44:54 AM UTC-4, [email protected]
>>>>> wrote:
>>>>>>
>>>>>> Andrew, wow, thanks again, Im dying to see this working! I changed
>>>>>> the path per your instructions but cant seem to get the page to render
>>>>>> properly. I have it in the root dir of my web server but if I open a
>>>>>> browser and point to that file it comes up as a white page. If I view
>>>>>> the
>>>>>> source I see it exactly as the page is saved, its like it didnt execute
>>>>>> the
>>>>>> html code just loaded the page. Does that make sense? If I point to my
>>>>>> index.html file that works fine.
>>>>>> Im using IIS on Windows 7 to serve the page. Anything special I need
>>>>>> to turn on?
>>>>>>
>>>>>>
>>>>>> On Monday, July 28, 2014 4:48:17 PM UTC-7, Andrew Gallant wrote:
>>>>>>>
>>>>>>> Storing the CSV file inside your web directory makes this much
>>>>>>> easier, as this allows you to use AJAX to fetch the data directly
>>>>>>> instead
>>>>>>> of writing some server-sude code to get the CSV. The jQuery library
>>>>>>> provides a handy shortcut for writing AJAX:
>>>>>>>
>>>>>>> $.ajax({
>>>>>>> url: '/path/to/data.csv', // this is the path in your web
>>>>>>> directory, not your system directory
>>>>>>> dataType: 'text',
>>>>>>> success: function (csv) {
>>>>>>> // code to draw chart
>>>>>>> }
>>>>>>> });
>>>>>>>
>>>>>>> I attached an HTML file that ties all of this together.
>>>>>>>
>>>>>>> On Sunday, July 27, 2014 2:01:35 PM UTC-4, [email protected] wrote:
>>>>>>>>
>>>>>>>> Wow, thank you so much Andrew. I would have never figured that
>>>>>>>> parsing out...
>>>>>>>>
>>>>>>>> Either one of those examples to turn stuff on or off would work.
>>>>>>>> The site is going to be only accessed by me so it doesnt have to be
>>>>>>>> super
>>>>>>>> sexy.
>>>>>>>>
>>>>>>>> The csv file is hosted on the machine that is running the
>>>>>>>> webserver. I can store its location anywhere including the root dir
>>>>>>>> of the
>>>>>>>> website. Hopefully that makes it a bit easier.
>>>>>>>> Thanks again for all your help on this!
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sunday, July 27, 2014 6:23:30 AM UTC-7, Andrew Gallant wrote:
>>>>>>>>>
>>>>>>>>> For turning on and off the lines, would either of these work for
>>>>>>>>> you?
>>>>>>>>>
>>>>>>>>> http://jsfiddle.net/asgallant/WaUu2/
>>>>>>>>> http://jsfiddle.net/asgallant/6gz2Q/
>>>>>>>>>
>>>>>>>>> If you can't change the format of the CSV, then you'll have to
>>>>>>>>> manually parse it, but your structure is simple enough that this
>>>>>>>>> shouldn't
>>>>>>>>> present a problem. Once it is loaded in the browser, this should
>>>>>>>>> suffice
>>>>>>>>> to transform it into a DataTable for the charts:
>>>>>>>>>
>>>>>>>>> function csvToDataTable (csv) {
>>>>>>>>> // split the csv on line breaks
>>>>>>>>> var csvRows = csv.split(/\r{0,1}\n/g);
>>>>>>>>> var rawData = [], row, match, year, month, day, hours,
>>>>>>>>> minutes, seconds;
>>>>>>>>> for (var i = 0; i < csvRows.length; i++) {
>>>>>>>>> row = csvRows[i].split(',');
>>>>>>>>> if (i != 0) {
>>>>>>>>> // assumes dates are in the format "MM/dd/yyyy
>>>>>>>>> HH:mm:ss"
>>>>>>>>> match = row[0].match(/(\d{2})\/(\d{2})\/(\d{4})
>>>>>>>>> (\d{2}):(\d{2}):(\d{2})/);
>>>>>>>>> year = parseInt(match[3], 10);
>>>>>>>>> month = parseInt(match[1], 10) - 1; // convert to
>>>>>>>>> javascript's zero-indexed months
>>>>>>>>> day = parseInt(match[2], 10);
>>>>>>>>> hours = parseInt(match[4], 10);
>>>>>>>>> minutes = parseInt(match[5], 10);
>>>>>>>>> seconds = parseInt(match[6], 10);
>>>>>>>>> row[0] = new Date(year, month, day, hours, minutes,
>>>>>>>>> seconds);
>>>>>>>>> for (var j = 1; j < row.length; j++) {
>>>>>>>>> // convert the strings to numbers
>>>>>>>>> // change to parseFloat if your numbers can be
>>>>>>>>> floats
>>>>>>>>> row[j] = parseInt(row[j]);
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>> rawData.push(row);
>>>>>>>>> }
>>>>>>>>> return google.visualization.arrayToDataTable(rawData);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> Loading the data might be a bit tricky; is this going to be hosted
>>>>>>>>> on your local PC or on a website? Do you have the choice of where
>>>>>>>>> the CSV
>>>>>>>>> gets stored?
>>>>>>>>>
>>>>>>>>> On Saturday, July 26, 2014 2:40:51 PM UTC-4, [email protected]
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Well Im certainly willing to try. I've looked a bunch of
>>>>>>>>>> examples but just cant seem to get my data loaded,at least if I
>>>>>>>>>> include the
>>>>>>>>>> date field. I manually put a ' ' around date and that worked except
>>>>>>>>>> I have
>>>>>>>>>> no control over the format of the csv to actually include those ' '
>>>>>>>>>>
>>>>>>>>>> But sure, lets give this a shot.
>>>>>>>>>>
>>>>>>>>>> By turning off / isolate values I have 10 temperatures, I'd like
>>>>>>>>>> to be able to display just one or two of them or all 10. Having 10
>>>>>>>>>> lines
>>>>>>>>>> gets a bit messy, plus this might grow to more in the future.
>>>>>>>>>>
>>>>>>>>>> Both of those zooms are brilliant. I was checking out the google
>>>>>>>>>> example when I was researching this the last couple weeks, thats
>>>>>>>>>> exactly
>>>>>>>>>> what I was envisioning.
>>>>>>>>>>
>>>>>>>>>> Thanks for offering to help out!
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Friday, July 25, 2014 6:36:49 PM UTC-7, Andrew Gallant wrote:
>>>>>>>>>>>
>>>>>>>>>>> This is probably easy to do, and if you're feeling adventurous,
>>>>>>>>>>> we can help you save a bit of cash and do this yourself.
>>>>>>>>>>>
>>>>>>>>>>> A few key questions:'
>>>>>>>>>>>
>>>>>>>>>>> What do you mean by "turn off / isolate certain values"?
>>>>>>>>>>>
>>>>>>>>>>> Would something like this
>>>>>>>>>>> <https://developers.google.com/chart/interactive/docs/gallery/controls#chartrangefilter>
>>>>>>>>>>> or
>>>>>>>>>>> this <http://jsfiddle.net/asgallant/fgM4V/> work for you to
>>>>>>>>>>> zoom your data?
>>>>>>>>>>>
>>>>>>>>>>> On Friday, July 25, 2014 2:26:08 PM UTC-4, [email protected]
>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> I have a few bucks to pay someone to write a fairly basic chart
>>>>>>>>>>>> for me. I have a csv file on the local machine that will be
>>>>>>>>>>>> serving the
>>>>>>>>>>>> chart web page. The file is updated every few minutes recording
>>>>>>>>>>>> temperature values and a time stamp. All the chart needs to do is
>>>>>>>>>>>> load the
>>>>>>>>>>>> data and display it. I would like the ability to turn off /
>>>>>>>>>>>> isolate
>>>>>>>>>>>> certain values and also zoom into a section of the chart.
>>>>>>>>>>>> Every couple months the data is reset so the max is going to be
>>>>>>>>>>>> 3 months of data. Here is what the .csv looks like.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Time,Temp1,Temp2,Temp3,Temp4,Temp5,Temp6,Temp7,Temp8,Temp9,Temp10
>>>>>>>>>>>> 03/03/2014 00:26:37,52,77,79,66,63,66,86,72,66,57
>>>>>>>>>>>> 03/03/2014 00:27:37,52,78,80,66,63,66,87,72,67,57
>>>>>>>>>>>> 03/03/2014 00:28:38,52,79,84,67,64,69,86,72,68,52
>>>>>>>>>>>> 03/03/2014 00:29:39,52,77,88,68,66,76,83,72,68,51
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.