javascript - 在 highcharts 工具提示中附加第三个 `<td>` 值

标签 javascript jquery highcharts

下面的代码片段显示类似 Colin Cockram : 601118.076 的工具提示与货币符号。 我如何附加我的第三个 <td>此工具提示中的值?

需要类似 Colin Cockram : 601118.076 - Survey : 891 的工具提示.

我怎样才能实现这个目标?

$(function () {
        $('#container').highcharts({
            data: {
                table: 'datatable'
            },
            chart: {
                type: 'column'
            },
            title: {
                text: 'Survey Reports Chart'
            },
            subtitle: {
                text: ''
            },
            yAxis: {
                allowDecimals: true,
                min: 0,
                title: {
                    text: 'Amount'
                }
            },
            tooltip: {
                formatter: function() {
                    return '<b>'+ this.point.name +'</b>: \u00a3'+Highcharts.numberFormat(this.point.y, 2);
                }
            },
            plotOptions: {column: {colorByPoint: true}},
            legend: {
                enabled: false
            },
            credits: {
                enabled: false
            },
        });
    });
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<table id="datatable" style="display:none;">
    <thead>
        <tr>
            <th></th>
            <th> Test </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Gavin Leney</td>
            <td>13592.400</td>
            <td>39</td>
        </tr>
        <tr>
            <td>Colin Cockram</td>
            <td>601118.076</td>
            <td>891</td>
        </tr>
        <tr>
            <td>Alan Alker</td>
            <td>152274.000</td>
            <td>235</td>
        </tr>

    </tbody>
</table>

最佳答案

有更好的方法来做到这一点,将数据源设置为 json 对象而不是 dataTable

使用系列将数据绘制到图表

series: [{ data: [{ name: 'Gavin Leney', y: 13592.400, z: '39' },{ name: 'Colin Cockram', y: 601118.076, z: '891' },{ name: 'Alan Alker', y: 152274.000, z: '235' }] }],

然后您就可以删除您的数据

data: { table: 'datatable' }, //This is no longer needed as you are feeding data with series. Also, now you can get rid of your entire html for data table.

请参阅下面的工作代码:[注意:我没有添加系列中的所有数据。]

    $(function () {
            $('#container').highcharts({
                
                chart: {
                    type: 'column'
                },
                title: {
                    text: 'Survey Reports Chart'
                },
                subtitle: {
                    text: ''
                },
                yAxis: {
                    allowDecimals: true,
                    min: 0,
                    title: {
                        text: 'Amount'
                    }
                },
                tooltip: {
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: \u00a3'+Highcharts.numberFormat(this.point.y, 2) +' - <b>Survey</b>: '+ this.point.z;
                    }
                },
                series: [{
                      data: [{
                         name: 'Gavin Leney',
                         y: 13592.400,
                         z: '39'
                     },{
                     name: 'Colin Cockram',
                     y: 601118.076,
                     z: '891'
                 },{
                     name: 'Alan Alker',
                     y: 152274.000,
                     z: '235'
                     }]
                 }],
                plotOptions: {column: {colorByPoint: true}},
                legend: {
                    enabled: false
                },
                credits: {
                    enabled: false
                },
            });
        });
    <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/data.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

关于javascript - 在 highcharts 工具提示中附加第三个 `<td>` 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40657432/

相关文章:

javascript - Highchart 库和响应式设计

javascript - 根据所做的选择环绕图像

javascript - jQuery 只允许数字、字母和连字符

javascript - 如何在 React 中正确切换元素(如果它在数组中)

javascript - 使页面部分填充浏览器高度

javascript - jQuery 多重替换

javascript - Highcharts重绘前一行仍然存在

javascript - Highcharts 不显示数据

javascript - 如何确定特定时间是否在javascript中的给定时间范围之间

javascript - 如果模型中不存在数据,则使用 django 保存数据,如果数据存在则更新