我使用.net包装器创建了一个高库存图表,通过API提取数据并成功地从模型传递到视图:
现在,我正在尝试添加图例,以允许用户隐藏/显示系列。我尝试了以下代码(生成如图所示的代码),但未显示图例。我想念什么? 这是我的代码:
@{ var chartOptions =
new Highstock
{
Chart = new Chart { Height = 500 },
RangeSelector = new RangeSelector { Selected = 2 },
Title = new Title { Text = "CompanyName" },
Legend = new Legend
{
Enabled = true,
UseHTML = true,
Align = LegendAlign.Right,
Layout = LegendLayout.Proximate,
BackgroundColor = "#000"
},
YAxis = new List<YAxis>
{
new YAxis
{
Labels = new YAxisLabels
{
Align = YAxisLabelsAlign.Right,
X = -3
},
LineWidth = 2,
Height = "80%",
},
new YAxis
{
Labels = new YAxisLabels
{
Align = YAxisLabelsAlign.Right,
X = -3
},
Title = new YAxisTitle
{
Text = "Volume"
},
Top = "85%",
Height = "15%",
Offset = -1,
LineWidth = 2,
Id = "VolumeAxis"
}
},
Series = new List<Series>
{
new LineSeries
{
Data = Model.exaeData as List<LineSeriesData>,
Name = "EXAE",
Compare = "percent",
TurboThreshold = 10000,
ShowInLegend = true,
Shadow = new Shadow
{
Enabled = true,
},
Tooltip = new LineSeriesTooltip
{
ValueDecimals = 2
},
Color = "#3b61a6"
},
new LineSeries
{
Data = Model.gdData as List<LineSeriesData>,
Name = "Index",
Compare = Model.CompareMethod,
TurboThreshold = 10000,
Visible = Model.showGD,
ShowInLegend = true,
Shadow = new Shadow
{
Enabled = true,
},
Tooltip = new LineSeriesTooltip
{
ValueDecimals = 2
},
Color = "#6f42c1",
},
new LineSeries
{
Data = Model.ftseData as List<LineSeriesData>,
Name = "FTSE/ΧΑ LARGE CAP",
Compare = Model.CompareMethod,
TurboThreshold = 10000,
Visible = Model.showFTSE,
ShowInLegend = true,
Shadow = new Shadow
{
Enabled = true,
},
Tooltip = new LineSeriesTooltip
{
ValueDecimals = 2
},
Color = "#00a3e2",
},
new ColumnSeries
{
Name = "Volume",
Data = Model.volumeData as List<ColumnSeriesData>,
DataGrouping = new ColumnSeriesDataGrouping() {Enabled = true, Forced = true },
TurboThreshold = 10000,
ShowInNavigator = false,
Color = "#3b61a6",
YAxis = "VolumeAxis"
}
},
};
chartOptions.ID = "chart";
var renderer = new HighstockRenderer(chartOptions, "theKey");
}
@Html.Raw(renderer.RenderHtml())