请问用C#怎么做曲线图?

百思软件工作室 2010-06-12 03:20:44
请问用C#怎么做用户排名曲线图?
不需要自己手写的代码,那种可能不是很美观
大家都是用OWC做吗?
能不能提供一套OWC画图的代码啊?
...全文
691 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
sclsuccess2010 2010-06-13
  • 打赏
  • 举报
回复
#region 输出柱形图
/**//// <summary>
/// 柱形图
/// </summary>
/// <returns></returns>
public string CreateColumn()
{
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//创建ChartSpace对象来放置图表
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表,Add方法返回chart对象

//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到//Microsoft.Office.Interop.OWC.ChartChartTypeEnum
objChart.Type=Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;

//指定图表是否需要图例
objChart.HasLegend = true;

//标题
objChart.HasTitle = true;
objChart.Title.Caption= _title;
// objChart.Title.Font.Bold=true;
// objChart.Title.Font.Color="blue";


#region 样式设置

//旋转
// objChart.Rotation = 360;//表示指定三维图表的旋转角度
// objChart.Inclination = 10;//表示指定三维图表的视图斜率。有效范围为 -90 到 90

//背景颜色
// objChart.PlotArea.Interior.Color = "red";

//底座颜色
// objChart.PlotArea.Floor.Interior.Color = "green";
//
// objChart.Overlap = 50;//单个类别中标志之间的重叠量

#endregion

//x,y轴的图示说明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : "+this._xtitle;
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : "+this._ytitle;


//添加一个series
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);


//给定series的名字
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),SeriesName);
//给定分类
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
//给定值
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
//表示柱形图上的单个数据标志
Microsoft.Office.Interop.Owc11.ChDataLabels dl=objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue=true;
// dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;


string filename=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";
string strAbsolutePath = _phaysicalimagepath + "\\"+filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件.

return filename;

}
#endregion

#region 输出饼图
/**//// <summary>
/// 饼图
/// </summary>
/// <returns></returns>
public string CreatePie()
{
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//创建ChartSpace对象来放置图表
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表,Add方法返回chart对象


//指定图表的类型
objChart.Type=Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie;

//指定图表是否需要图例
objChart.HasLegend = true;

//标题
objChart.HasTitle = true;
objChart.Title.Caption= _title;


//添加一个series
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);

//给定series的名字
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),SeriesName);
//给定分类
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
//给定值
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);


//表示系列或趋势线上的单个数据标志
Microsoft.Office.Interop.Owc11.ChDataLabels dl=objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue=true;
dl.HasPercentage=true;
//图表绘图区的图例放置在右侧。
// dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionRight;

string filename=DateTime.Now.Ticks.ToString()+".gif";
string strAbsolutePath = _phaysicalimagepath + "\\"+filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件.

return filename;
}
#endregion

#region 输出曲线图
/**//// <summary>
/// 曲线图
/// </summary>
/// <returns></returns>
public string CreateLine()
{
//创建ChartSpace对象来放置图表
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();

//在ChartSpace对象中添加图表,Add方法返回chart对象

Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add (0);
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine;

//指定图表是否需要图例
objChart.HasLegend = true;


//给定标题
objChart.HasTitle = true;
objChart.Title.Caption =this._title;

//给定x,y轴的图示说明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : " +this._xtitle;
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : " +this._ytitle;


//添加一个series
ChSeries chseries=objChart.SeriesCollection.Add(0);

chseries.Line.set_Weight(Microsoft.Office.Interop.Owc11.LineWeightEnum.owcLineWeightHairline);
//给定series的名字
objChart.SeriesCollection[0].SetData (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
+ (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, SeriesName);

//给定分类
objChart.SeriesCollection[0].SetData (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
+ (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);

//给定值
objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
//表示曲线上的单个数据标志
Microsoft.Office.Interop.Owc11.ChDataLabels dl=objChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue=true;

string filename=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";
//string filename = "quxian.gif";
string strAbsolutePath = _phaysicalimagepath + "\\"+filename;
objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件.
return filename;
}
#endregion

#region 调用说明及范例
// 在要显示统计图的页面代码直接调用,方法类似如下:
//
// ShowChart chart=new ShowChart(); 创建对象
// chart.Title="标题";
// chart.XTitle ="月份";
// chart.YTitle ="数量";
// chart.SeriesName="图例";
// string filepath=Server.MapPath(".")+"\\ChartImages";
// chart.PhaysicalImagePath=filepath;
// chart.PicHight=320;
// chart.PicWidth=500;
// chart.DataSource=GetData();//这是你的数据源
// Response.Write("<img src='" +filepath+"\\"+chart.CreateColumn()+"'/>");
// this.Image1.ImageUrl=filepath+"\\"+chart.CreateBar();//显示给图像控件。
#endregion
}
}
sclsuccess2010 2010-06-13
  • 打赏
  • 举报
回复
lz可以参考一下
using System;
using System.Data;
using System.Text;
using Microsoft.Office.Interop.Owc11;

namespace Test
{
/**//// <summary>
/// sclsmile
/// 根据数据动态生成图形(柱形图、饼图、曲线图)
/// 2010-06-19
/// </summary>
public class ShowChart
{
#region 属性
private string _phaysicalimagepath;//图片存放路径
private string _title; //图片标题
private string _xtitle;//图片x座标名称
private string _ytitle;//图片y座标名称
private string _seriesname;//图例名称
private int _picwidth;//图片宽度
private int _pichight;//图片高度
private DataTable _datasource;//图片数据源
private string strCategory;//图片数据源的分类
private string strValue;//图片数据源的值

/**//// <summary>
/// 图片存放路径
/// </summary>
public string PhaysicalImagePath
{
set{_phaysicalimagepath=value;}
get{return _phaysicalimagepath;}
}
/**//// <summary>
/// 图片标题
/// </summary>
public string Title
{
set{_title=value;}
get{return _title;}
}
/**//// <summary>
/// 图片标题
/// </summary>
public string XTitle
{
set{_xtitle=value;}
get{return _xtitle;}
}
/**//// <summary>
/// 图片标题
/// </summary>
public string YTitle
{
set{_ytitle=value;}
get{return _ytitle;}
}

/**//// <summary>
/// 图例名称
/// </summary>
public string SeriesName
{
set{_seriesname=value;}
get{return _seriesname;}
}
/**//// <summary>
/// 图片宽度
/// </summary>
public int PicWidth
{
set{_picwidth=value;}
get{return _picwidth;}
}
/**//// <summary>
/// 图片高度
/// </summary>
public int PicHight
{
set{_pichight=value;}
get{return _pichight;}
}
/**//// <summary>
/// 图片数据源
/// </summary>
public DataTable DataSource
{
set
{
_datasource=value;
strCategory=GetColumnsStr(_datasource);
strValue=GetValueStr(_datasource);
}
get{return _datasource;}
}
/**//// <summary>
/// 图片数据源的分类
/// </summary>
private string GetColumnsStr(DataTable dt)
{
StringBuilder strList=new StringBuilder();
foreach(DataRow r in dt.Rows)
{
strList.Append(r[0].ToString()+'\t');
}
return strList.ToString();
}
/**//// <summary>
/// 图片数据源的值
/// </summary>
private string GetValueStr(DataTable dt)
{
StringBuilder strList=new StringBuilder();
foreach(DataRow r in dt.Rows)
{
strList.Append(r[1].ToString()+'\t');
}
return strList.ToString();
}

#endregion

#region 构造函数
public ShowChart()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public ShowChart(string PhaysicalImagePath,string Title,string XTitle,string YTitle,string SeriesName)
{
_phaysicalimagepath=PhaysicalImagePath;
_title=Title;
_xtitle=XTitle;
_ytitle=YTitle;
_seriesname=SeriesName;
}
#endregion

xingcheng8888 2010-06-13
  • 打赏
  • 举报
回复
MsChart
wyq29 2010-06-13
  • 打赏
  • 举报
回复
用破解的 dotnetCHARTING
chxg99 2010-06-13
  • 打赏
  • 举报
回复
mark
ycagri 2010-06-13
  • 打赏
  • 举报
回复
dundas chart 已经被MS收购了,就是现在的MsChart
当然OWC也不错,就是做出的图不绚
现在做图基本上就是三大阵营
1、生成图片的 推荐 msChart
2、生成flash的 推荐 FusionChartsFree
3、纯JS代码类的(包括VML等) 推荐 highchart

至少这些都是免费的,完全可以满足你的需要
wen98091 2010-06-13
  • 打赏
  • 举报
回复
我用的dundas chart 。


看看实例和文档,上手还是很快的。
oneatree 2010-06-13
  • 打赏
  • 举报
回复
mark
皇城龙三 2010-06-12
  • 打赏
  • 举报
回复
给楼主找几个OWC的开源例子:





http://www.codeproject.com/KB/web-image/Column-Chart.aspx
wuyq11 2010-06-12
  • 打赏
  • 举报
回复
ms chart
zesgraph
Dundas Chart
OWC
chenqingwei 2010-06-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 mervyn807 的回复:]

微软有MSchart控件
可以使用
[/Quote]
可以使用这个
缭绕飘渺 2010-06-12
  • 打赏
  • 举报
回复
微软有MSchart控件
可以使用
sardineany 2010-06-12
  • 打赏
  • 举报
回复
DEV 里的chartControl。。各种数据图,什么都能做。。很强大
lbser 2010-06-12
  • 打赏
  • 举报
回复
学习学习
Zhanlixin 2010-06-12
  • 打赏
  • 举报
回复
private void Loadimg()
{
string strField = ddlField.SelectedItem.Value.ToString();
string strTx = "";
if (rdbPie.Checked == true)
{
strTx = "1";
}
else if (rdbBar.Checked == true)
{
strTx = "2";
}
else
{
strTx = "3";
}

OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass();

//在ChartSpace对象中添加图表,Add方法返回chart对象
OWC11.ChChart objChart = objCSpace.Charts.Add(0);

//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
if (strTx == "1")
{
if (chk3d.Checked == false)
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypePie;
}
else
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypePie3D;
}
}
else if (strTx == "2")
{
if (chk3d.Checked == false)
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered;
}
else
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
}
}
else
{
if (chk3d.Checked == false)
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeLine;
}
else
{
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeLine3D;
}
}


//指定图表是否需要图例
objChart.HasLegend = true;

//给定标题
objChart.HasTitle = true;
objChart.Title.Caption =ddlField.SelectedItem.Text.ToString() + "分布图";

//给定x,y轴的图示说明
if (strTx != "1")
{
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "X : 地区";
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "Y : 数量";
}

//计算数据
/*categories 和 values 可以用tab分割的字符串来表示*/
string strSeriesName = "图例 1";

string strSQL = "";
if (Convert.ToInt16(Session["Z001"]) == 1)
{
strSQL = "select b.unit,sum(" + strField + ") from stat" + Session["JCNO"].ToString() + " a,areacode b,stat0 c where substr(a.areacode,0,4)=substr(b.code,0,4) and a.z000=c.z000 and a.ny=c.ny and c.qysbsj is not null and b.z001=2 and a.ny='" + Session["Ny"].ToString() + "' group by substr(a.areacode,0,4),b.unit order by substr(a.areacode,0,4)";
}
else if (Convert.ToInt16(Session["Z001"]) == 2)
{
strSQL = "select b.unit,sum(" + strField + ") from stat" + Session["JCNO"].ToString() + " a,areacode b,stat0 c where substr(a.areacode,0,6)=substr(b.code,0,6) and a.z000=c.z000 and a.ny=c.ny and c.qysbsj is not null and b.z001 in(3,4,5,6) and left(a.z000,4)='" + Session["Z000"].ToString().Substring(0, 4) + "' and a.ny='" + Session["Ny"].ToString() + "' group by substr(a.areacode,0,6),b.unit order by substr(a.areacode,0,6)";
}

string strCategory = "";
string strValue = "";
IDataReader dr = GetData.GetReadbySQL(strSQL);
while (dr.Read())
{
strCategory = strCategory + dr[0].ToString() + '\t';
if (dr[1] != DBNull.Value)
{
strValue = strValue + dr[1].ToString() + '\t';
}
else
{
strValue = strValue + "0" + '\t';
}
}
dr.Close();


// string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t' + "4" + '\t' + "5" + '\t' + "6" + '\t';
// string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t' + "10" + '\t' + "12" + '\t' + "6" + '\t';

//添加一个series
objChart.SeriesCollection.Add(0);

//给定series的名字
objChart.SeriesCollection[0].SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,
+(int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

//给定分类
objChart.SeriesCollection[0].SetData(OWC11.ChartDimensionsEnum.chDimCategories,
+(int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);

//给定值
objChart.SeriesCollection[0].SetData
(OWC11.ChartDimensionsEnum.chDimValues,
(int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);

if (strTx == "1")
{
objChart.SeriesCollection[0].DataLabelsCollection.Add();
objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;

//设置饼状图中字体的大小
objChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size = 14;

//显示各部分的百分比
objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
}


//输出成GIF文件.
string TimeTicks = DateTime.Now.Ticks.ToString();
string path = "\\chart\\" + TimeTicks + ".gif";
string strAbsolutePath = (Server.MapPath(".")) + path;

objCSpace.ExportPicture(strAbsolutePath, "GIF", 900, 580);


//创建GIF文件的相对路径.

string strRelativePath = "chart/" + TimeTicks + ".gif";
//把图片添加到placeholder.
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
ChartHolder.Controls.Add(new LiteralControl(strImageTag));
RemoveFiles(Server.MapPath(".") + "\\chart\\");
}

private void RemoveFiles(string strPath)
{
System.IO.DirectoryInfo di = new DirectoryInfo(strPath);
FileInfo[] fiArr = di.GetFiles();
foreach (FileInfo fi in fiArr)
{
if (fi.Extension.ToLower() != ".gif")
{
continue;
}

TimeSpan min = new TimeSpan(0, 0, 0, 2, 0);
if (fi.CreationTime < DateTime.Now.Subtract(min))
{
fi.Delete();
}

}
}
zhuxiaojun2002 2010-06-12
  • 打赏
  • 举报
回复
OWC也可以啊。我最近一个项目用了amchart.很炫
www.amcharts.com

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧