0

当用户输入值并单击按钮时,尝试将单个数据点添加到系列中。

<div data-id="metricModel">
    <div class="edit">
      <input type="text" class="metric">
      <button class="submit">Confirm</button>
    </div>
  </div>

  <script>
    $('.submit').click(function() {
      var self = $(this);
      var edit = self.closest('.edit');
      var val = edit.find('.metric').val();
      var chart = $('#session').highcharts();
      var date = Date.UTC(2012, 11, 8);
      chart.series[0].addPoint([date, val]);
    });

var dates = [
      [Date.UTC(2011, 08, 1), -0.2],
      [Date.UTC(2011, 11, 1), 0.8],
      [Date.UTC(2012, 08, 1), 5.7],
      [Date.UTC(2012, 11, 6), 11.3]
    ];

$(function () {
      var options = {
        chart: {
          type: 'line',
          marginRight: 130,
          marginBottom: 25
        },
        title: {
          text: 'Power'
        },
        xAxis: {
          type: 'datetime'
        },
        yAxis: {
          title: {
            text: "Power"
          },
          plotLines: [{
            value: 0, 
            width: 1,
            color: '#808080'
          }]
        },
        legend: {
          layout: 'vertical',
          align: 'right',
          verticalAlign: 'top',
          x: -10,
          y: 100,
          borderWidth: 2
        },
        series: [{
          name: 'John',
          data: dates
          }]
        };
      $('#session').highcharts(options);
    });

这是错误:

Error: Problem parsing d="M 118.65966386554622 313.6 L 835.046218487395 182.2 L 1085.1302521008404 32.2 L 1090.3403361344538 " highcharts.js:9
A                       highcharts.js:9
ra.attr                 highcharts.js:42
e                       highcharts.js:25
cZ.run                  jquery.min.js:2
i                       jquery.min.js:2
p.fx.tick               jquery.min.js:2

关于如何使它工作的任何建议?

4

1 回答 1

0

问题似乎是这样的

var val = edit.find('.metric').val();

它是typeof字符串,chart.series[0].addPoint([date, val]);并且必须是数字类型

更正:
chart.series[0].addPoint([date, +val]);chart.series[0].addPoint([date, parseFloat(val)]);

于 2013-06-09T03:11:32.283 回答