来自 .Net 图表的意外行为
Unexpected Behavior from .Net Charts
我正在尝试创建 .Net 图表 (Windows.Forms) 并将其导出到 .jpeg
文件。
下面是它的代码
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);
}
我得到的输出如下所示(5 个点的 xValue = 1000、2000、3000、4000 和 yValue 相同)
当我为 AxisX and AxisY
删除 Maximum = yMax + 100, Minimum = yMin - 100
时,我得到了所需的输出。请看下面
任何建议为什么会这样?
使用一些第三方图表,如高图,示例如下
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>
从您的系列定义中删除 IsXValueIndexed = true
。
我正在尝试创建 .Net 图表 (Windows.Forms) 并将其导出到 .jpeg
文件。
下面是它的代码
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);
}
我得到的输出如下所示(5 个点的 xValue = 1000、2000、3000、4000 和 yValue 相同)
当我为 AxisX and AxisY
删除 Maximum = yMax + 100, Minimum = yMin - 100
时,我得到了所需的输出。请看下面
任何建议为什么会这样?
使用一些第三方图表,如高图,示例如下
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>
从您的系列定义中删除 IsXValueIndexed = true
。