如何从javascript列表中删除双引号? [英] How to remove double quotes from javascript list?

查看:103
本文介绍了如何从javascript列表中删除双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友......



我正在使用高图表,我引用它的例子,因为数据是硬编码的。这就是它在图表上显示正确数据的原因。但在我的情况下,Data来自SQL Server如下



Hello Friends...

I m working with high-charts, I refer its examples in that data is hard coded. That's why it shows correct data on charts. but in my case, Data comes from SQL Server as follows

public partial class Default : System.Web.UI.Page
    {
        public List<string> ObjMonthList = new List<string>();
        public List<decimal> ObjMumbaiValues = new List<decimal>();
        public List<decimal> ObjNewYorkValues = new List<decimal>();
        public List<decimal> ObjBerlinValues = new List<decimal>();
        public JavaScriptSerializer ObjJavaScriptSerializer = new JavaScriptSerializer();

        protected void Page_Load(object sender, EventArgs e)
        {
            GetData();
        }

        void GetData()
        {
            SqlConnection ObjConnection = new SqlConnection("Data Source=abc; Initial Catalog=test; Integrated Security=True;");
            SqlDataAdapter ObjDataAdapter = new SqlDataAdapter("select * from test", ObjConnection);
            DataTable ObjTable = new DataTable();
            ObjDataAdapter.Fill(ObjTable);
            GridView1.DataSource = ObjTable;
            GridView1.DataBind();

            for (int i = 0; i < ObjTable.Rows.Count; i++)

            {

                ObjMonthList.Add(ObjTable.Rows[i][0].ToString());

            }





        }

    }





我已将ObjMonthList传递给Javascript,如下所示



var monthnames =<%= ObjJavaScriptSerializer。 Serialize(ObjMonthList)%> ;;



它显示月份名中的数据如下





I have passed ObjMonthList to Javascript as follows

var monthnames = <%=ObjJavaScriptSerializer.Serialize(ObjMonthList) %>;

It shows data in monthnames as follows

var monthnames = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];

        $(function () {
            $('#container').highcharts({
                title: {
                    text: 'Monthly Average Temperature',
                    x: -20 //center
                },
                subtitle: {
                    text: 'Source: WorldClimate.cyesom',
                    x: -20
                },
                xAxis: {
                    categories: monthnames
                },
                yAxis: {
                    title: {
                        text: 'Temperature (°C)'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    valueSuffix: '°C'
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: [{
                    name: 'Tokyo',
                    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
                }, {
                    name: 'New York',
                    data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
                }, {
                    name: 'Berlin',
                    data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
                }, {
                    name: 'London',
                    data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
                }]
            });
        });





但它没有按类别显示数据。它只显示如下变量名称





But it doesn't show data in categories. it shows only variable name as follows

xAxis: {
                   categories: monthnames
               },





请帮助我。



Please help me.

推荐答案

(function(){
(function () {


' #container')。highcharts({
title :{
text:' 每月平均温度
x:-20 < span class =code-comment> // center
},
副标题:{
text:< span class =code-string>' 来源:WorldClimate.cyesom'
x:-20
},
xAxis:{
类别:monthnames
},
yAxis:{
title:{
text:' 温度(°C) '
},
plotLines:[{
value 0
宽度: 1
color:' #808080'
}]
},
工具提示:{
valueSuffix: ' °C'
},
legend:{
layout:' vertical'
align:' 右击t'
verticalAlign:' middle'
borderWidth : 0
},
系列:[{
name:' 东京'
数据:[ 7 0 6 9 9 5 14 5 18 2 21 5 25 2 ,< span class =code-digit> 26 。 5 23 3 18 3 13 9 9 6 ]
},{
name:' 纽约'
data:[ - 0。 2 0 8 5 7 11 3 17 0 22 0 24 8 24 1 20 1 14 1 8 6 2 5 ]
}, {
name:' Berlin'
data:[ - 0。< span class =code-digit> 9 , 0 6 3 5 8 4 13 5 17 0 18 6 17 9 14 3 9 0 3 9 1 0 ]
},{
name:' 伦敦'
数据:[ 3 9 4 2 5 7 8 5 11 9 15 2 17 0 16 6 14 2 10 3 6 6 4 8 ]
}]
});
});
('#container').highcharts({ title: { text: 'Monthly Average Temperature', x: -20 //center }, subtitle: { text: 'Source: WorldClimate.cyesom', x: -20 }, xAxis: { categories: monthnames }, yAxis: { title: { text: 'Temperature (°C)' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { valueSuffix: '°C' }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'middle', borderWidth: 0 }, series: [{ name: 'Tokyo', data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] }, { name: 'New York', data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] }, { name: 'Berlin', data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] }, { name: 'London', data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] }] }); });





但它没有按类别显示数据。它只显示如下变量名称





But it doesn't show data in categories. it shows only variable name as follows

xAxis: {
                   categories: monthnames
               },





请帮助我。



Please help me.


如果你在单引号上使用数组值

ex:

if u use on single quotes for array values
ex:
ar A = ['Sunday','Monday','Tuesday','Wednesday','Thursday']
array = A + ""


这篇关于如何从javascript列表中删除双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆