2015-07-21 100 views
0

我使用HighCharts .NET API创建一个简单的图表:如何格式化轴highchart

Dim sFontFamily As String = "fontFamily: 'inherit'" 

      Dim oChart As DotNet.Highcharts.Highcharts = New DotNet.Highcharts.Highcharts("SearchCount") 
      With oChart 
       .InitChart(New DotNet.Highcharts.Options.Chart With {.Style = sFontFamily, .Height = 250, .DefaultSeriesType = DotNet.Highcharts.Enums.ChartTypes.Line}) 
       .SetOptions(New GlobalOptions With {.Global = New DotNet.Highcharts.Options.Global With {.UseUTC = False}}) 
       .SetTitle(New Title With {.Style = sFontFamily, .Text = "Search Count"}) 
       .SetXAxis(New XAxis With {.Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New XAxisTitle With {.Style = sFontFamily, .Text = "Month"}}) 
       .SetYAxis(New YAxis With {.Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New YAxisTitle With {.Style = sFontFamily, .Text = "Searches"}}) 
       .SetCredits(New Credits With {.Enabled = False}) 
       .SetTooltip(New Tooltip With {.Style = sFontFamily}) 
       .SetSeries(New Series() With {.Name = "this year", .Data = New Data(oData)}) 

       'display a legend so user knows what graphs represent 
       .SetLegend(New Legend With {.Style = sFontFamily, .Enabled = True}) 

       litHighChartSearchCount.Text = oChart.ToHtmlString() 
      End With 

为了方便这里的渲染结果:https://jsfiddle.net/d063mhoL/

而且数据传递给系列的外观像这样:

HighCharts Data

如果检查小提琴,你会看到在Y轴上的数据是数字,当我想它成为月份名称的字符串,任何人都可以帮忙吗?

+1

更好是使用Y轴的日期时间类型,然后为每个点的时间戳(时间list(of string)毫秒)并通过http://api.highcharts.com/highcharts#yAxis.dateTimeLabelFormats格式化标签 –

回答

0

我需要设置的类别为坐标轴,像这样:

.SetXAxis(New XAxis With {.Categories = sCategories.ToArray, .Labels = New XAxisLabels With {.Style = sFontFamily}, .Title = New XAxisTitle With {.Style = sFontFamily, .Text = "Month"}, .Type = AxisTypes.Datetime}) 

sCategories是包含月