Unexpected behavior from .Net diagrams

I am trying to create a .Net Chart (Windows.Forms) and export it to a file .jpeg

.

Below is the code for it

public void ExportRouteGraphToJpeg(string nameOfChart, int xMax, int yMax, int xMin, int yMin )
{
    var chartForExport = new Chart();
    chartForExport.Series.Clear();

    var xVsYSeries = new Series
    {
        Name = "XvsY",
        Color = Color.Blue,
        IsVisibleInLegend = false,
        IsXValueIndexed = true,
        ChartType = SeriesChartType.Point,
        MarkerSize = 6, 
        MarkerColor   = Color.Blue 
    };

    for (var i = 0; i < xValue.Length; i++)
    {
        xVsYSeries.Points.AddXY(xValue[i], yValue[i]);
    }

    chartForExport.Series.Add(xVsYSeries);

    // Chart Area Definition
    var chartArea = new ChartArea
    {
        Name = "SupportPoints",
        AxisX =
        {
            Title = "X Co-ordinate [cm]",
            ArrowStyle = AxisArrowStyle.Triangle,
            Maximum = xMax + 100,
            Minimum = xMin - 100
        },
        AxisY =
        {
            Title = "Y Co-ordinate [cm]",
            ArrowStyle = AxisArrowStyle.Triangle,
            Maximum = yMax + 100,
            Minimum = yMin - 100
        }
    };

    chartForExport.ChartAreas.Add(chartArea);
    chartForExport.Location = new Point(0, 50);
    chartForExport.TabIndex = 0;

    chartForExport.Name = "ChartRoute";          

    chartForExport.SaveImage(nameOfChart + ".jpeg", ChartImageFormat.Jpeg);
}

      

The result I am getting is shown below (for 5 points xValue = 1000, 2000, 3000, 4000 and the same for yValue)

enter image description here

When I remove Maximum = yMax + 100, Minimum = yMin - 100

for AxisX and AxisY

, I get the desired result. see below

enter image description here

Any guess why this is happening?

+3


source to share


2 answers


Remove IsXValueIndexed = true

from your batch definition.



enter image description here

+2


source


Use some third party charts like tall graph, example is given below



DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Bar Chart</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
      <script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>

      <script type="text/javascript">
          $(function() {
              $('#container').highcharts({
                  chart: {
                      type: 'bar'
                  },
                  title: {
                      text: 'MyFruit database info'
                  },
                  xAxis: {
                      categories: ['Records', 'Fragmentation', 'Users']
                  },
                  yAxis: {
                      title: {
                          text: 'Values'
                      }
                  },
                  series: [
                      {
                          name: 'MyFruit_Sites',
                          data: [10, 50, 4]
                      }, {
                          name: 'MyFruit_Devices',
                          data: [500, 80, 3]
                      }
                  ]
              });

              // the button handler
              $('#button').click(function () {
                  var chart = $('#container').highcharts();
                  chart.addSeries({
                              name: 'MyFruit_Users',
                              data: [30, 60, 4]
                          });
                });
          });
      </script>
  </head>
  <body>
    <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
      <button id="button" class="autocompare">Add series</button>
  </body>
</html>

      

-1


source







All Articles