Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set interval in chart .net mvc3

I want to set interval to 1 on my chart (using System.Web.Helpers) in mvc3 .net c#. i cant find chart property to set the interval so that the x/yValues show all the labels. Here the code:

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");

Any help would be much appreciate.

Thanks.

like image 341
dejoong Avatar asked Jan 17 '23 22:01

dejoong


1 Answers

You can do it with "theme" string. I have tested OK with it.

Just add a Interval=""1"" to the theme xml.

See this post: http://forums.asp.net/t/1807781.aspx/1 see the 6th floor reply (May 27, 2012 11:23 AM)

my test code:

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");
    }
}
like image 71
Edi Wang Avatar answered Jan 21 '23 14:01

Edi Wang