Giter Site home page Giter Site logo

northstarcn / wpfcanvaschart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from igorcrevar/wpfcanvaschart

0.0 0.0 0.0 708 KB

There are controls for: Line series charts, Bar charts, Stacked bar charts, etc. You can also use WPFCanvasChartComponent class directly(look at WPFCanvasChartTest example). The class will do for you things like axis drawing, point translation, zooming, scrolling, etc... Actual chart content is drawn by user. Both WPFCanvasChartComponent and WPFChartControl are fast and customizable.

License: MIT License

C# 100.00%

wpfcanvaschart's Introduction

WPFCanvasChart

Customizable WPF charting for large number of elements

There are controls for: Line series charts, Bar charts, Stacked bar charts, etc. You can also use WPFCanvasChartComponent class directly(look at WPFCanvasChartTest example). The class will do for you things like axis drawing, point translation, zooming, scrolling, etc... Actual chart content is drawn by user. Both WPFCanvasChartComponent and WPFChartControl are fast and customizable.

How to use?

Its easy! Just look at WPFChartControlExample or WPFCanvasChartTest example projects in solution. Using chart control is easy. In XAML:

...
xmlns:chart="clr-namespace:IgorCrevar.WPFChartControl;assembly=WPFChartControl"
...
<chart:ChartControl Drawer="{Binding Path=YourCustomDrawer}" />

In ViewModel you can do something like:

YourCustomDrawer = new LineSeriesChartDrawer(new List<Point> { new Point(10, 20), new Point(20, 40) });

or

YourCustomDrawer = new StackedBarChartDrawer(new List<StackedBarItem>
{
   new StackedBarItem(0, new double[] { 50, 30, 20 }),
   new StackedBarItem(1, new double[] { 100, 0, 100 }),
})
{
	Legend = new LegendItem[]
	{
		new LegendItem(Colors.Blue, "One"),
		new LegendItem(Colors.Red, "Two"),
		new LegendItem(Colors.Yellow, "Total"),
	},
	LegendWidth = 120.0d,
};

or

BarChartDrawer = new BarChartDrawer(new Point[]{
	new Point(1.0d, rnd.Next(100)),
	new Point(2.0d, rnd.Next(100)),
	new Point(3.0d, rnd.Next(100)),
	new Point(4.0d, rnd.Next(100)),
});

etc Check example for more options for every drawer...

Also you can use WPFCanvasChartComponent directly (from WPFCanvasChart project)

  • Before using, instance of WPFCanvasChart must be created
  • after that, you must set min/max x/y of your chart values using WPFCanvasChart instance SetMinMax method
  • you must implement IWPFCanvasChartDrawer interface
  • draw call on WPFCanvasChart instance will draw chart(step above must be executed before drawing!)
  • IWPFCanvasChartDrawer method public void Draw(DrawingContext ctx) is used to draw actual graph
  • Inside public void Draw(DrawingContext ctx) use Point2ChartPoint to convert your actual value to chart point

Note:

Chart is fast if canvas used for charting is inside Viewbox(like in code snippet bellow). If canvas is inside some other container(for example grid like in second code snippet bellow. This is how chart is created inside chart control), than performances dramatically decrease. Why? I do not know yet.

<!-- fast -->
<Viewbox Stretch="Fill" Grid.Row="1">
	<Canvas Name="Canvas" Width="350" Height="190" />
</Viewbox>

<!-- slow :( -->
<Grid Grid.Row="0" Grid.Column="1" Name="CanvasParent" 
	HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
	<Canvas Name="Canvas" Width="{Binding Path=ActualWidth, ElementName=CanvasParent, Mode=OneWay}"
		Height="{Binding Path=ActualHeight, ElementName=CanvasParent, Mode=OneWay}"/>
</Grid>

wpfcanvaschart's People

Contributors

igorcrevar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.