简体   繁体   English

使用EPPlus的C#绘图图,在X轴上的序列号\\数据类似于Y轴

[英]C# Draw Graph using EPPlus with sequential numbers\data in X-Axis similar to Y-Axis

I need to draw a graph in Excel. 我需要在Excel中绘制图形。 I am using EPPLus to create the excel file. 我正在使用EPPLus创建excel文件。

I have data say 我有数据说

P1_Value : 22,43,56,87
P2_Value : 9,2,7,5

Now I need to plot the graph in Excel using EPPLus such that the graph displays sequential numbers in X-Axis ( like how the Y-Axis values are shown across Y-Axis ) instead of having categories on X-Axis; 现在,我需要使用EPPLus在Excel中绘制图形,以使图形在X轴上显示序列号( 例如,如何在Y轴上显示Y轴值 ),而不是在X轴上具有类别。

such that a graph is drawn taking coordinates points as {(22,9),(43,2),(56,7),(87,5)} on the X-Axis & Y-Axis. 这样就可以在X轴和Y {(22,9),(43,2),(56,7),(87,5)}绘制一个坐标为{(22,9),(43,2),(56,7),(87,5)}

But the code I've tried plots the X-Axis with values taking X Value Data as categories and so X-axis has values as Category 9,Category 2, Category 7 ... , instead of sequential values 2,4,6 ... 但是我尝试的代码以X值数据作为类别来绘制X轴的值,因此X轴具有的值为Category 9,Category 2, Category 7 ... ,而不是顺序值2,4,6 ...

My Current code: 我当前的代码:

ExcelLineChart lineChart = workSheet.Drawings.AddChart("lineChart", eChartType.Line) as ExcelLineChart;
        lineChart.Title.Text = GraphTitle;
         var rangeLabel = workSheet.Cells["D2:D2571"];
         var range1 = workSheet.Cells["C2:C2571"];

        lineChart.Series.Add(range1, rangeLabel);

        lineChart.Series[0].Header = workSheet.Cells["A1"].Value.ToString();
         lineChart.Legend.Position = eLegendPosition.Right;
        lineChart.SetSize(600, 300);

        lineChart.SetPosition(5, 0, 1, 0);

My Requirement 我的要求

I need to have X-Axis values as 1,2,3 ... across X-Axis like how 我需要像跨X轴那样将X轴值设置为1,2,3 ...

Y-Axis has values as 100,200 ... Y轴的值为100,200 ...

And the graph should accordingly plot for each coordinate Say for (22,9) at the point 22,9 on the graph. 并且该图应相应地在图的点22,9上针对(22,9)的每个坐标Say作图。

更改图表类型ExcelScatterChartExcelLineChart解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM