如何使用Javascript而不是Jquery动态地更改HighCharts中的系列

时间:2018-04-24 05:58:47

标签: javascript json highcharts

我搜遍了Stack Overflow网站,找不到完美的解决方案。所以擅长HighCharts的人可以帮助我。 任何答案都会得到赞赏.....请用Javascript回答而不是Jquery ....     通常我会根据我的用法在系列中创建空变量。但是我希望它们在JSON文件中添加名称和数据时动态创建...我将在下面附加我的JSON文件...所以请检查出来..

var i = 1,
            chart;
        $(function () {
            chart = Highcharts.chart('container', {
                chart: {
                    type: 'bar'
                },
                title: {
                    text: ''
                },
                subtitle: {
                    text: "This is a sample"
                },
                xAxis: {
                    categories: ['Physics', 'Chemistry', 'Maths', 'Science', 'Telugu', 'English']
                },
                yAxis: {
                    title: {
                        text: 'Marks'
                    }
                },
                series: [
                    {
                        name: "",
                        data: []
                    },
                    {
                        name: "",
                        data: []
                    },
                    {
                        name: "",
                        data: []
                    }
                ]
            });
        });

This is my json and when ever I add some name and data I want Series in Chart to add it....



        {
    "title":"My first chart",
    "dataa": 
    [
        {
            "name": "Unit Test 1",
            "data":[1,13,15,17,40,50,80]
        },
        {
            "name": "Unit Test 2",
            "data":[2,20,50,40,20,50,15]
        },
        {
            "name": "Unit Test 3",
            "data":[3,50,40,10,30,40,25]
        }
    ],

    "heading" :[  
    {
        "text":"S.No"
    },
    {
        "text":"Phy"
    },
    {
        "text":"Che"
    },
    {
        "text":"Mat"
    },
    {
        "text":"Sci"
    },
    {
        "text":"Tel"
    },
    {
        "text":"Eng"
    }
    ]  
}

0 个答案:

没有答案