【问题标题】:Use HTML Textbox value as a HighCharts Percentage使用 HTML 文本框值作为 HighCharts 百分比
【发布时间】:2015-02-19 07:57:24
【问题描述】:

我有以下代码:

HTML 代码

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

JavaScript

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                            ]
        }]
    });
});

此代码的输出是一个饼图,其中一个 div 内的值为 Chrome(15)、IE(31) 和 Firefox(53)。

这是一组文本框和一个按钮:

    Number of Arson: <input type="text" id="arson" name="arson">
    Number of Homicide: <input type="text" id="homicide" name="homicide">
    Number of Physical Injuries: <input type="text" id="physicalinjuries" name="physicalinjuries">
    Number of Carnapping: <input type="text" id="carnapping" name="carnapping">
    Number of Ethical Law Violation: <input type="text" id="elv" name="elv">
<input type="submit" id = "chart" value="Submit">

点击按钮时是否可以传递文本框的值并将其用作图表(PIE)中的自定义百分比(切片)?

我的目标是调用一个 PHP 函数,该函数将使用从表名中选择(计数)并将其传递到文本框,然后当按下按钮时,该值将被发送到 PIE 图表。

【问题讨论】:

标签: javascript php jquery html highcharts


【解决方案1】:
$('#chart').on('click', function() {

   var value = Number($('#arson').val());

   var myChart = $('#container').highcharts();

   myChart.series[0].data[0].update(value); 

});

【讨论】:

  • 您能向我解释一下吗?只是一个文本框的例子。如果你没问题
  • 老实说我不知道​​如何尝试
  • 谢谢您,先生,我会等待非常感谢您
  • 好的,我添加了 cmets 并用你的标签交换了部分,这样更有意义。
  • 先生,帮了大忙
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多