MVC System.Web.Helpers圆环图标签定位

时间:2017-07-26 07:57:05

标签: c# asp.net asp.net-mvc model-view-controller charts

我有一个MVC应用程序,我试图显示一个圆环图。它使用下面的代码完美地工作,除了我找不到一种方法来让图表标签显示在图表之外

 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 个答案:

答案 0 :(得分: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

相关问题