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.

Fri Feb 22, 2019 5:45 pm

Hello! I have a problem with the column's color of a chart with a single serie.
If the value is negative, the color of the column is transparent. And i set that all the columns must be Blue. If the value is positive, the column is blue.

Here is my code.

createPowerpoint()
{
presentation.Slides.Append();

//insert chart
RectangleF rect = new RectangleF(50, 50, 600, 400);

IChart chart = presentation.Slides[5].Shapes.AppendChart(ChartType.ColumnClustered, rect);





//add chart Title


chart.ChartTitle.Height = 30;

chart.HasTitle = true;


//load data

DataTable dataTable = LoadData();

//load data from datatable to chart

InitChartData(chart, dataTable);

chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];

chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];


chart.Series[0].Values = chart.ChartData["B2", "B5"];

chart.Series[0].Fill.SolidColor.Color =Color.Blue;

chart.Series[0].Fill.FillType = FillFormatType.Solid;

chart.HasLegend = false;




chart.PrimaryValueAxis.HasTitle = true;

chart.PrimaryValueAxis.Title.TextProperties.Text = "Title";


}


//function to load data from XML file to DataTable

private DataTable LoadData()

{


DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Categoria"));
dt.Columns.Add(new DataColumn("Valor"));


DataRow dr1 = dt.NewRow();
dr1["Categoria"] = "Category 1";
dr1["Valor"] = 0;
dt.Rows.Add(dr1);

DataRow dr2 = dt.NewRow();
dr2["Categoria"] = "Category 2";
dr2["Valor"] = -1;
dt.Rows.Add(dr2);


DataRow dr3 = dt.NewRow();
dr3["Categoria"] = "Category 3";
dr3["Valor"] = -4;
dt.Rows.Add(dr3);

DataRow dr4 = dt.NewRow();
dr4["Categoria"] = "Category 4";
dr4["Valor"] = 32;
dt.Rows.Add(dr4);

return dt;

}



//function to load data from DataTable to IChart

private void InitChartData(IChart chart, DataTable dataTable)

{

for (int c = 0; c<dataTable.Columns.Count; c++)

{

chart.ChartData[0, c].Text = dataTable.Columns[c].Caption;

}

for (int r = 0; r<dataTable.Rows.Count; r++)

{

object[] data = dataTable.Rows[r].ItemArray;

for (int c = 0; c<data.Length; c++)



{
if (c == 0)
chart.ChartData[r + 1, c].Value = data[c];
else
{
chart.ChartData[r + 1, c].Value = decimal.Parse(data[c].ToString());
}

}



}

}

gargamuza
 
Posts: 2
Joined: Fri Sep 13, 2013 12:40 pm

Mon Feb 25, 2019 4:27 am

Hello,

Thanks for your letter.
I tested your case with the latest Spire.Presentation Pack Hotfix Version:4.2.1 and didn't reproduce your issue. It could generate the correct PPT file like the attached document. If you were using an old version, I suggest you download the latest version to try again. If there is still any issue after trying, please provide your system configuration (E.g. Win7 64 bit) and region settings(E.g. China/Chinese) to help further look into it.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Mon Feb 25, 2019 7:41 pm

Yes, it's true. With the new version the problem es gone. Thanks!

gargamuza
 
Posts: 2
Joined: Fri Sep 13, 2013 12:40 pm

Tue Feb 26, 2019 1:26 am

Hello,

Glad to hear that. Just feel free to contact us if you need any assistance in the future. Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Presentation