ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  WPF Bar Chart Issue
Posted by Rick on Sep-11-2024 22:00
I have a need to add a bar chart to an app that I wrote for my own use. The app displays current data from my backyard weather station. The app uses the WPF MVVM architecture written in C# with Visual Studio 2022 and .NET Framework 4.8. I want to add a bar chart of monthly rainfall for the past 12 months.

I am currently evaluating ChartDirector and while the WPF bar charts work with WPF, they do not support very basic WPF capabilities, like setting chart properties in XAML or with the Property designer, nor do they support data binding facilities. All the properties for a chart, including data and labels are set in code-behind ad runtime.

To overcome this drawback, I am wrapping the ChartDirector BarChart in a WPF UserControl that will let me set chart properties at design-time in XAML, and also allow the data and lables (in my case this is inches of rainfall, and the associated months) via data binding. The chart will still be static, but I am okay with having to re-render the chart when the data changes.

This effort means creating many many dependency properties that associate with the underlying bar chart properties. This brings me to my issue. I am currently looking at the code for the Bar Labels chart from your Sample Charts app.

The Axis.setColors metnod has an argument to set the color of the axis labels -- argument 2. This argument does not appear to work. That is, changing the label color in the call does not affect the foreground color of the label font in the rendered chart. However, a different method, Axis.setLabelStyle does allow me to set the font color of the labels, so I can work around the fact that setColors does not work to set the color of the label font. What I cannot work around is the inabllity to use setColors to make the axis title and axis ticks be the same color as the label font color, as indicated by the documentation.

Is this a documentation error (perhaps it used to work and was deprecated and never removed? is there some different method(s) to set the title and tick colors?

Thanks!

Rick B

  Re: WPF Bar Chart Issue
Posted by Peter Kwan on Sep-12-2024 01:15
Hi Rick,

The followings are two examples that show the labels, titles, axis and ticks all set to the same color:

https://www.advsofteng.com/doc/cdnet.htm#dualyaxis.htm
https://www.advsofteng.com/doc/cdnet.htm#multiaxes.htm

For your case, if it appears the Axis.setColors cannot set the colors but the setLabelStyle can, it is probable because the colors set with Axis.setColors is overwritten by Axis.setLabelStyle. Note that if you call setLabelStyle without providing a color, it defaults black (assume the default palette is used). See:

https://www.advsofteng.com/doc/cdnet.htm#Axis.setLabelStyle.htm

The same applies to Axis.setTitle, which will set the title color and defaults to black.

The solution is to call Axis.setColors after setLabelStyle and setTitle so that the colors specified in Axis.setColors are the final colors.

Best Regards
Peter Kwan