Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Wed Apr 08, 2020 2:18 pm

Hi
I want to draw a chart .
please find the uploaded chart type.please help me to draw the same chart which is attached in file.

Regards,
Anusha

AnuH365068
 
Posts: 13
Joined: Wed Mar 04, 2020 10:45 am

Thu Apr 09, 2020 2:47 am

Hello,

Thanks for your inquiry.
Below is the sample code for reference. Please download the latest Spire.Presentation Pack Hotfix Version:5.3.6 for testing.
Code: Select all
        //Create a PowerPoint document
        Presentation presentation = new Presentation();

        //Add a "BarClustered" chart to the first slide
        presentation.SlideSize.Type = SlideSizeType.Screen16x9;
        SizeF slidesize = presentation.SlideSize.Size;

        var slide = presentation.Slides[0];
        RectangleF rect = new RectangleF(20, 20, slidesize.Width - 40, slidesize.Height - 40);
        IChart chart = slide.Shapes.AppendChart(Spire.Presentation.Charts.ChartType.BarClustered, rect);

        //Create a datatable
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Date", Type.GetType("System.String")));
        dt.Columns.Add(new DataColumn("Sales", Type.GetType("System.Double")));
        dt.Rows.Add("2020/1/1", 455.41);
        dt.Rows.Add("2020/1/2", 777.19);
        dt.Rows.Add("2020/1/3", 1249.61);
        dt.Rows.Add("2020/1/4", 1327.58);
        dt.Rows.Add("2020/1/5", 3245.48);
        dt.Rows.Add("2020/1/6", 3416.16);
        dt.Rows.Add("2020/1/7", 14224.41);
        dt.Rows.Add("2020/1/8", 18227.57);
        dt.Rows.Add("2020/1/9", 22998.39);
        dt.Rows.Add("2020/1/10", 99186.24);

        //Import data from datatable to chart data
        for (int c = 0; c < dt.Columns.Count; c++)
        {
            chart.ChartData[0, c].Text = dt.Columns[c].Caption;
        }
        for (int r = 0; r < dt.Rows.Count; r++)
        {
            object[] datas = dt.Rows[r].ItemArray;
            for (int c = 0; c < datas.Length; c++)
            {
                chart.ChartData[r + 1, c].Value = datas[c];
            }
        }

        chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, dt.Columns.Count - 1];
        chart.Categories.CategoryLabels = chart.ChartData[1, 0, dt.Rows.Count, 0];

        //Set the position of category axis
        chart.PrimaryCategoryAxis.Position = AxisPositionType.Left;
        chart.SecondaryCategoryAxis.Position = AxisPositionType.Left;
        chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionLow;

        //Set the data, font and format for the series of each column
        for (int c = 0; c < dt.Columns.Count - 1; ++c)
        {
            chart.Series[c].Values = chart.ChartData[1, c + 1, dt.Rows.Count, c + 1];
            chart.Series[c].Fill.FillType = FillFormatType.Solid;
            chart.Series[c].InvertIfNegative = false;

            for (int r = 0; r < dt.Rows.Count; ++r)
            {
                var label = chart.Series[c].DataLabels.Add();
                label.LabelValueVisible = true;
                chart.Series[c].DataLabels[r].HasDataSource = false;
                chart.Series[c].DataLabels[r].NumberFormat = "[$$-en-US]#,##0.00";
                chart.Series[c].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 12;
            }
        }

        //Set the color of the Series
        chart.Series[0].Fill.SolidColor.Color = Color.Red;

        TextFont font = new TextFont("Arial");
        //Set the font and size for chartlegend.
        for (int k = 0; k < chart.ChartLegend.EntryTextProperties.Length; k++)
        {
            chart.ChartLegend.EntryTextProperties[k].LatinFont = font;
            chart.ChartLegend.EntryTextProperties[k].FontHeight = 20;
        }

        String result = "BarChart.pptx";

        //Save to file
        presentation.SaveToFile(result, FileFormat.Pptx2013);

If this doesn't meet your needs well, please provide your desired output, so that we could provide you with a corresponding solution.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Apr 10, 2020 7:28 am

Thanks.
I am able to generate the reports.
But i don't want those horizontal grid lines.how to remove them from chart Please suggest.

AnuH365068
 
Posts: 13
Joined: Wed Mar 04, 2020 10:45 am

Fri Apr 10, 2020 8:53 am

Hello,

Thanks for your feedback.
Please refer to the below code snippet. If you have further questions, please feel free to contact us.
Code: Select all
chart.PrimaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Presentation