Tutorial 54: Combo 2D charts using C#
« on: February 05, 2016, 01:37:12 AM »
This sample will show how to mix two different 2D charts using C#.
 
Steps:
 
1. Create a new Windows application project (C#) and name it Combo2DCharts.
2. Add Crossing Charts Library to the toolbox palette and drag it to Form1. Name it "CrossingCharts1".
3. Copy and paste de following code:

Code: [Select]
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrossingChartsLibrary;
namespace Combo2DCharts
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Random rnd = new Random();
ArrayList[] arrBarChartValues = new ArrayList[1];
arrBarChartValues[0] = new ArrayList();
CrossingCharts1.AutoRefresh = false; // Increase speed
CrossingCharts1.Style = STYLE2D3D.STYLE2D_SPLINE_AREA;
CrossingCharts1.Title = "Area/Line Combo Chart";
for (int k = 0; k < 15; k++)
{
arrBarChartValues[0].Add(rnd.Next(25000) + 25000);
}
CrossingCharts1.Series = arrBarChartValues; // Assign values to area chart
CrossingCharts1.SeriesLegend = new String[] { "Income" };
CrossingCharts1.SeriesColor = new Color[] { Color.LightYellow };
CrossingCharts1.YAxisScaleMode = SCALEMODE.SCALEMODE_FIXED;
CrossingCharts1.YAxisScaleMaximum = 50000;
CrossingCharts1.YAxisScaleMinimum = 0;
CrossingCharts1.YAxisTitle = "Y-Axis 1 Title";
CrossingCharts1.XAxisTitle = "X-Axis Title";
CrossingCharts1.ShowValues = false; // ' Hide values over chart
CrossingCharts1.ShowLegend = true;
CrossingCharts1.ShowPoints = false;
CrossingCharts1.LegendAlignment = STYLEALIGNMENT.STYLEALIGNMENT_BOTTOM_CENTER;
CrossingCharts1.LegendText = ""; // ' Hide legend's title
CrossingCharts1.ShowDataTable = false;
 
// Now create the second chart (line chart)
CrossingCharts oBarChart = new CrossingCharts();
ArrayList[] arrSeries = new ArrayList[1];
arrSeries[0] = new ArrayList();
int p = rnd.Next(50) + 50;
oBarChart.AutoRefresh = false;
for (int k = 0; k < 15; k++)
{
arrSeries[0].Add(p);
p += rnd.Next(10) - 5;
if (p < 50)
{
p += 25;
}
else if (p > 99)
{
p -= 25;
}
}
oBarChart.Series = arrSeries;
oBarChart.Style = STYLE2D3D.STYLE2D_LINE;
oBarChart.YAxisLocation = STYLEYAXISLOCATION.STYLEYAXISLOCATION_RIGHT;
oBarChart.YAxisTitle = "Y-Axis 2 Title";
oBarChart.YAxisScaleMode = SCALEMODE.SCALEMODE_FIXED;
oBarChart.YAxisScaleMinimum = 0;
oBarChart.YAxisScaleMaximum = 150;
oBarChart.SeriesLegend = new String[] { "Profit" };
oBarChart.ShowValues = false;
// Add the second chart to current chart and refresh
CrossingCharts1.ChartAdd(oBarChart);
CrossingCharts1.AutoRefresh = true;
 
}
}
}

Results:
« Last Edit: February 21, 2016, 03:56:44 AM by CrossingCharts »