2012-01-02 37 views
4

我想在我的圖表(使用System.Web.Helpers)上將間隔設置爲1(在mvc3 .net c#中)。 我無法找到圖表屬性來設置時間間隔,以便x/yValues顯示所有標籤。 這裏的代碼:在圖表中設置時間間隔.net mvc3

Chart key = new Chart(width: 600, height: 400) 
       .AddSeries(
        chartType: "bar", 
        legend: "Rainfall", 
        xValue: xVal, //new[] { "Jan", "Feb", "Mar", "Apr", "May" }, 
        yValues: yVal 
        ) //new[] { "20", "20", "40", "30", "10" }) 
       .AddTitle("Chart Success Rate") 
       .Write("png"); 

任何幫助將不勝感激。

謝謝。

回答

8

你可以用「主題」字符串來做到這一點。我已經測試好了。

只需在主題xml中添加一個Interval =「」1「」。

看到這個職位:http://forums.asp.net/t/1807781.aspx/1看到6樓的回覆(2012年5月27日上午11點23分)

我的測試代碼:

public ActionResult GetChartCategoryCountList1() 
{ 
    string temp = @"<Chart> 
         <ChartAreas> 
         <ChartArea Name=""Default"" _Template_=""All""> 
          <AxisY> 
          <LabelStyle Font=""Verdana, 12px"" /> 
          </AxisY> 
          <AxisX LineColor=""64, 64, 64, 64"" Interval=""1""> 
          <LabelStyle Font=""Verdana, 12px"" /> 
          </AxisX> 
         </ChartArea> 
         </ChartAreas> 
        </Chart>"; 

    using (var context = new EdiBlogEntities()) 
    { 
     var catCountList = context.GetCategoryCountList().ToList(); 

     var bytes = new Chart(width: 850, height: 400, theme: temp) 
      .AddSeries(
         xValue: catCountList.Select(p => p.DisplayName).ToArray(), 
         yValues: catCountList.Select(p => p.PostCount).ToArray() 
        ) 
      .GetBytes("png"); 

     return File(bytes, "image/png"); 
    } 
}