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.
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");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With