产生图表图片的代码如下:
public static string GetFastLine(
string width,//图片的宽度
string height,//图片的高度
string title,//图表标题
string XTitle,//X轴标题
string YTitle,//Y轴标题
string[] xValue,//X轴数据
string[] yValue,//Y轴数据
string maxValue, //X轴最大值
string minValue,//X轴最大值
string YMaxValue,//Y轴最大值
string YMinValue,//Y轴最小值
double xCount,//X轴间隔
double yCount,//Y轴间隔
bool isSavedIMG)//是否存储为图片
{
Chart chartObj = new Chart();
chartObj.Width = Convert.ToInt32(width);
chartObj.Height = Convert.ToInt32(height);
chartObj.RenderType = RenderType.ImageTag;
chartObj.Palette = ChartColorPalette.BrightPastel;
Title imgTitle = new Title(title, Docking.Top, new Font("Trebuchet MS", 13, FontStyle.Bold), Color.FromArgb(26, 65, 180));
chartObj.Titles.Add(imgTitle);
chartObj.ChartAreas.Add("Areas 1");
chartObj.ChartAreas["Areas 1"].AxisX.LineColor = Color.Black;
chartObj.ChartAreas["Areas 1"].AxisY.LineColor = Color.Black;
chartObj.ChartAreas["Areas 1"].AxisX.MajorGrid.LineColor = Color.White;
chartObj.ChartAreas["Areas 1"].AxisY.MajorGrid.LineColor = Color.White;
int start=Convert.ToInt32(minValue);
int end=Convert.ToInt32(maxValue);
chartObj.Series.Add("IMGInfo");
if (xValue != null)
{
for (int cursor = 0; cursor < yValue.Length; cursor++)
{
chartObj.Series["IMGInfo"].Points.AddXY(xValue[cursor], yValue[cursor]);
}
}
else
{
for (int cursur = 0; cursur < yValue.Length; cursur++)
{
chartObj.Series["IMGInfo"].Points.AddY(Convert.ToDouble(yValue[cursur]));
}
}
chartObj.Series["IMGInfo"].ChartType = SeriesChartType.FastLine;
chartObj.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chartObj.BackColor = Color.White;
chartObj.BorderlineDashStyle = ChartDashStyle.Solid;
chartObj.BorderlineWidth = 2;
chartObj.ChartAreas["Areas 1"].AxisY.Maximum = Convert.ToDouble(YMaxValue);
chartObj.ChartAreas["Areas 1"].AxisY.Minimum = Convert.ToDouble(YMinValue);
chartObj.ChartAreas["Areas 1"].AxisX.Maximum = Convert.ToInt32(Convert.ToDouble(maxValue));
chartObj.ChartAreas["Areas 1"].AxisX.Minimum = Convert.ToInt32(Convert.ToDouble(minValue));
chartObj.ChartAreas["Areas 1"].AxisX.Interval = xCount;
chartObj.ChartAreas["Areas 1"].AxisX.IntervalType = DateTimeIntervalType.Milliseconds;
chartObj.ChartAreas["Areas 1"].AxisY.Interval = yCount;
chartObj.ChartAreas["Areas 1"].AxisX.Title = XTitle;
chartObj.ChartAreas["Areas 1"].AxisY.Title = YTitle;
if (isSavedIMG)
{
string currentTicks = DateTime.Now.Ticks.ToString();
string filePath = HttpRuntime.AppDomainAppPath + "ImageChart\\BDIMG\\" + currentTicks + ".png";
string fileVisualPath = HttpRuntime.AppDomainAppVirtualPath + "ImageChart/BDIMG/" + currentTicks + ".png";
while (true)
{
if (File.Exists(filePath))
{
string temp = (new Random()).Next(10000).ToString();
filePath = filePath.Split('.')[0] + temp + ".png";
fileVisualPath = fileVisualPath.Split('.')[0] + temp + ".png";
}
else
{
break;
}
}
chartObj.SaveImage(filePath);
chartObj.Dispose();
return fileVisualPath;
}
else
{
return null;
}
}
xValue[] yValue[] 数组即时需要的数据坐标点数据。
调用方式如下:
ChartHelper.GetFastLine(width1, height1, "图表标题", "X轴标题", "Y轴标题", IMG2AxisX, YValue2, XAxisMax, XAxisMin, YAxisMax, YAxisMin, 200, 0.5, true);
,但是在生成的图片中,横坐标只能出到249.5,而在xValue[] 数组中,的最大值为500。
想了好几天,也没明白是怎么回事?
各位大虾,帮帮忙吧~在线等……………….
public static string GetFastLine(
string width,//图片的宽度
string height,//图片的高度
string title,//图表标题
string XTitle,//X轴标题
string YTitle,//Y轴标题
string[] xValue,//X轴数据
string[] yValue,//Y轴数据
string maxValue, //X轴最大值
string minValue,//X轴最大值
string YMaxValue,//Y轴最大值
string YMinValue,//Y轴最小值
double xCount,//X轴间隔
double yCount,//Y轴间隔
bool isSavedIMG)//是否存储为图片
{
Chart chartObj = new Chart();
chartObj.Width = Convert.ToInt32(width);
chartObj.Height = Convert.ToInt32(height);
chartObj.RenderType = RenderType.ImageTag;
chartObj.Palette = ChartColorPalette.BrightPastel;
Title imgTitle = new Title(title, Docking.Top, new Font("Trebuchet MS", 13, FontStyle.Bold), Color.FromArgb(26, 65, 180));
chartObj.Titles.Add(imgTitle);
chartObj.ChartAreas.Add("Areas 1");
chartObj.ChartAreas["Areas 1"].AxisX.LineColor = Color.Black;
chartObj.ChartAreas["Areas 1"].AxisY.LineColor = Color.Black;
chartObj.ChartAreas["Areas 1"].AxisX.MajorGrid.LineColor = Color.White;
chartObj.ChartAreas["Areas 1"].AxisY.MajorGrid.LineColor = Color.White;
int start=Convert.ToInt32(minValue);
int end=Convert.ToInt32(maxValue);
chartObj.Series.Add("IMGInfo");
if (xValue != null)
{
for (int cursor = 0; cursor < yValue.Length; cursor++)
{
chartObj.Series["IMGInfo"].Points.AddXY(xValue[cursor], yValue[cursor]);
}
}
else
{
for (int cursur = 0; cursur < yValue.Length; cursur++)
{
chartObj.Series["IMGInfo"].Points.AddY(Convert.ToDouble(yValue[cursur]));
}
}
chartObj.Series["IMGInfo"].ChartType = SeriesChartType.FastLine;
chartObj.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chartObj.BackColor = Color.White;
chartObj.BorderlineDashStyle = ChartDashStyle.Solid;
chartObj.BorderlineWidth = 2;
chartObj.ChartAreas["Areas 1"].AxisY.Maximum = Convert.ToDouble(YMaxValue);
chartObj.ChartAreas["Areas 1"].AxisY.Minimum = Convert.ToDouble(YMinValue);
chartObj.ChartAreas["Areas 1"].AxisX.Maximum = Convert.ToInt32(Convert.ToDouble(maxValue));
chartObj.ChartAreas["Areas 1"].AxisX.Minimum = Convert.ToInt32(Convert.ToDouble(minValue));
chartObj.ChartAreas["Areas 1"].AxisX.Interval = xCount;
chartObj.ChartAreas["Areas 1"].AxisX.IntervalType = DateTimeIntervalType.Milliseconds;
chartObj.ChartAreas["Areas 1"].AxisY.Interval = yCount;
chartObj.ChartAreas["Areas 1"].AxisX.Title = XTitle;
chartObj.ChartAreas["Areas 1"].AxisY.Title = YTitle;
if (isSavedIMG)
{
string currentTicks = DateTime.Now.Ticks.ToString();
string filePath = HttpRuntime.AppDomainAppPath + "ImageChart\\BDIMG\\" + currentTicks + ".png";
string fileVisualPath = HttpRuntime.AppDomainAppVirtualPath + "ImageChart/BDIMG/" + currentTicks + ".png";
while (true)
{
if (File.Exists(filePath))
{
string temp = (new Random()).Next(10000).ToString();
filePath = filePath.Split('.')[0] + temp + ".png";
fileVisualPath = fileVisualPath.Split('.')[0] + temp + ".png";
}
else
{
break;
}
}
chartObj.SaveImage(filePath);
chartObj.Dispose();
return fileVisualPath;
}
else
{
return null;
}
}
xValue[] yValue[] 数组即时需要的数据坐标点数据。
调用方式如下:
ChartHelper.GetFastLine(width1, height1, "图表标题", "X轴标题", "Y轴标题", IMG2AxisX, YValue2, XAxisMax, XAxisMin, YAxisMax, YAxisMin, 200, 0.5, true);
,但是在生成的图片中,横坐标只能出到249.5,而在xValue[] 数组中,的最大值为500。
想了好几天,也没明白是怎么回事?
各位大虾,帮帮忙吧~在线等……………….
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货