具有 x 和 y 值的折线图

发布于 2024-12-28 18:51:25 字数 2335 浏览 0 评论 0原文

我正在尝试构建我的第一个图表(折线图)。我已经拉出了 x 轴和 y 轴以及线的名称。但是,当我尝试推送数据时,它不显示。它只显示一个空白页。这是我的代码,有人可以帮忙吗?

$(document).ready(function() {
    var Options = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'line',
            marginRight: 130,
            marginBottom: 40
        },
        title: {
            text: 'Weight-for-age percentiles:',
            x: -20 
        },
        subtitle: {
            text: 'boys, 5 to 19 years',
            x: -20
        },
        xAxis: {
            title: {
                text: 'Age (Years)'
            },
            min:5,
        },
        yAxis: {

            title: {
            text: 'Weight (Kg)'
            },
            min: 5,

        },
        tooltip: {
            formatter: function() {
            return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y +'Kg.';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [ ]
    });

    // Ajax call:-      

    $.get('Newchart.aspx', function(data) {   

        var fulldata = document.getElementById("MyHiddenField").value;                     
        var lines = fulldata.split('$');                    
        var Series = {
            data: []                             
        };


    $.each(lines, function(lineno, line){                                   

        \\i.e line[0] ="Red#[5.4,13.7235931],[7.3,15.10509471],[8,16.95593574]"
        \\  line[1]="Green#[5,14.7235931],[6,16.36275897],[7,18.10509471]"
        \\  line[2]="Black#[5,15.09371211],[6,16.79146158],[7,18.58739757]"
        \\ where  Red,Green,Black are the names of the line and rest is [x,y]....

    }); 
});            

// The HTML:-

<div>
    <div id="container" style="width: 950px; height: 500px; margin: 0 auto">
    </div>
    <input type="hidden" id="MyHiddenField" name="MyHiddenField" value="Red#[5.4,13.7235931],[7.3,15.10509471]$Green#[5,14.7235931],[6,16.36275897],[7,18.10509471]$Black#[5,15.09371211],[6,16.79146158],[7,18.58739757]" />
</div>

任何示例/代码将不胜感激!

提前致谢..

I am trying to build my first chart (lines chart). I got as far as pulling up x and y axis and Name of the line. However when I try and push the data, it does not display. It only displays a blank page. Here is my code, can somebody help?

$(document).ready(function() {
    var Options = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'line',
            marginRight: 130,
            marginBottom: 40
        },
        title: {
            text: 'Weight-for-age percentiles:',
            x: -20 
        },
        subtitle: {
            text: 'boys, 5 to 19 years',
            x: -20
        },
        xAxis: {
            title: {
                text: 'Age (Years)'
            },
            min:5,
        },
        yAxis: {

            title: {
            text: 'Weight (Kg)'
            },
            min: 5,

        },
        tooltip: {
            formatter: function() {
            return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y +'Kg.';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [ ]
    });

    // Ajax call:-      

    $.get('Newchart.aspx', function(data) {   

        var fulldata = document.getElementById("MyHiddenField").value;                     
        var lines = fulldata.split('

Any examples/code would be greatly appreciated!

Thanks in Advance..

); var Series = { data: [] }; $.each(lines, function(lineno, line){ \\i.e line[0] ="Red#[5.4,13.7235931],[7.3,15.10509471],[8,16.95593574]" \\ line[1]="Green#[5,14.7235931],[6,16.36275897],[7,18.10509471]" \\ line[2]="Black#[5,15.09371211],[6,16.79146158],[7,18.58739757]" \\ where Red,Green,Black are the names of the line and rest is [x,y].... }); }); // The HTML:- <div> <div id="container" style="width: 950px; height: 500px; margin: 0 auto"> </div> <input type="hidden" id="MyHiddenField" name="MyHiddenField" value="Red#[5.4,13.7235931],[7.3,15.10509471]$Green#[5,14.7235931],[6,16.36275897],[7,18.10509471]$Black#[5,15.09371211],[6,16.79146158],[7,18.58739757]" /> </div>

Any examples/code would be greatly appreciated!

Thanks in Advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2025-01-04 18:51:25

将系列添加到图表的两种方式

  1. 在 ajax 调用成功结束时创建整个图表(从而在调用 new Highcharts.Chart 之前创建系列),请参阅下面的代码
  2. 以编程方式添加指向(已经)渲染的图表

示例1(没有尝试这个,我只是记住了图表结构):

// Create the options object without calling New Highcharts.Chart
var Options = { chart: { renderTo: 'container' } };

$.get('Newchart.aspx', function(data) {
   var fulldata = document.getElementById("MyHiddenField").value;
   var lines = fulldata.split('

示例2:看一下此处。基本上创建图表的新实例,然后在 success 函数中调用 addSeries() 。

); var series = []; // Array of series to be filled // Then loop each line and create one series for each line $.each(lines, function(lineno, line) { // Extract name and x/y values (e.g. [[x1, y1], [x2, y2]] from current line var name, values; var current = { name : name, data : values }; series.push(current); // Push current series }); // Inizialize the chart Options.series = series; var chart = new Highcharts.Chart(Options); });

示例2:看一下此处。基本上创建图表的新实例,然后在 success 函数中调用 addSeries() 。

Two way of adding series to your chart:

  1. Create the whole chart when ajax call ends successfully (thus creating series prior to invoke new Highcharts.Chart), see code below
  2. Programmatically adding points to the (already) rendered chart

Example 1 (didn't try this, i'm just remembering the chart struncture):

// Create the options object without calling New Highcharts.Chart
var Options = { chart: { renderTo: 'container' } };

$.get('Newchart.aspx', function(data) {
   var fulldata = document.getElementById("MyHiddenField").value;
   var lines = fulldata.split('

Example 2: take a look here. Basically create a new instance of the chart and then call addSeries() inside success function.

); var series = []; // Array of series to be filled // Then loop each line and create one series for each line $.each(lines, function(lineno, line) { // Extract name and x/y values (e.g. [[x1, y1], [x2, y2]] from current line var name, values; var current = { name : name, data : values }; series.push(current); // Push current series }); // Inizialize the chart Options.series = series; var chart = new Highcharts.Chart(Options); });

Example 2: take a look here. Basically create a new instance of the chart and then call addSeries() inside success function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文