1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Manco.Chart;
using Manco.Chart.Data;
namespace WpfMancoChart
{
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
public ChartControl m_ChartControl;
private void button1_Click(object sender, RoutedEventArgs e)
{
int liCategoryCount = 2; // Set desirable number of the categories
int liSeriesCount = 2; // Set desirable number of the series
// Declare array of doubles
double[,] ldaData = new double[liCategoryCount, liSeriesCount];
double ldMin = 0;
double ldMax = 40;
// Fill array with data here
Random rnd = new Random();
for (int i = 0; i < liCategoryCount; i++)
{
for (int j = 0; j < liSeriesCount; j++)
{
ldaData[i, j] = ldMin + (ldMax - ldMin) * rnd.NextDouble();
if (j != 3)
{
// Data with regular scale [0...40]
ldaData[i, j] = ldMin + (ldMax - ldMin) * rnd.NextDouble();
}
else
{
// Data with scale different from the regular ([900...1040] series #3)
ldaData[i, j] = 900 + (1040 - 900) * rnd.NextDouble();
}
}
}
// Create IChartDataSource object
IChartDataSource loDataSource = new ArrayDataSource(ldaData, DataOrientation.CategoryInColumn);
// Load data to the chart
m_ChartControl.Charts[5].LoadData(loDataSource, false, true);
// Load theme to decorate chart or assign chart layout settings using API here
// m_ChartControl.LoadTheme("BaseTheme.xml");
// Make third series use own Y-axis (second Y-axis) with own scale.
m_ChartControl.Charts[0].Layout.SeriesList[3].ChartType = Manco.Chart.Layouts.ChartType.Line;
m_ChartControl.Charts[0].Layout.SeriesList[3].ShowSecondYAxis = true;
m_ChartControl.Charts[0].Layout.SeriesList[3].Fill.ShowShadow = false;
//m_ChartControl.Charts[0].Layout.SeriesList[0].Title = "Series #1";
// Set category titles
for (int i = 0; i < liCategoryCount; i++)
{
m_ChartControl.Charts[0].Layout.Categories[i].Title = i.ToString();
if (i % 1 == 0)
{
m_ChartControl.Charts[0].Layout.Categories[i].ShowLabel = true;
}
else
{
m_ChartControl.Charts[0].Layout.Categories[i].ShowLabel = false;
}
}
// Show data points on the line chart
m_ChartControl.Charts[0].Layout.ChartSpecific.Line.ShowDataPoints = true;
// Make data points transparent
m_ChartControl.Charts[0].Layout.ChartSpecific.Line.TransparentDataPoints = false;
// Pay attention. To make datapoints invisible the border around elements should not exist
m_ChartControl.Charts[0].Layout.Element.Border.Width = 0;
// Change scale settings for the second Y-axis (if you'd like - uncomment it)
// Automatic scale for the second Y-axis will be 0...1200
m_ChartControl.Charts[0].Layout.SecondYAxis.ScaleAndGrid.Scale.Min = 900;
m_ChartControl.Charts[0].Layout.SecondYAxis.ScaleAndGrid.Scale.Max = 1040;
// Resume chart layout
m_ChartControl.ResumeChartLayout(false);
// Draw chart
m_ChartControl.Draw();
}
}
} |
Partager