2017-07-26 140 views
1

我有一個MVC應用程序,我試圖在上顯示甜甜圈圖表。它的工作完全使用下面的代碼,但我不能找到一個辦法讓圖表標籤圖表MVC System.Web.Helpers甜甜圈圖標籤定位

private static void CreateChart(int width, int height, ArrayList xData, ArrayList yData, string title = "") 
    { 
     string myTheme = @"<Chart BackColor=""Transparent"" AntiAliasing=""All"" > 
           <ChartAreas> 
            <ChartArea Name=""Default"" BackColor=""Transparent""> 
             <AxisY> 
              <LabelStyle ForeColor=""#ffffff"" Font=""Helvetica Neue, 20 px"" /> 
             </AxisY> 
            </ChartArea> 
           </ChartAreas> 
           <Legends> 
            <Legend _Template_=""All"" BackColor=""Transparent"" Font=""Trebuchet MS, 18.25pt, style=Bold"" IsTextAutoFit=""False"" /> 
           </Legends> 
          </Chart>"; 

     new System.Web.Helpers.Chart(width: width, height: height, theme: myTheme) 
      .AddSeries("Default", chartType: "Doughnut", xValue: xData, yValues: yData) 
      .AddTitle(title) 
      .Write("png"); 
    } 

ChartLabelIssue

外顯示你可以從我的代碼看,我是主題化圖表使用XML,但我還沒有發現任何看起來可能有助於定位標籤的東西。

這不是個大問題上面的圖表上,但顯示超過2場,標籤都重疊在一起時:

ChartOverlappingLables

有誰知道如何更改標籤的位置?還有爲什麼圖表標題出現全部模糊的獎勵點? :)

回答

1

使用自定義屬性PieLabelStyle以避免重疊。至於模糊標題,主題中的垃圾太多了。清理。請看下圖:

string myTheme = @"<Chart> 
       <ChartAreas> 
        <ChartArea Name=""Default""> 
        </ChartArea> 
       </ChartAreas> 
       <Series> 
        <Series Name=""Default"" CustomProperties=""PieLabelStyle = Outside"" Label=""Very very long label (#VAL)""></Series> 
       </Series> 
       <Titles> 
        <Title Name=""Default""></Title> 
       </Titles> 
      </Chart>"; 

enter image description here

+1

美麗!最高分;)感謝jstreet,你是​​一個拯救生命的人! – Nick