Im creating a silverlight application for now, and I'm having a difficulty how to set an itemssource variable for a stacked chart.
Im using Microsoft.Windows.Controls.DataVisualization.Charting library
I'm used to make a non-stacked chart like so
void getChartCompleted(object sender, GetChartCompletedEventArgs e)
{
Chart chart = new Chart();
BarSeries barSeries = new BarSeries()
{
ItemsSource = e.Result.Value,
DependentValueBinding = new Binding("Value"),
IndependentValueBinding = new Binding("Label")
};
chart.Series.Add(pieSeries);
stackPanelChart.Children.Add(chart);
}
Now, if I want it to be a stacked bar chart, how to set the 'e' variable? Also, what other setting should I appplied to the chart object?
Thanks
Related
I am trying to use live chart for wpf c#. Generally I got it to work to display a graph. However when i try to call the function below more than once it does not execute the second time. Why? If I restart the program it works but only the first time again. Anybody familiar with live charts (lvcharts) library and can give me some direction. Thank you!
public void FillTheGraph(string[] axisX, double[] axisY)
{
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Graph",
Values = new ChartValues<double>(axisY)
},
};
Labels = axisX;
DataContext = this;
}
I'm attempting to open a chart in another window form, however the classes used for the data in the chart is in the first form. My goal here is to have a chart be able to open many times in a modeless window.
in form1.cs I build my chart:
Chart chart = new Chart();
Series price = new Series("Price"); //create new series
chart.Series.Add(price);
chart.Series["Price"].ChartType = SeriesChartType.Candlestick;
chart.Series["Price"]["OpenCloseStyle"] = "Candlestick";
chart.Series["Price"]["ShowOpenClose"] = "Both";
chart.Series["Price"]["PriceUpColor"] = "Green"; //Price increase = green
chart.Series["Price"]["PriceDownColor"] = "red"; //price decrease = red
for (int i = 0; i < data.Count; i++)
{
chart.Series["Price"].Points.AddXY(data[i].getDate(), data[i].getHigh()); //Adds date and high value
chart.Series["Price"].Points[i].YValues[1] = System.Convert.ToDouble(data[i].getLow()); //Low value added to chart
chart.Series["Price"].Points[i].YValues[2] = System.Convert.ToDouble(data[i].getOpen()); //open value added to chart
chart.Series["Price"].Points[i].YValues[3] = System.Convert.ToDouble(data[i].getClose()); //close value added to chart
}
Form2.cs:
public void DisplayChart(Chart newChart)
{
chart1 = newChart;
chart1.Show();
}
It is best to make the Chart is a separate class and call or create it from whichever form you need.
This follows object-oriented principles so you can reuse code and also use it for multiple purposes/views.
I am using Microsoft Visual Studio 2010, Includes Dynamic Data Display. I'm trying to adding on the chart a DYNAMIC label or textblock. I have been success to add a textblock on the grid but it move with the chart (I want it on the chart on specific point- not on the screen).
My adding textBlock :
TextBlock LenghtText = new TextBlock();
LenghtText.Margin = new Thickness(180, 50, 0, 0);
LenghtText.Text = lengthLine + "";
LenghtText.Width = 50;
myGrid.Children.Add(LenghtText);
// plotter.Children.Add(LenghtText); //--> If i try this line it error that LenghtText doesn't children of a IPlotterElement
I've been able to create a WriteableBitmap from controls that are rendered in my Silverlight application UI and export them to an XImage via SilverPDF and include them in a PDF document. This conversion and export process works fine.
Now, I'm working on a piece where I have a DataGrid that I'm building completely in the code behind and I do not intend to render it on the UI. My problem now is getting a WriteableBitmap of the DataGrid so that I can run it through the above process to convert it to an XImage and export it to a PDF document.
I've seen this thread which seems to also describe my situation, but it did not help: WPF - Get size of UIElement in Memory?
I'm wondering if the Measure and Arrange functions only apply on the WPF side and not Silverlight.
How can I get a WriteableBitmap from an un-rendered control? Here is the relevant code so far:
//Add DataGrid with feature's attributes.
DataGrid dg = new DataGrid();
dg.AutoGenerateColumns = false;
dg.HeadersVisibility = DataGridHeadersVisibility.None;
DataGridTextColumn keyColumn = new DataGridTextColumn
{
Binding = new Binding {Path = new PropertyPath("Key")}
};
DataGridTextColumn valueColumn = new DataGridTextColumn
{
Binding = new Binding {Path = new PropertyPath("Value")}
};
dg.Columns.Add(keyColumn);
dg.Columns.Add(valueColumn);
dg.ItemsSource = _featureToPrint.Attributes;
sp.Children.Add(dg);
return sp;
}
Once that sp (stackpanel) is returned, I call the Measure / Arrange method on it:
private static void ArrangeElement(UIElement element, double height, double width)
{
var box = new Viewbox { Child = element };
box.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
box.Arrange(new Rect(10, 10, width, height));
}
Any help or explanation of what I'm missing would be greatly appreciated! Thanks!
I am working on a Dashboard System where i am using Line Chart in WinForms. I need to show the tooptip on each line. I have tried this
var series = new Series
{
Name = chartPoint.SetName,
Color = chartPoint.ChartColor,
ChartType = SeriesChartType.Line,
BorderDashStyle = chartPoint.ChartDashStyle,
BorderWidth = chartPoint.BorderWidth,
IsVisibleInLegend = !chartPoint.HideLegend,
ToolTip = "Hello World"
};
but its not working for me
You have two options either use Keywords accepted by the Chart control.
myChart.Series[0].ToolTip = "Name #SERIESNAME : X - #VALX{F2} , Y - #VALY{F2}";
In the Chart control, a Keyword is a character sequence that is replaced with an automatically calculated value at run time. For a comprehensive list of keywords accepted by the Chart control look up Keyword reference
or
if you want something more fanciful, you have to handle the event GetToolTipText
this.myChart.GetToolTipText += new System.Windows.Forms.DataVisualization.Charting.Chart.ToolTipEventHandler(this.myChart_GetToolTipText);
Now I am not sure what you want to show on the ToolTip but you could add the logic accordingly. Assuming you want to show the values of the DataPoints in the series
private void myChart_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
{
switch(e.HitTestResult.ChartElementType)
{
case ChartElementType.DataPoint:
e.Text = myChart.Series[0].Points[e.HitTestResult.PointIndex]).ToString()
+ /* something for which no keyword exists */;
break;
case ChartElementType.Axis:
// add logic here
case ....
.
.
default:
// do nothing
}
After some RnD i got tooltips on Line Series, but still confused why its not working with this solution.
Here is the solution
series.ToolTip = string.Format("Name '{0}' : X - {1} , Y - {2}", chartPoint.SetName, "#VALX{F2}",
"#VALY{F2}");
mainChartControl.GetToolTipText += ChartControlGetToolTipText;
private void ChartControlGetToolTipText(object sender, ToolTipEventArgs e)
{
}