今天弄這個NetAdvantage畫圖表的東西,沒有接觸過,現在要下載圖片,還要在柱狀圖的上面顯示數值,糾結了一下午,搞定了。
這里只說下載圖片和柱狀圖最上方加數值的問題
1、柱狀圖上顯示數值
//第一種方法
this.UltraChartSScore.Data.ZeroAligned = true;
this.UltraChartSScore.DataSource = dt.DefaultView;
this.UltraChartSScore.DataBind();
ChartTextAppearance text = new ChartTextAppearance();
text.Column = -2;
text.Row = -2;
text.PositionFromRadius = 50;
text.VerticalAlign = System.Drawing.StringAlignment.Far;
text.ItemFormatString = "<DATA_VALUE:00.00>";
text.Visible = true;
UltraChartSScore.ColumnChart.ChartText.Add(text);
this.UltraChartSScore.TitleTop.Text = "主項S得分對比柱狀圖";
//第二種方法(一個一個的添加)
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < 4; j++)
{
ChartTextAppearance text = new ChartTextAppearance();
text.Row = i;
text.Column = j;
text.VerticalAlign = System.Drawing.StringAlignment.Far;
text.ItemFormatString = "<DATA_VALUE:00.00>";
text.Visible = true;
chart.ColumnChart.ChartText.Add(text);
}
}
2、導出圖片
//一定要先綁定UltraChart,如果先綁定,然后有點擊圖片導出,沒有用的
string fulPath="xxxx";
this.UltraChartTScore.SaveTo(fulPath, System.Drawing.Imaging.ImageFormat.Jpeg);//這個是保存為圖片的方法
System.IO.FileInfo file = new System.IO.FileInfo(strFileFullPath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/x-msdownload";
Response.WriteFile(strFileFullPath);
Response.Flush();
file.Delete();
Response.End();
