我米使用dotnetHightchartsHighcharts每個系列的tooltipformat?
BasicColumnChart
public static Highcharts BasicColumnChart(Series[] Series, string[] Categories, string Title = "", string SubTitle = "", string XAxisTitle = "", string YAxisTitle = "", string ToolTipFormat = "", string YAxisLabel = "")
{
Highcharts chart = new Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, Height = 300 })
.SetTitle(new Title { Text = Title })
.SetSubtitle(new Subtitle { Text = SubTitle })
.SetXAxis(new XAxis { Categories = Categories })
.SetYAxis(new YAxis
{
Min = 0,
Title = new YAxisTitle { Text = YAxisTitle },
Labels = new YAxisLabels
{
Formatter = @"function() { return this.value +' " + YAxisLabel + "';}"
}
})
.SetLegend(new Legend
{
Layout = Layouts.Vertical,
VerticalAlign = VerticalAligns.Top,
Align = HorizontalAligns.Right,
Shadow = true,
BackgroundColor = ColorTranslator.FromHtml("#FFFFFF"),
Floating = true
})
.SetTooltip(new Tooltip { Formatter = @"function() { return ''+ this.x +' - '+ this.y +' " + ToolTipFormat + "'; }" })
.SetPlotOptions(new PlotOptions
{
Column = new PlotOptionsColumn
{
PointPadding = 0.2,
BorderWidth = 0
}
})
.SetSeries(Series);
return chart;
}
我可以設置相同tooltipFormat爲每個系列下面一行:
.SetTooltip(new Tooltip { Formatter = @"function() { return ''+ this.x +' - '+ this.y +' " + ToolTipFormat + "'; }" })
以上代碼的輸出:date - value tooltipFormat
但我想爲每個系列顯示不同的格式。爲什麼我要這樣,因爲我要證明有不同的單元,例如不同的數據:
value[0] = 220 V //Volt
value[1] = 5 A //Ampere
...
value[15] = 1200 kW //Kilowatt
有很多例子關於這個話題,但是,這些例子只是更改文本。我的數據意見是這樣的:
NAME VALUE UNIT
Volt 220 V
Ampere 5 A
....
我想動態改變每個系列的tooltipFormat。我想動態地添加UNIT
字段。我怎樣才能做到這一點?
謝謝。
我創建了這樣的系列C#端:'系列localSeries =新系列{名稱=項目名稱,數據=新數據(數據)};'所以,我該如何添加新的屬性? –
你的建議後,我發現這樣的:'系列localSeries =新系列{名稱= item.Name,數據=新的數據(數據),PlotOptionsSpline =新的PlotOptionsSpline {Tooltip = item.Unit}};但這段代碼不工作也是如此。 :) –
Series對象中有Stack屬性(不知道它是什麼),您可以使用它。 –