Dygraphs动态更改系列名称?

时间:2013-08-13 00:53:31

标签: dygraphs

我有一个dygraphs图表,上面画着115个左右的系列。它很棒。但是,我正在试图弄清楚如何检索突出显示的系列的系列名称,以及如何格式化该数字。

关于dygraph小提琴页面的例子(不过,我使用一个大的php字符串作为数据,不会显示)。 http://jsfiddle.net/eM2Mg/861/

我最终得到了一个突出显示的标签,例如“年份:1955年Y73投资组合:1,000,000美元”。我希望能够检索该73号码并编辑它所说的内容。我在dygraph js文件中找不到序列号的特定标签格式化程序,或者检索它的方法。我不想手动标记每个系列。

想法?这是一个很棒的图表软件。

gr = new Dygraph(
// containing div
document.getElementById("graphdiv2"),
// CSV or path to a CSV file.
<?php echo $chartDataString2; ?>,
{
    title: 'Spending Level',
    ylabel: 'Spending ($)',
    xlabel: 'Year',
    labelsDivStyles: { 'textAlign': 'right' },
    digitsAfterDecimal: 0,
    yAxisLabelWidth: 100,
    axes: {
        y: {


                labelsKMB: false,
                maxNumberWidth: 11,
                valueFormatter: function numberWithCommas(x) {
                    return 'Spending: $' + x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                },
                axisLabelFormatter: function numberWithCommas(x) {
                    return '$' + x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                }
        },
        x: {
            valueFormatter: function numberWithCommas(x) {
                    return 'Year: ' + x;
                },
        },
    },
    showLabelsOnHighlight: true,
    highlightCircleSize: 3,
    strokeWidth: 1.5,
    strokeBorderWidth: 0,
 highlightSeriesBackgroundAlpha: 1.0,
    highlightSeriesOpts: {
      strokeWidth: 4,
      strokeBorderWidth: 2,
      highlightCircleSize: 5,
    },
}
);

1 个答案:

答案 0 :(得分:1)

内置的dygraphs图例适用于大多数图表,但在某些时候你会超过它。听起来你已达到这一点。我建议使用highlightCallback和unhighlightCallback隐藏内置图例并实现自己的图例。您可以通过g.getLabels()来访问系列名称。