Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use WPF Chart LiveChart

Shulou Source: shulou.com Published: 2022-06-01 20:03:16 09月14日 Update

This article mainly introduces the "WPF Chart LiveChart how to use" related knowledge, Xiaobian through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope this "WPF Chart LiveChart how to use" article can help you solve the problem.

Import LiveChart.Wpf

NuGet searches for the LiveChart package and installs LiveChart.Wpf.

Quote LiveChart.Wpf

Reference LiveChart.Wpf 's class library in the interface you are using

Xmlns:lvc= "clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"

For example, histograms and broken lines belong to a type of Series under CartesianChart, such as line charts, as follows:

LinSeries binding data can be set to Values. If you can see it with s, it means that it is a plural collection type, which is inherited from IChartValues, so the final bound data conforms to ChartValues. The following figure binds a collection of numeric types:

The interface appears as follows:

Next, take LineSeries as an example to expand and add the definition display of X and Y coordinates.

Add a title to the X and Y axes of LiveChart

The effect is as follows:

Chart display Settings

1. Where the legend is displayed: LegendLocation= "Top" / / shown at the top

two。 Background color of the chart: Background= "# FFEFD5"

As follows:

3. Add visual element: VisualElements

Add a text to the chart as follows:

Hello!, this is a note merged in the chart.

Display effect:

LineSeries style settin

1. Line display value: DataLabels= "True"

two。 Whether the line is bent: LineSmoothness= "0" or "1"

3. Color of lines: Stroke= "Red" / / sets the color of lines to red

4. Color below the line: Fill= "Pink" / / the color below the line

5. Each point of the line: PointGeometrySize= "20" / / sets the data point size

6. Display data font color: Foreground= "Red"

7. Color of the data point: PointForeground= "# FF6347"

8. Line dotted line: the larger the StrokeDashArray= "5" / / value, the larger the interval, as shown in the green dotted line

9. The shape of the bar point: PointGeometry / / as shown below, set to a rectangle for the data point

The effect is as follows:

X, Y coordinate style settin

1. Whether to display coordinate points: ShowLabels= "False"

two。 Rotation angle of coordinate points: LabelsRotation= "45"

3. Axis label: Labels= "A, B, C, D, E, F" / / example

4. Custom display format: LabelFormatter

Whether the chart shows background X and Y lines:

The following code sets a solid red line with a width of 1 on the X and Y axes:

The effect is as follows:

Define pie chart

Since the pie chart does not have the concept of X and Y axes, if you need to use a pie chart, use PieChart.

1. Set the format of the display data: LabelPoint / / the binding is a Func delegate

Xaml binding:

Background code and display effect:

This is the end of the introduction to "how to use WPF Chart LiveChart". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Lines colors charts data effects coordinates knowledge types codes numerical values punctuation styles formats interfaces red line graphs backgrounds dashed lines industries different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Xiaomi Shulou Information Huawei