Razor Chart Helper: How to change AxisX text orien

2019-07-26 23:45发布

问题:

In a view, I can not change the orientation of the text of the labels of the X axis I tried to add a property in a theme but this does not seem to work. Do you have an idea for it to work?

@{

    string myTheme = "<Chart>\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\">\r\n <AxisX  TextOrientation=\"Rotated90\" Interval=\"1\" />\r\n  </ChartArea>\r\n </ChartAreas>\r\n \r\n \r\n</Chart>";


    var myChart = new Chart(width: 600, height: 400, theme: myTheme)
        .AddSeries(
            name: "test ",
            xValue: new[] { "Peter", "andrew" },
            yValues: new[] { "1", "2" })
             .AddLegend()
        .Write();

}

回答1:

Try this:

@{
    string myTheme = "<Chart>\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\">\r\n <AxisX IsLabelAutoFit=\"false\"><LabelStyle Angle=\"-90\" Interval=\"1\"></LabelStyle></AxisX>\r\n  </ChartArea>\r\n </ChartAreas>\r\n \r\n \r\n</Chart>";


    var myChart = new Chart(width: 600, height: 400, theme: myTheme)
        .AddSeries(
            name: "test ",
            xValue: new[] { "Peter", "andrew" },
            yValues: new[] { "1", "2" })
             .AddLegend()
        .Write();
}