Tuesday, March 20, 2012

Custom Semi-Transparent bar charts?

I know that SSRS 2005 has a built-in semi-transparent color chart palette, but I'd like to define my own custom color semi-transparent palette.

Brian Welker's blog (https://blogs.msdn.com/bwelcker/archive/2005/05/20/420349.aspx) has a terrific post on how to create your own custom color palette, but it generates solid colors. How can it be tweaked to create semi-transparent colors? Is there another function that needs to be created to define the transparency of the color palette?

Thanks in advance,

Pete

Sorry, semi-transparency cannot be achieved by defining your own custom color palette.

There are CustomReportItem-based chart add ins available for RS from third parties (such as Dundas and ChartFX) which will enable that kind of functionality in RS 2005.

-- Robert

|||

Bummer.

Can images be used in charts? (I doubt it, but thought I'd inquire.)

Thanks,
Pete

|||

Yes, you can use an image as a background image for the chart plotarea (select the chart and look for the BackgroundImage property in the VS properties window).

-- Robert

|||

I should have made my followup question clearer. I meant to ask if images can be used in the actual charting of values, for example to use an image of coins for bar charts whereby the bars on the chart are actually a "stack" of the coins. Or to use an image that gets "stretched" on the bars of a bargraph.

--Pete

|||

I believe the plug-in from Dundas ("Dundas Charts for Reporting Services") supports this, but you would need to check with them. It is not supported out of the box with the built-in charts.

-- Robert

|||

Transparency is more than possible with ANY system palette or custom palette.
The trick (work-around whatever) lies in modifying the 'alpha' component of the colour for each series in the chart AFTER they have had their colour assigned to them.

ie. i used the code

//set the transparency of the series
if(_abstractChart.Options.Transparency > 0) {
//get the transparency as a percentage
double transPerc = _abstractChart.Options.Transparency / 100.00;
//Alpha value 255 is opaque, 0 is transparent. set the transparency as a % of 255
int alphaValue = (int) (255 * (1-transPerc));
_chart.ApplyPaletteColors();
foreach(Series series in _chart.Series) {
series.Color = Color.FromArgb(alphaValue, series.Color.R, series.Color.G, series.Color.B);
}
}

where
-abstractChart.Options.Transparency is the integer value (between 0 and 100 inclusive) denoting the transparent %.
-_chart is a Dundas.Charting.WebControl.Chart

in my C# application, a percentage value is retrieved from the user from an aspx form. I subtract the tranparent component of the alpha value from the max (255) to get the Opacity, which is what i set in the colour. Giving the user 101 grades of tranparency (no pun intended).

HOWEVER, i actually have a problem. Though this method works fine for bar chart, radar, area line charts, it DOES NOT work for pie charts. The semi-transparent palette works for pie charts, but this method does not.

Perhaps someone with more knowledge of the dundas system could use my solution in the right place to achieve transparency for pie charts?

please?

I thought maybe using this method in Customize, PrePaint or PostPaint event would work. Havent had the chance to try it yet.
Cheers

|||

Okay, i figured it out.
A bar chart has one series object in the Dundas.Charting.WebControl.Chart.Series[] of the chart for every bar, so setting the colour of the series would apply to the bar which that series plots.
A pie chart has one series object for the whole chart, and the slices are individual datapoints within that series.
The solution quite simply is to add another level to the loop which iterates through every datapoint of the current series.
If processing time is a concern there should be a check present for whether the second loop is necessary (so far i have only found it necessary within PIE charts)
if(abstractChart.Options.Transparency > 0) {
//get the transparency as a percentage
double transPerc = abstractChart.Options.Transparency / 100.00;
//Alpha value 255 is opaque, 0 is transparent. set the transparency as a % of 255
int alphaValue = (int) (255 * (1-transPerc));
chart.ApplyPaletteColors();
foreach(Series series in chart.Series) {
if(abstractChart.GetChartType != ChartType.Pie) {
series.Color = Color.FromArgb(alphaValue, series.Color.R, series.Color.G, series.Color.B);
}
else{
foreach(DataPoint dp in series.Points) {
dp.Color = Color.FromArgb(alphaValue, dp.Color.R, dp.Color.G, dp.Color.B);
}
}
}
}
Where
-abstractChart.Options.Transparency is the integer value (between 0 and 100 inclusive) denoting the transparent %.
-_chart is a Dundas.Charting.WebControl.Chart
-abstractChart.ChartType is an identifier for the type of chart we are plotting (Abstract Chart is one of MY classes, as is ChartType)

By the way, this code is called after the chart object has been created, but before returning from the method which created the chart object.
IE.
public Dundas.Charting.WebControl.Chart MakeChart(){
Dundas.Charting.WebControl.Chart chart = new Dundas.Charting.WebControl.Chart();
..
..
..
..
<transparency code>
..
..
..
return chart;
}
any questions?
LiLbUg@.ozemate.com

|||

just an out of topic question: sorry because i need an answer really fast hope you understand....

Hi everyone,

I just inquiring if the 'My subscription' toolbar at the upper right portion of the report manager can be removed? or shall we say hide... If possible, how to remove please help...

Another question is when you click the show details button, the option to delete and move appears but it is initially disabled...is there a way also to hide the move button?

thank you very much...hope to have any response or advice as soon as possible...thanks

|||

Hello Thor:

Interesting... I'm a little confused, though. Is your code affecting the Dundas charting component or are you suggesting a way to create charting transparency in reporting services without the need for a third party add-in like Dundas (or ChartFX)?

Thanks,

Pete

|||

hey pete

yeh, not sure what you mean, theres alot of syllables in some of those words.
To try to answer your question; i'm using dundas, and the code i supplied directly changes the colour value for datapoint objects/series objects inside a DUNDAS chart. IE i assign a new colour for each datapoint/series in the code, in this case the new colour is the same as the old one (which is assigned from the palette) except the alpha value has been changed.
effectively, any palette can therefore have transparency applied to it, retaining the oiginal colours of the palette.
SO... i think the answer to your question is that this code NEEDS dundas and i affect the instance of the dundas charting component to create transparency.
but technically this should work for any charting tool that allows you to modify the colour of the datapoints in a series after they have been assigned a colour and before they are drawn.
ps. last time i ran my app. it changed the colour for the whole pie chart to the colour of the first datapoint. i think this code would have to be in the PrePaint event (its worked there before).
ill post again when i know for sure.

...Edit...
just read the top post again, and realised you're not using dundas. for some reason i thought this was all about dundas.
anyways, this should work for that charting thing you use IF you can change the colours of the series / datapoints at the right time. Might take some experimenting to figure out where, or even if you can do it.

sql

No comments:

Post a Comment