Problems in generating a chart with 2 series using OWC11

N

Noman Ali

Hi,

I am new in using OWC11. I am generating a chart using the C# code below.
The problem is that the second series bars are not shown in chart. I also
want to know how can i get the right percentage as it gives me always 100
percantage.


ChartSpaceClass oChartSpace = new ChartSpaceClass();

string[] aNames = new string["1", "2" , "3"];

string[] aTotals = new string["3", "4", "5"];

string[] aWeightage = new string["10", "11", "12"];

string[] companyTotals = new string["5","6","7"];

tring names = String.Empty;

string totals = String.Empty;

string weightage = String.Empty;

string company = String.Empty;

//Chart control accepts tab-delimited string of values

names = String.Join("\t", aNames);

totals = String.Join("\t", aTotals);

weightage = String.Join("\t", aWeightage);

company = String.Join("\t", companyTotals);

oChartSpace.Charts.Add(0);

oChartSpace.Charts[0].Type =
(ChartChartTypeEnum)((int)Session["ChartType"]);

oChartSpace.Charts[0].SeriesCollection.Add(0);

oChartSpace.Charts[0].SeriesCollection[0].Caption = "Employee Parameters
Average";

oChartSpace.Charts[0].SeriesCollection.Add(1);

oChartSpace.Charts[0].SeriesCollection[1].Caption = "Company Parameters
Average";

oChartSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,

Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), names);

oChartSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,

Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), totals);


oChartSpace.Charts[0].SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories,

Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), names);

oChartSpace.Charts[0].SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues,

Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), companyTotals);

// Display the title for the chart

oChartSpace.Charts[0].HasTitle = true;

oChartSpace.Charts[0].Title.Caption = "Employee OverAll Appraisal";

oChartSpace.Charts[0].Axes[0].HasTitle = true;

oChartSpace.Charts[0].Axes[0].Title.Caption = "Parameter";

oChartSpace.Charts[0].Axes[1].HasTitle = true;

oChartSpace.Charts[0].Axes[1].Title.Caption = "Score";

oChartSpace.Charts[0].Axes[1].Scaling.Minimum = 0;

oChartSpace.Charts[0].Axes[1].Scaling.Maximum = 15;

oChartSpace.Charts[0].HasLegend = true;

for (int i = 0; i <= 3; i++)

{

ChDataLabels a =
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add();

a.HasPercentage = true;

a.HasValue = true;

}

long ticks = DateTime.Now.Ticks;

string strFullPathAndName = Server.MapPath("~/images/graphs/" + userName +
"graph" + ticks + ".gif");
//Server.MapPath(System.DateTime.Now.Ticks.ToString() + ".gif");

oChartSpace.ExportPicture(strFullPathAndName, "gif", 640, 480);
 
S

Steven Cheng[MSFT]

Hello Noman,

From your description and the code snippet you provided, you're using the
OWC webcontrol to generate some chart(as image) in .NET web application and
display it to web clients. However, you found that the generated chart has
the following problems:

** only one of the two ChartSeries added displayed in the chart

** the percentage value doesn't display correctly(always 100%)

I've tried running the code in my local environment and also met the
following problem:

** in the code you provided, you use a Session variable to determine the
chart type, would tell me what's the exact type you'll use at runtime?

** When I tried some chart type like Pie type, it will report exception
about some arguments.

also, I've found that "HasPercentage" property is working for some certain
chart type as mentioned below:

http://msdn.microsoft.com/library/en-us/owcvba11/html/ocproHasPercentage_HV0
5259474.asp?frame=true

Please let me know the exact chart type so that we can perform further test
on this. Also, if you have any other finding, please feel free to post here
also.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Noman Ali

Yes, I am using OWC to generate charts in ASP .NET.

The code I provided is simplified version of what is actual(which gets
values from database).

For this data I want to show a chart as described

// Parameters names

string[] aNames = new string["Parameter1", "Parameter2" , "Parameter3"];

// Employee averages on paramters

string[] aTotals = new string["3", "4", "5"];

// Company averages of each parameter

string[] companyTotals = new string["5","6","7"];

// Wiegtage of each Parameter

string[] aWeightage = new string["10", "11", "12"];

Now, the chart should have two series one for employee and one for company
in order to compare them.

I also want percantage shown based on the weightage array.

Can you provide me an example how to show percentage and how to show 2
series simultaneously.
 
P

Peter Huang [MSFT]

Hi Noman,

Currently we are researching the issue and we will update you ASAP.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Noman,

From your description, I understand your scenairo is that you want to build
a chart with two Series
Based on my test, per the document the HasPercent will only work for a few
type chart.
Here are code lines for building a Pie chart with percent which will work.
Dim MyTitle As String
MyTitle = "Sale amount"
ChartSpace1.Clear
ChartSpace1.HasChartSpaceTitle = True
ChartSpace1.ChartSpaceTitle.Caption = MyTitle
ChartSpace1.ChartSpaceTitle.Font.Bold = True
Dim objChart0
Set objChart0 = ChartSpace1.Charts.Add
ChartSpace1.Charts(0).Type =
ChartChartTypeEnum.chChartTypePieStacked
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).Legend.Position =
ChartLegendPositionEnum.chLegendPositionRight
With ChartSpace1.Charts(0).SeriesCollection.Add
..SetData ChartDimensionsEnum.chDimCategories,
ChartSpecialDataSourcesEnum.chDataLiteral, Array("ProductA", "ProductB",
"ProductC", "ProductD", "ProductE", "ProductF")
..SetData ChartDimensionsEnum.chDimValues,
ChartSpecialDataSourcesEnum.chDataLiteral, Array(100, 30, 25, 60, 85, 165)
.DataLabelsCollection.Add.HasPercentage = True
End With

HOW TO: Find Office Web Components (OWC) Programming Documentation and
Samples
http://support.microsoft.com/default.aspx?scid=kb;en-us;319793

Also here is the code snippet for build two Series on one chart.
How To Create a Combination Chart Using the Office XP Chart Component or
the Office 2003 Chart Component
http://support.microsoft.com/kb/286211/

Because the we can not draw Chart and Line on same chart, so I would
suggest you create another chart to show the percent as Pie.
And use the KB above to build two Series on one chart of type
chChartTypeLine and chChartTypeColumnClustered.

You may have a look and let me know if that works for you.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Noman Ali

Based on my test, per the document the HasPercent will only work for a few
type chart.
I have seen percentage on bars graphs in OWC which are exactly what i am
using.
I think i have to set wieghtage (or may be something like Max values) so OWC
will calculate percentage but i dont know how to do this.
I tried
oChartSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimMaxValues,

Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral),weightage);

I tried different option but they thowrs an exception that this option is
not allowed on this graph..


How To Create a Combination Chart Using the Office XP Chart Component or
the Office 2003 Chart Component
http://support.microsoft.com/kb/286211/
Now, i understand the problem that why second series is not showing. The
2nd series is right behind the first one i.e they overlaps. So, only first
series is shown.

The axes needs to be changed for second series like the code in article is

' Ungroup the series so that they can have separate value-axis scaling.
oSeries2.Ungroup True

' Add a new value-axis for the second series. Position the new axis on
the right side
'of the chart and modify the gridlines and numberformat.
Set oAxis2 = oChart.Axes.Add(oSeries2.Scalings(oConst.chDimValues))
oAxis2.Position = oConst.chAxisPositionRight
oAxis2.HasMajorGridlines = False
oAxis2.NumberFormat = "0%"


While converting this code in C# there is no Series.Scaling function.

The following line is not compiling

' Add a new value-axis for the second series. Position the new axis on the
right side
'of the chart and modify the gridlines and numberformat.
Set oAxis2 = oChart.Axes.Add(oSeries2.Scalings(oConst.chDimValues))


It seems that series has a function Scaling which is actually not at my end.
The equivalent C# code is

ChAxis oAxis2 =
oChartSpace.Charts[0].Axes.Add(oChartSpace.Charts[0].SeriesCollection[1].Scaling(oChartSpace.Constants.chDimValues));

which gives compilation error.

Any idea?

I have seen
 
P

Peter Huang [MSFT]

Hi

For Question #1, can you provide more information about a screen shot or
something else about the Bar type chart.
Also I will try to do further research on this issue about if Bar chart is
valid for HasPercent which contradict the document.


#Question 2, Here I provide the full C# code for the KB I provide.
BTW: We did not recommend you run Office application in server
side(ASP.NET), commonly OWC is used in client script, i.e. it actually at
client desktop, but not ASP.NET server side.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OWC = Microsoft.Office.Interop.Owc11;
namespace WindowsApplication18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
OWC.ChChart oChart;
OWC.ChSeries oSeries1;
OWC.ChSeries oSeries2;
OWC.ChAxis oAxis1;
OWC.ChAxis oAxis2;
axChartSpace1.Clear();
oChart = axChartSpace1.Charts.Add(0);
oSeries1 = oChart.SeriesCollection.Add(0);
oSeries1.Caption = "Sales";
oSeries1.SetData(OWC.ChartDimensionsEnum.chDimCategories,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, new object[] { "A",
"B", "C", "D" });
oSeries1.SetData(OWC.ChartDimensionsEnum.chDimValues,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, new object[] { 5000,
6025, 5575, 5900 });
oSeries1.Type =
OWC.ChartChartTypeEnum.chChartTypeColumnClustered;
oSeries2 = oChart.SeriesCollection.Add(1);
oSeries2.Caption = "Discount";

oSeries2.SetData(OWC.ChartDimensionsEnum.chDimCategories,(int)OWC.ChartSpeci
alDataSourcesEnum.chDataLiteral, new object[] { "A", "B", "C", "D" });

oSeries2.SetData(OWC.ChartDimensionsEnum.chDimValues,(int)OWC.ChartSpecialDa
taSourcesEnum.chDataLiteral, new object[] { 0.1, 0.2, 0.1, 0.15 });
oSeries2.Type = OWC.ChartChartTypeEnum.chChartTypeLine;

oAxis1 =
oChart.Axes[OWC.ChartAxisPositionEnum.chAxisPositionLeft];
oAxis1.Scaling.Maximum = 8000;
oAxis1.Scaling.Minimum = 0;
oAxis1.NumberFormat = "$0";
oAxis1.HasMajorGridlines = false;
oSeries2.Ungroup(true);

oAxis2 =
oChart.Axes.Add(oSeries2.get_Scalings(OWC.ChartDimensionsEnum.chDimValues));
oAxis2.Position = OWC.ChartAxisPositionEnum.chAxisPositionRight;
oAxis2.HasMajorGridlines = false;
oAxis2.NumberFormat = "0%";

oChart.HasLegend = true;
oChart.Legend.Position =
OWC.ChartLegendPositionEnum.chLegendPositionBottom;

oChart.HasTitle = true;
oChart.Title.Caption = "Sales & Discounts";
}
}
}


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Noman,

Thanks for your input, I am not sure what is your goal.
Based on my understanding, the code I posted in my last post will show a
Line series and a bar series, they two will compare each other.
Can you show more information about what is your goal?
Or draw something more on the pic, so that I can understand your idea?

If you have any concern on this issue, please feel free to let me know.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Noman,

I am just checking to see how this is going.
Please drop me a quick note at your convenience to let me know the current
status of this issue.
Based on my discussion with other senior engineers, it seems that the Bar
type chart showed 100% for all the bars is by design.

If you have any concerns, please do not hesitate to let me know.
Thanks, and have a great day! :)

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Noman,

"The attached picture is the output i want. Two side by series but when i
used the similar C# code in ASP.NET to generate chart image. I get the
picture which is attached. "

From your description, I am somewhat confused. The attached picture in your
last post is what you want or your did not want.

Anyway, you may try to the C# code below to see if the result is you want
and let me know the result.
OWC.ChChart oChart;
OWC.ChSeries oSeries1;
OWC.ChSeries oSeries2;

axChartSpace1.Clear();
oChart = axChartSpace1.Charts.Add(0);
oSeries1 = oChart.SeriesCollection.Add(0);
oSeries1.Caption = "Sales";
oChart.Type =
Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered;
oSeries1.SetData(OWC.ChartDimensionsEnum.chDimCategories,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, new object[] { "A",
"B", "C", "D" });
oSeries1.SetData(OWC.ChartDimensionsEnum.chDimValues,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, new object[] { 100, 30,
25, 60, 85, 165 });
oSeries1.DataLabelsCollection.Add().HasPercentage = true;

oSeries2 = oChart.SeriesCollection.Add(1);
oSeries2.Caption = "Discount";

oSeries2.SetData(OWC.ChartDimensionsEnum.chDimCategories,(int)OWC.ChartSpeci
alDataSourcesEnum.chDataLiteral, new object[] { "A", "B", "C", "D" });
oSeries2.SetData(OWC.ChartDimensionsEnum.chDimValues,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, new object[] { 50, 75,
96, 23, 5, 65 });
oSeries2.DataLabelsCollection.Add().HasPercentage = true;

oChart.HasLegend = true;
oChart.Legend.Position =
OWC.ChartLegendPositionEnum.chLegendPositionBottom;

oChart.HasTitle = true;
oChart.Title.Caption = "Sales & Discounts";

If you still have any other concern, please feel free to let me know.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Noman Ali

I mean to say that your attached picture is what i want and my attached
picture is what i am getting using the code provided later and also the one
which is below.
 
P

Peter Huang [MSFT]

Hi Noman,

Thanks for your clarification.
In last Email I post the C# code, have you tried that, did that work for
you?

Also for the issue about the percentage based on a weightage, I think you
may try to calculate the weightage in the code.
e.g. we provide Array(100, 30, 25, 60, 85, 165) to the Chart, so if we want
to add the weightage, we just need to recalculate the result with Weight.
the weight is 1,2,3,4,5,6
so the result will be
100*1,30*2,25*3,60*4,85*5,165*6


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top