Click here to Skip to main content
15,909,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
x-axis values are not displayed in the chart using asp.net MVC razer. but y axis are displayed properly.


with the below code the chart is dispalying properly with X-axis and Y-axis values too.


C#
public ActionResult Index()
      {
          var key = new Chart(width: 600, height: 400)
             .AddSeries(
                 chartType: "bar",
                 legend: "Rainfall",
                  xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
                  yValues: new[] { "20", "20", "40", "10", "10"}

                  ).Write();

          return null;

      }



but when i tried with the below code the chart is displaying but the X-axis values are not displayed properly


C#
 public ActionResult Index()
   {
       Chart chart = new Chart(width: 1080, height: 1280);
       chart.AddSeries(
       chartType: "stackedbar",
    xValue: new[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" , "j", "k", "l", "m", "n", "o" , "p", "q", "r", "s", "t", "u" },
   yValues: new[] { "200", "400", "600", "200", "400", "600", "200", "400", "600" , "200", "400", "600", "200", "400", "600"  , "200", "400", "600", "200", "400", "600" }
           ).Write();

     return null;
}

any help will be appreciated..
Posted
Updated 19-Dec-11 22:26pm
v2

1 solution

public ActionResult Index()
{
System.Web.UI.DataVisualization.Charting.Chart c = new System.Web.UI.DataVisualization.Charting.Chart();
ChartArea area = new ChartArea();
area.AxisX.IsLabelAutoFit = true;
area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30;
area.AxisX.LabelStyle.Enabled = true;
area.AxisX.Interval = 1;
area.AxisY.Interval = 1;
//System.Web.UI.DataVisualization.Charting.Axis
//c.ChartAreas.Add(new ChartArea());
c.ChartAreas.Add(area);
c.Width = 200;
c.Height = 200;
Series mySeries = new Series();
mySeries.Points.DataBindXY(
new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" },
new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" }

);

c.Series.Add(mySeries);
//c.ChartAreas[0].AxisX.LabelStyle.Angle = 45;


// chart.Series.Add(series);
var returnStream = new MemoryStream();
c.ImageType = ChartImageType.Png;
c.SaveImage(returnStream);
returnStream.Position = 0;
return new FileStreamResult(returnStream, "image/png");

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900