Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get my date value to parse correct format of date but however i am experiencing the following error on the console debugging interface :

ReferenceError: dt is not defined --> error

JavaScript
function drawVisualization(dataValues, chartTitle, columnNames, categoryCaption) {
            if (dataValues.length < 1)
                return;
				
            var data = new google.visualization.DataTable();
            data.addColumn('string', columnNames.split(',')[0]);
            data.addColumn('number', columnNames.split(',')[1]);
            data.addColumn('string', columnNames.split(',')[2]);
            data.addColumn('datetime', columnNames.split(',')[3]);

            for (var i = 0; i < dataValues.length; i++) {

                
                var date = new Date(parseInt(dt.getValue(row, 3))); // error line

                data.addRow([dataValues[i].ColumnName, dataValues[i].Value, dataValues[i].Type, date]);
            }


            var dateFormatter = new google.visualization.DateFormat({ pattern: 'dd MM yyyy' });
            var line = new google.visualization.ChartWrapper({
                'chartType': 'LineChart',
                'containerId': 'PieChartContainer',
                'options': {
                    'width': 950,
                    'height': 450,
                    'legend': 'right',
                    'hAxis': {
                        'format': "dd-MM-yyyy",
                        'hAxis.maxValue': 'viewWindow.max',
                        'maxValue': new Date(2014, 05, 30), 'minValue': new Date(2014, 04, 05),
                        'viewWindow': { 'max': new Date(2014, 05, 30) },
                    },
                    'title': chartTitle,
                    'chartArea': { 'left': 100, 'top': 100, 'right': 0, 'bottom': 100 },
                    'tooltip': { isHtml: true }
                },
                'view': {
                    'columns': [{

                        type: 'string',
                        label: data.getColumnLabel(3),
                        calc: function (dt, row) {
                            var date = new Date(parseInt(dt.getValue(row, 3)));
                            return dateFormatter.formatValue(date);
                        }
                    }, 1, {
                        type: 'string',
                        role: 'tooltip',
                        calc: function (dt, row) {
                            return 'Name: ' + dt.getValue(row, 0) + ', Decimal Price: ' + +dt.getValue(row, 1) + ', Date: ' + +dt.getFormattedValue(row, 3);
                        }
                    }]
                }
            });

            new google.visualization.Dashboard(document.getElementById('PieChartExample')).bind([categoryPicker], [line]).draw(data);
        }


I have also tried editing to the error line with the following:
var date = new Date(parseInt(dataValues[i].getValue(row, 3)));

However the above line code shows a similar error message such as:
Uncaught ReferenceError: row is not defined --> error

Please advice. Many thanks.
Posted

1 solution

What i am seeing that 'dt' and 'row' are not declared anywhere before being used here.

Do you mean to use 'data' in place of 'dt' ?
 
Share this answer
 
v2
Comments
miss786 14-May-14 5:19am    
Thank you for your quick response. I was originally using (data) however this shows the date format as 'NaN'. I would like to know how can I use (dt) in the parseInt line code. The (dt) value parse the date as string. Please advice if possible. Many Thanks.
SRS(The Coder) 14-May-14 5:28am    
By the way you have not explained what is 'dt' here neither declared it any where in code and just using it, so it is throwing error. If you want to use 'dt' then you need to declare or create the datatable with this name and use it.<br>
 <br>
There is another method in asp.net named as 'TryParse' which will be helpfull to check whether anything can be parsed to desired type or not first, you can use it. If it can be then parse or else not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900