简体   繁体   English

Highcharts工具提示显示额外数据

[英]Highcharts tool-tip show extra data

I am trying to add data to my tool-tips in highcharts. 我正在尝试将数据添加到图表中的工具提示中。 I import data with CSV, but for this code I put the data in a var. 我使用CSV导入数据,但是对于此代码,我将数据放入var中。 Normally my data is formatted by: Name, startDate, EndDate in the CSV. 通常,我的数据的格式为:CSV中的名称,开始日期,结束日期。 Now I want to attempt to use: Name, startDate, endDate, eventType, unitType. 现在,我想尝试使用:名称,startDate,endDate,eventType,unitType。

I am trying to figure out how to get my data eventType and unitType to display in the tool-tips. 我试图弄清楚如何使我的数据eventType和unitType显示在工具提示中。 I did try to push data to the series.data.composition, but I guess I was doing wrong! 我确实尝试将数据推送到series.data.composition,但我想我做错了!

As a bonus, dates that are just 1 day wide do not appear to show, but they are there, just too thin to see, anyone know of a solution? 另外,似乎没有显示只有1天宽的日期,但是它们在那里,太薄了,看不到,有人知道解决方案吗? I hacked around the theme for some time, but did not seem to help. 我在这个主题上乱砍了一段时间,但似乎并没有帮助。

Here is my JSFiddle code. 这是我的JSFiddle代码。

var options = {
    chart: {
        zoomType: 'y',
        borderWidth: '0',
        borderRadius: '15',
        renderTo: 'container',
        inverted: true,
        backgroundColor: {
            linearGradient: [0, 0, 500, 500],
            stops: [
                [0, 'rgb(44, 44, 58)'],
                [1, 'rgb(62, 62, 62)']
            ]
        },
        plotBackgroundColor: 'rgba(255, 255, 255, .9)'
    },
    tooltip: {
        useHTML: true,
        formatter: function () {
            var point = this.point;
            return '<table><tr>' + point.category + '</tr><tr><td style="color:#00CC00">Start:</td><td style="text-align: right">' + Highcharts.dateFormat('%b %e, %Y', point.low) + '</td></tr><tr><td style="color:#FF0000">Finish:</td><td>' + Highcharts.dateFormat('%b %e, %Y', point.high) + '</td></tr><tr><td>Unit:</td> <td></tr></table>'
        }
    },
    subtitle: {
        text: 'MTC'
    },
    credits: {
        text: 'MTC',
        href: 'myLink'
    },
    legend: {
        enabled: true
    },
    title: {
        text: 'Calendar'
    },
    xAxis: {
        categories: []
    },
    plotOptions: {
        series: {
            grouping: false
        }
    },
    yAxis: {
        type: 'datetime',
        minRange: 0,
        startOnTick: false,
        endOnTick: false,
        title: {
            text: 'yAxis'
        }
    },
    series: []
},
categories = [];;


var data = "Soldier 1,12/1/2013,12/10/2013,Training 1,Unit 1,4/8/2014,4/10/2014,Training 3,Unit 7\nSoldier 2,4/15/2013,4/18/2013,Training 2,Unit 2,4/20/2014,4/23/2014,Training 4,Unit 8\nSoldier 3,6/3/2013,6/3/2013,Training 31,Unit 3,8/12/2014,8/13/2014,Training 66,Unit 9,6/15/2013,6/22/2013,Train 92,Unit 44\nSoldier 4,10/10/2013,10/12/2013,Training 9,Unit 4,10/13/2013,10/19/2013,Training 6,Unit 10\nSoldier 5,9/20/2013,9/24/2013,Training 5,Unit 5";
var lines = data.split('\n');

$.each(lines, function (lineNo, line) {
    var items = line.split(','),
        iLen = items.length,
        series = {
            type: 'columnrange',
            data: [],
            name: items[0],
            composition: []
        };

    categories.push(items[0]);
    for (var i = 1; i < iLen; i += 2) {
        var from = (new Date(items[i])).getTime(),
            to = (new Date(items[i + 1])).getTime();
        if (!isNaN(from) && !isNaN(to)) {
            series.data.push([lineNo, from, to]);
        }
    };
    options.series.push(series);
});

options.xAxis.categories = categories;

var chart = new Highcharts.Chart(options);

Your fiddle with new data push and formatter: http://jsfiddle.net/WXLaN/2/ 使用新的数据推送和格式化程序进行摆弄: http : //jsfiddle.net/WXLaN/2/

Key thing to note is the data push loop: 需要注意的关键是数据推送循环:

for (var i = 1; i < iLen; i += 4) {
    var from = (new Date(items[i])).getTime(),
        to = (new Date(items[i + 1])).getTime();
    var point = {
        x: lineNo,
        low: from,
        high: to,
        event: (items[i + 2]),
        unit: (items[i + 3])
    };
    if (!isNaN(from) && !isNaN(to)) {
        series.data.push(point);
    }
};

Because the data lines are now 4 blocks of data, the inc was set to 4. In order to use the custom data fields, you need to push in an object with the required info and the additional info. 因为数据行现在是4个数据块,所以inc设置为4。为了使用自定义数据字段,您需要插入一个带有必需信息和附加信息的对象。 Your required info is the X, low & high. 您所需的信息是X,低和高。 The extra info is the event & unit. 额外的信息是事件和单位。 All of these things are available in the formatter in the point.options object and referenced by the same same you give them in the data push loop. 所有这些内容都可以在point.options对象的格式化程序中使用,并由与您在数据推送循环中提供的相同的对象引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM