Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
SOLUTION
: I realized that the current Regional Setting of test environment is set to Turkish, and it uses comma for decimal symbol. In my local, it is set to UK, and that's the reason that the code works in my local and doesn't work in test. I guess I'll replace all commas with dots beforehand. Thanks for all the replies.
I'm trying to fill a bar chart with following data:
var oneToTen = [0,1,2,3,4,5,6,7,8,9,10];
var ticks = [[0, 'Atmosfer'],[1, 'Servis'],[2, 'Yemeklerimiz']];
var labels = ['Atmosfer','Servis','Yemeklerimiz'];
var mainQuest_d1 = 8,16666666666667;
var mainQuest_d2 = 7,95833333333333;
var mainQuest_d3 = 8,125;
var d_main_quest_bar = [[0, 8,16666666666667],[1, 7,95833333333333],[2, 8,125]];
I get this error:
Uncaught SyntaxError: Unexpected number
I can't see what's wrong the code above. It works fine in localhost, but when I publish it to the test server, it gives this error.
Complete code that's not yet rendered by Razor:
int i = 0;
int j = 0;
int m = 0;
@Html.Raw("var oneToTen = [0,1,2,3,4,5,6,7,8,9,10];");
@Html.Raw("var ticks = [");
if (Model.MainQuestionsRatingList != null)
foreach (var item in Model.MainQuestionsRatingList)
@Html.Raw("["+(j-1)+", '"+item.QuestionText+"']")
if (j != Model.MainQuestionsRatingList.Count) { @Html.Raw(","); }
@Html.Raw("];");
@Html.Raw("var labels = [");
if (Model.MainQuestionsRatingList != null)
foreach (var item in Model.MainQuestionsRatingList)
@Html.Raw("'"+item.QuestionText+"'")
if (m != Model.MainQuestionsRatingList.Count) { @Html.Raw(","); }
@Html.Raw("];");
if (Model.MainQuestionsRatingList != null)
foreach (var item in Model.MainQuestionsRatingList)
@Html.Raw("var mainQuest_d" + i + " = " + item.Avg + ";");
i = 0;
@Html.Raw("var d_main_quest_bar = [");
if (Model.MainQuestionsRatingList != null)
foreach (var item in Model.MainQuestionsRatingList)
@Html.Raw("[" + (i-1) + ", "+item.Avg+"]");
if (i != Model.MainQuestionsRatingList.Count) { @Html.Raw(","); }
@Html.Raw("];");
data.push({
label: labels,
data: d_main_quest_bar,
bars: {
show: true,
barWidth: 0.2,
order: 1
EDIT: I ran the same code in my local, and figured out that the commas are automatically replaced with dots and that's why it works in my local as @T.J. Crowder said. But it doesn't happen when I run it in test. How is that possible?
–
–
–
You can't use localized decimal separator characters in JavaScript source code. You must use .:
var mainQuest_d1 = 8.16666666666667;
var mainQuest_d2 = 7.95833333333333;
var mainQuest_d3 = 8.125;
See What is the decimal separator symbol in JavaScript?
It should be obvious that , has another meaning already. How many elements do you expect the array
[0, 8,16666666666667]
to contain?
–
–
–
You shouldn't use commas in your numbers. Use a decimal place instead. Commas are special characters reserved for other uses, such as separators in arrays and function parameters.
For example:
8,16666666666667
should be
8.16666666666667
You have a few instances so here is the full code written correctly:
var oneToTen = [0,1,2,3,4,5,6,7,8,9,10];
var ticks = [[0, 'Atmosfer'],[1, 'Servis'],[2, 'Yemeklerimiz']];
var labels = ['Atmosfer','Servis','Yemeklerimiz'];
var mainQuest_d1 = 8.16666666666667;
var mainQuest_d2 = 7.95833333333333;
var mainQuest_d3 = 8.125;
var d_main_quest_bar = [[0, 8.16666666666667],[1, 7.95833333333333],[2, 8.125]];
(there are 6 changes in total across the last 4 lines)
<script type="text/javascript">
var oneToTen = [0,1,2,3,4,5,6,7,8,9,10];
var ticks = [[0, 'Atmosfer'],[1, 'Servis'],[2, 'Yemeklerimiz']];
var labels = ['Atmosfer','Servis','Yemeklerimiz'];
var mainQuest_d1 = 8.16666666666667;
var mainQuest_d2 = 7.95833333333333;
var mainQuest_d3 = 8.125;
var d_main_quest_bar = [[0, 8.16666666666667],[1, 7.95833333333333],[2, 8.125]];
</script>
Source: http://en.wikipedia.org/wiki/JavaScript_syntax#Number
–
var mainQuest_d1 = 8,16666666666667;
var mainQuest_d2 = 7,95833333333333;
var mainQuest_d3 = 8,125;
You can't use commas there.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.