如何使用Epplus将两个具有不同类型图表的系列放置在控制图中? [英] How to put two series with different types of charts inside a control chart using Epplus?

查看:78
本文介绍了如何使用Epplus将两个具有不同类型图表的系列放置在控制图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 EPPLUS 将两种类型的图表组合为一个图形图表,希望能为您提供帮助

I am trying to combine two types of graphs into a single graphical chart using EPPLUS, I would appreciate if you could help me

controller.cs

controller.cs

public ActionResult ExportarExcel()
{    
    var myChart2 = ws.Drawings.AddChart("chart", eChartType.ColumnClustered);

    /*//Define las series para el cuadro
    var series = myChart.Series.Add("C7: E7", "C6: E6");
    myChart.Border.Fill.Color = System.Drawing.Color.Green;
    myChart.Title.Text = "My Chart";
    myChart.SetSize(500, 400);

    //Agregar a la 6ta fila y a la 6ta columna
    myChart.SetPosition(6, 0, 10, 0);*/



    //Define las series para el cuadro
    /*var series = myChart2.Series.Add("C7: E7", "C6: E6");
    myChart2.Border.Fill.Color = System.Drawing.Color.Green;
    myChart2.Title.Text = "My Chart";
    myChart2.SetSize(500, 400);*/


    //Agregar a la 6ta fila y a la 6ta columna
    myChart2.SetPosition(6, 0, 10, 0);

    ws.Cells["A:AZ"].AutoFitColumns();


    MemoryStream memoryStream = new MemoryStream();
    pkg.SaveAs(memoryStream);
    memoryStream.Position = 0;

    return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = "Gestion_horas.xlsx" };
}

我想从我的应用程序中获取的数据获取的图像样本

Sample of the image that I want to obtain with the data that I bring from my application

推荐答案

以下是对我的评论的正确答案.如果需要,只需将 myChart2 放在 myChart1 的区域内:

Here is a proper answer to my comment. Just need to put myChart2 inside of myChart1's area if that makes sense:

[TestMethod]
public void Chart_Two_Series()
{
    //https://stackoverflow.com/questions/57500910/how-to-put-two-series-with-different-types-of-charts-inside-a-control-chart-usinvar existingFile = new FileInfo(@"c:\temp\temp.xlsx");
    var fileInfo = new FileInfo(@"c:\temp\Chart_Two_Series.xlsx");
    if (fileInfo.Exists)
        fileInfo.Delete();

    using (var pck = new ExcelPackage(fileInfo))
    {
        var ws = pck.Workbook.Worksheets.Add("Content");

        //Some data
        ws.Cells["C5"].Value = "amarillo";
        ws.Cells["C6"].Value = 12;
        ws.Cells["C7"].Value = 485;

        ws.Cells["D5"].Value = "rojo";
        ws.Cells["D6"].Value = 121;
        ws.Cells["D7"].Value = 77;

        ws.Cells["E5"].Value = "verde";
        ws.Cells["E6"].Value = 548;
        ws.Cells["E7"].Value = 44;

        var myChart = ws.Drawings.AddChart("chart", eChartType.ColumnClustered);

        //Define las series para el cuadro
        var series = myChart.Series.Add("C6:E6", "C5:E5");
        myChart.Border.Fill.Color = System.Drawing.Color.Green;
        myChart.Title.Text = "My Chart";
        myChart.SetSize(500, 400);

        //Agregar a la 6ta fila y a la 6ta columna
        myChart.SetPosition(6, 0, 10, 0);

        //Define las series para el cuadro
        var myChart2 = myChart.PlotArea.ChartTypes.Add(eChartType.Line);
        var series2 = myChart2.Series.Add("C7:E7", "C5:E5");

        ws.Cells["A:AZ"].AutoFitColumns();
        pck.Save();
    }
}

哪个在输出中给出:

这篇关于如何使用Epplus将两个具有不同类型图表的系列放置在控制图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆