我制作了一个以 PDF 格式导出的图表。但是客户希望每个 x 轴间隔之间的间隙为 25 毫米,因为它是心电图图,并且每个 y 轴之间的间隙在打印在纸上时应为 5 毫米。
我有一个 CSV 文件,其中包含以毫秒为单位的 x 轴数据和 y 轴数据,我必须以秒为单位显示 x 轴,间隔为 1 秒。我已经打破了列表中的 CSV 数据,以便每个图表在 x 轴上只能包含 7 秒。功能工作正常,但我如何调整图表,以便在纸上打印时心电图图表可以显示 25 毫米的 x 轴间隔间隙。是否有任何第三方工具可以实现或显示它就像在坐标纸(图形背景或 ECG 图形背景)上绘制的一样,X 轴上 25 毫米/秒
因为它必须被导出,所以我不能使用 java 脚本或 jquery,因为它省略了标签。
下面是我的代码
private Byte[] GetChart(List<string[]> data)
{
var chart = new Chart
{
Width = 1000,
Height = 450,
RenderType = RenderType.ImageTag,
AntiAliasing = AntiAliasingStyles.All,
TextAntiAliasingQuality = TextAntiAliasingQuality.High
};
chart.Titles.Add(string.Empty);
chart.Titles[0].Font = new System.Drawing.Font("Arial", 16f);
chart.ChartAreas.Add("");
chart.ChartAreas[0].AxisX.Title = "Speed:25/Sec";
chart.ChartAreas[0].AxisY.Title = "Gain:10mm/mV";
chart.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Arial", 12f);
chart.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Arial", 12f);
chart.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Arial", 10f);
chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
chart.ChartAreas[0].BackColor = System.Drawing.Color.White;
chart.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Auto;
chart.ChartAreas[0].AxisY.IntervalOffsetType = DateTimeIntervalType.Auto;
chart.ChartAreas[0].AxisX.Interval = 1;
chart.Series.Add("");
chart.Series[0].ChartType = SeriesChartType.Line;
foreach (var item in data)
{
double xval = Convert.ToDouble(item[0]) / 1000;
chart.Series[0].Points.AddXY(xval, item[1]);
}
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
}
public ActionResult ExportDataToPDF()
{
//Create the PDF Document
Document pdfDoc = new Document(PageSize.A4);
pdfDoc.SetMargins(30f, 30f, 60f, 30f);
//open the stream
pdfDoc.Open();
List<string[]> data = GetCSVData();
if (data.Count > 0)
{
double d = 0;
double.TryParse(data.LastOrDefault()[0], out d);
d = d / 1000;
double totalchart = Math.Ceiling(d / 7);
long startrange = 0; long endrange = 7000;
for (int i = 0; i < totalchart; i++)
{
var lst = data.Where(e => Convert.ToDouble(e[0]) > startrange && Convert.ToDouble(e[0]) <= endrange).ToList();
var image = iTextSharp.text.Image.GetInstance(GetChart(lst));
image.ScalePercent(50f);
pdfDoc.Add(image);
startrange = endrange;
endrange = endrange + 7000;
}
}
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;" + "filename=EcgReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
return View();
}
public List<string[]> GetCSVData()
{
var csv = new List<string[]>(); // or, List<YourClass>
string path = Server.MapPath("~/Files/ecg_asc1011100000318g_20121115144350032.csv");
var lines = System.IO.File.ReadAllLines(path);
string[] myColumns = new string[90];
foreach (string line in lines)
{
csv.Add(line.Split(',')); // or, populate YourClass
}
return csv;
}